The Case of Custom Ouf Of Office

In 2006-07, when I was writing Windows Mobile apps, I really enjoyed using MessageInterceptor type. Using that, we could build our own workflows based on Text Messaging. For example, send an SMS to the device and if SMS contains “Play”, play a song. If SMS contains “Stop”, stop playing the song. And what not. Oh, and I could say if the message is from my parents, reply “I’m in college” and if from friends reply as “I’m waiting outside the movie theater”.

However, I missed this functionality for a long time with different devices (lack of message intercepting API on some platforms). And recently I eagerly wanted to have it for the email, considering the heavy influx of emails in my new role. I got to know about Azure Logic App Service and thought, perhaps let’s go ahead and build something similar. And for me, this is a fantastic way to learn something new.

Scenario: Let’s build a solution which will read incoming email messages and if the message is from one particularly annoying friend, let’s reply with an equally annoying message. If it is from my manager, let’s reply with some positive update and if from a customer we’ll reply with actual OOF. Well, a lot of email service providers allow you to setup OOF, but it is not customizable for different emails. Outlook in Office 365 allows 2 separate OOF messages, one for members within your organization and one for outside organization. Our solution will provide more customizations.

Step 1: Create Azure Logic App Service

Navigate to Azure Portal and Create a resource. Search for Logic App and click on ‘Create’. Give it a name, select the subscription, create Resource Group and finally select a location near to you.

01. Create Logic App

Once Logic App is created, scroll down the next screen and click on ‘Blank Logic App’. This will allow you to add the logical functionality to the just created app.

02. Blank Logic App

Step 2: Design Logic App – Use Connector & Trigger

Connectors allow you to connect your logic app with the desired service. In our case, we’ll use Office 365 Outlook connector to connect to the mail service. And once you connect to the service, there will be a Trigger to activate the logic app. Again, in our case, it will be an email arriving in our inbox.

03. Logic App Connector & Trigger Webhook

Once you select the connector and trigger, sign in with your credentials and connect the email service with your logic app.

Step 3: Setup the Rule and Switch Case

On this screen select the folder in your mailbox to monitor and other aspects of the email. Click on ‘+ Next step’ and write define your logic.

04. Logic App Switch Case

Depending on the connector selected, you’ll see different options for the switch case. For example, in case of Outlook connector and Email trigger, there can be conditions to check for who has sent the email, if it has attachments, if it has importance set or if it has been sent directly to me or to any distribution list to which I’m subscribed.  These conditions will vary depending on trigger and connector.

05. Logic App Switch Options

Once the Switch is set, let’s set up the cases. Here, I’m checking if the email is from Vikram (Oh, he isn’t the annoying friend :) ) and setting up a reply for him. I can also repeat this for many more senders.

06. Logic App Case Vikram

The next one is for my manager Joao,

06. Logic App Case Joao

You can add as many cases as you want and ultimately add a default case. At the end, the logic app designer will look something like this:

06. Logic App Entire Logic

Finally, once this step is done, Run the logic app and wait for the magic to happen :)

07. Logic App Run

In this situation, if a user sends you an email and if the user falls under the cases, the user will receive the response accordingly and if not, user will receive the default response.

Conclusion:

Logic Apps Service makes it easy to write workflows and automate tasks. And even though we used Logic Apps for email workflow, there are connectors available for different services which you can find here. If this list doesn’t cover your service, you can write one on your own connector and documentation for the same is available here.
Don’t forget to ‘nuke’ the resource group once done with it or you’ll keep replying to all your emails – automagically. :)

Happy coding (or designing workflows :) ).
Namaste,
Mayur Tendulkar

 

 

 

 

 

 

 

Advertisements

Learn Mobile App Dev & Mobile DevOps Here

DevOps Meme

My friend Prachi tagged me on this meme on Facebook and I couldn’t agree more with her. When I started my career, my entire version control was folders – zipped, tagged and stored on multiple hard-disks. But then things changed. My guru Raj, enlightened me about advantages of version control systems. I learned about how multiple people can collaborate on projects or how errors can be reversed by going through code history if version controls like Team Foundation Server or GitHub are used. I started using those and these days, all my projects and samples are either in Visual Studio Team Services or in GitHub repository.  Going one step ahead, I’m using Visual Studio Mobile Center for DevOps along with these version control systems.

