While exploring the services in Azure, I’ve been in constant thought of how to use the Logic App service offered Logic App Designer.
While exploring more in-depth MS Documentation I’ve created a logic app for a small project on the calculating the time to travel to my local university on the days I have lectures.
For this post, we’re going to explore the usage and the design I’ve implemented in MS Azure.
Creating a Logic App
- Provision our resource navigate to the azure portal. www.portal.azure.com
Select + Create a resource.
Select Create.
2. After settings are entered for desired values and fields, wait for the deployment to be provisioned.
3. Navigate to your Logic App resource
As shown below select Logic App Designer.
4. Create a Blank Logic App
Search for Recurrence as shown as the image above and click on the Schedule option.
If you desire, you can name this task by selecting the … in the top right corner, we will fill out this step with parameters.
Interval – 1
Frequency – Week (or defined as you desire)
Then we will select the drop down Add new parameter, we will select On these days, At these hours, At these minutes.
The Preview block you see above is to show you exactly the configuration and when it will fire.
Click Save.
5. Click the +Add Step for the next operation to add to your logic app.
Search for Bing Maps the selection will have two tabs Triggers and Actions. We will select Get Route (Preview) this will require an API.
I’ve mapped the API of BingMaps so this will show on my screen but perhaps not on yours if you don’t have an API key connection.
Visit this URL for Getting a Bing Maps Key
After adding the parameters, I’ve also clicked Add New Parameter and selected Optimize, Distance Unit, Travel Mode.
For Optimize I’ve selected timeWithTraffic.
For Distance Unit I’ve selected Mile.
For Travel Mode I’ve selected Driving.
Save this step and select + New Step
6. In the next step search the query “Variables”
Since we are searching for a integer value, for this variable the Type is Integer
I’ve named this variable CommuteTime,
The last parameter that states Value: we will use Expression.
Expression field type in div(,60) then navigate to the Dyanmic Content until we see the Travel Duration Traffic value as the insertion for the div(,60)
Once the value is an accepted value you can then select continue.
6. Add a Condition as shown in the image below search for Condition navigate to the tab Built-in.
Add your commuteTime to the variable portion shown below.
On the drop down select is greater than and input the value as 15.
For our True statement if this is satisfied we will have to determine our method of notification.
Select Add an Action hyperlink to add your action when this condition is satisfied.
7. Search for ClickSend SMS this will need an API key click here
Navigate to the selection highlight Send SMS (preview) select this option.
for messages To – 1 field
- message To – 1 (Input phone number you wish to send the SMS too) this example phone number is not mine or anyone’s a random number.
- messages Body – 1 (input is the message the person who is receiving this SMS will get if conditions are met.)
- For the body, start with a plain sentence as shown “The time for commute is” then click on Add Dynamic Content button on the right corner of the field and once it’s populated add type in commuteTime it should show a {x} with variables as the header of the selection. Double-click this selection and it will populate the message body as shown above. Then for the purpose of the text add whatever your message you want and select Add Dynamic Content (+) again and navigate to Expression type in the field sub(,15).
Click in-between the parentheses and before the comma we will add variables(‘commuteTime’) into this field. By clicking on Dynamic Content and double-click commuteTime it will add as shown.
Then click OK.
Your completed condition of True should be completed now you can hit Save for your logic app.
Now the fun part the testing of your creation, since this is Serverless you’ll have to select Run Trigger to test the logic app it should be extremely fast for this demo, I’m going to include a screenshot of the SMS I receive on my end.
After your trigger has ran and you’ve received a message your logic-app is complete!