But what is this all about? How it helps in building successful mobile applications? And I thought about answering these questions in a video series. The goal is to explain mobile DevOps and different steps in mobile DevOps in small (less than 10 mins) videos.  After completing this series, you’ll be able to build cross-platform Xamarin.Forms mobile application, which will consume Microsoft Cognitive Service and set-up mobile DevOps for the same.

To follow along with this series, I’m recommending following minimum hardware/software combination:

  • Intel i5, 8GB, 50GB machine with Hyper-V support & Windows 10 Professional
  • MacBook or MacMini with i5, 4GB, 50GB for compiling iOS apps
  • Visual Studio 2017 Community Preview

With these hardware/software additional services used in this series are:

Watch the 1st video here about activating these tools & services to set-up mobile DevOps.

In 2nd video learn about how to setup build automation, using Visual Studio Mobile Center.

I’ll update this blog post in coming weeks with the 3rd video in this series, which will be about building mobile applications.

Stay tuned and subscribe to my blog/channel :)

Namaste.
Mayur Tendulkar

The Case of REST & Azure Resource Manager APIs

There are two kinds of people in this world. One who love ready made SDKs and then there are others who love to work on pure REST APIs. I’m from the 1st category. :)

The reason behind using SDKs is they include pure abstracted API calls. For example, if you use Active Directory Authentication Library (ADAL), it has AcquireTokenAsync method. This method, if you call, takes just couple of lines of code and makes your life much more easier.

However, behind the scenes, this method does a lot of stuff. For example, in case of Windows apps: calling WebAuthenticationBroker, launching Web UI, handling app navigation, etc. Similarly, it does same thing, in iOS and Android. But that entire code base is repetitive in every app which is going to use Active Directory for login. Now, one may ask, why so many calls are made just to authenticate and acquire token or as we progress through this blog post, why so many calls are required to perform basic operations. The answer lies in purity of REST APIs. And ADAL makes life easier here by providing one method doing all this for you while abstracting all the details.

When I was working on my blog post Monitor Azure Resource Usage and Predict Expenses, there was no SDK available for Azure Resource Manager (ARM) and the old API was not an ideal way to handle Resource Management APIs.

So, I had to write an app from scratch to get ARM working in my sample and here my friend Gaurav Mantri (@gmantri) helped me a lot. Gaurav founded Cloud Portam, which helps to manage resources in Azure like Storage, Search, etc… Thanks to him, I could understand the flow and I’m going to put it here on this blog post.

Step 1: Authenticate with Common

ARM allows you to manage resources within subscription and subscription is now part of your Active Directory. So, the first thing that you need to do is to authenticate with right Active Directory. This is simple if you’ve just one subscription and one Active Directory in your subscription, but if you’ve multiple subscriptions/active directories, you may want to iterate through them and get separate access tokens. To avoid this, first we hit the ‘common’ endpoint and then get the Tenants available.

Step 2: Get Tenants

As a user, your user account may be associated with multiple active directories. A tenant is nothing but an active directory to which you have access. Here, in this step we get all active directories first by calling below method. Later on we’ll try to fetch subscription (if available) from each directory.

Step 3: Get Subscriptions

Once we get tenants, each tenant may have subscription on which we may want perform some actions. To do so, we pass each tenant ID from GetTenants() to this method and acquire new token silently (without login prompt)

Step 4: Call ARM APIs

In order to perform management operations on an Azure Subscription, a user must be authenticated and authorized. Authentication part is handled by Azure Active Directory. There is a one to many relationship between an Azure AD and Azure Subscription. i.e. an Azure AD can be used as an authentication store for many Azure Subscriptions however authentication for an Azure Subscription can happen only with a single Azure AD. Once a user is authenticated with an Azure AD, next step is to find out a list of Azure Subscriptions the logged in user has access to. This is what we’re doing in this step. What a user can do in each of these subscriptions (i.e. the authorization part) can be accomplished by using Azure Resource Manager (ARM) API’s Role-based access control (RBAC).

Now you can replace your code in Step 4 to manage or monitor resources in your Azure subscription, but the flow will not change. The entire list of APIs covering resources and possible operations on them is available here

I hope this post will helps you to understand the model behind ARM API calls.

Namaste,
Mayur Tendulkar

Plugin 03: Phone Calling

In continuation to blog posts in this series on plugins, today we’ll cover a plugin to make phone calls.

As we understood before, all platforms support phone calling (just like emailing, texting, etc…) and Xamarin makes it easier with one common language – C#. However, developers still need to learn

In case of Windows Phone, one can initiate a phone call by using following code. In this case, Windows Phone has special class which allow developers to perform this task.

Screenshot 2015-02-23 10.53.12

In case of Android, developers can use ‘Intent’ and ‘URI activation’ to start a new phone call.

Screenshot 2015-02-23 10.56.09

In case of iOS, same concept of URI activation can be applied. As shown below in the code, developers can create a URI with telephone number and it will launch default application to make a phone call.

Screenshot 2015-02-23 11.13.09

Now, in case of Xamarin.Forms developers can use same Messaging Plugin for Xamarin and Windows plugin to implement phone functionality across the platforms.

Screenshot 2015-02-23 12.31.23

This way, developers can utilize the power of plugins to write one code which can work across different platforms, without bothering about underlying APIs.

Namaste
Mayur Tendulkar

Don’t Re-Invent the Wheel: Use Components or Plugins In Your Apps

Xamarin provides native, cross-platform mobile application development using language we all know and love – C#. However, it is still required to learn concepts of each platform. For example to send text message (SMS) in all these three platforms there are different set of APIs.

Below API is for Android, which uses SmsManager to send the text message. There is another way to do this using Intents.

image 

In case of Windows Phone, ChatMessage allows us to declare and send text message. This API is available in WinRT platform. In case of SL based apps, we need to use Launchers/Choosers.

image

In case of iOS as shown below, there is no API as such. But we use URL to launch default messaging app. In this case, we cannot set the message body, which we want to send out.

image

Life will be much simpler if there will be just one API on all these platforms which will take care of sending text messages and as I developer we don’t need to bother about on which platform it is being called. Here comes components and plugins. My friend James has written a nice blog about ‘What Exactly is a Plugin for Xamarin?’. You can read it here

In our case, we’re going to use Messaging Plugin for Xamarin and Windows which allow us to use same API to send text messages. Below code is written once in a Xamarin.Forms project which depending on platform on which code is executing, send the message using that platform’s APIs.

image

Using this plugin, it becomes easier to send text messages on Android, iOS and Windows. And this is the magic of Plugins for Xamarin.

In future posts, we’ll cover some of the best plugins and components which can help you build cross-platform mobile applications with single code-base.

I hope you’ve enjoyed this.

Namaste
Mayur Tendulkar

Events! Events!! Events Everywhere!!!

I’m drafting this blog post while attending (virtually) Apple Live event about iPhone 6 and Watch. And this is a start of series of events that are happening in near future. This is your one reference guide to those events. Don’t miss them if you’re a .NET Developer, Xamarin developer or a Microsoft MVP. Smile

PUG DevCon 2014

14271_10152748338121584_4822679446261989292_n

PUG DevCon is a premier event for developers in and around Pune, India. This is going to be a 2 days, multi-track event with industry experts and speakers like Daniel, Nauzad, Raj, Guruji (Sanjay Vyas) and many more. This event is happening on 13th and 14th Sept at MCCIA, SB Road Pune. For more information visit: http://aka.ms/devcon

Xamarin EVOLVE 2014

Capture

This almost a week long event is all about cross-platform mobile and smart gear app development using Xamarin. This event also includes hands-on training and sessions by various industry experts and it is happening at Atlanta, GA on 6th Oct till 10th Oct. For More information visit: https://evolve.xamarin.com/

TechEd 2014

Capture

Microsoft India’s premier technology event – TechEd is happening from 5th till 6th Nov and this time at Lalit Ashok, Bangalore. You can find more information about this event at: http://www.india.msteched.com/ 

MVP Summit

Capture

If you’re a Microsoft MVP, you might have received MVP Summit invite –  a special invite only event for MVPs. This time it is happening from 3rd Nov till 6th Nov at Redmond. Follow the invite for more information.

And much more:

Apart from these events, there are many events in December, for example friend Kunal and Deepak are getting married. Aviraj is coming for a short India visit and I think these are big events for us. And these are very special invite only events Smile

Till then, don’t forget to register and see you at all these events. ‘Say Hi’ if you’re around (except TechEd, I’ll be at Summit).

Namaste

Mayur Tendulkar