Azure Logic Apps - Sending SMS using Twilio connector

 Azure logic apps is a cloud service that helps you to define your works flows, schedule tasks etc in the cloud. It is server less and fully managed IPAAS (Integration Platform as Service) with inbuilt scalability. 

Logic apps provides a visual designer for create and configure your work flows. You can define your work flow with in-built connectors or other enterprise connectors. 

Advantages of Logic app

  • Inbuilt Connectors: We have plenty of inbuilt connectors, triggers and actions that cover many of the common business scenarios. 
  • Templates: Logic apps comes with many predefined templates that are available for common business cases which reduces the  development work.
  • Integration: You can integrate your on-premise legacy systems with the new ones in the cloud. 
  • Extensibility: You can create your own custom APIs, Azure Functions and integrate them to the workflow, if the inbuilt connectors are not met your needs.
  • Minimal Development Effort:  We can create the logic apps with minimal development effort in browser or visual studio.

Logic app for sending an SMS

Azure logic apps offers a pre-built Twilio connector which can allow you to send, get or list SMS / MMS from your Twilio account. In this post I will demonstrate how to use the logic app to Send an SMS using Twilio connector.

Prerequisites:

  • Azure subscription
  • Twilio AccountId and Authentication token
  • A Twilio number / Twilio verified number to send SMS
Steps:
1) Login to Azure portal
2) Select "Create a Resource" -> Search for Logic app -> Create
3) Select subscription, resource group, Region and give logic app name -> Click on Review & Create button -> Create
4) Open the logic app once the deployment completed
5) Select Http Request response template in the Logic Apps Designer. It will create a new app with Request and Response connectors as below


6) I want to send the SMS request in the following format
{
    "sendingNumber": "xxxxxxxxx",
    "destinationNumber": "xxxxxxxxx",
    "messageContent": "message from logic app",
    "statusCallBackURL": "https://hookb.in/yDRKx6el2xFJNNPaR2kk"
}
So, in the Http request trigger, give the following as request body JSON schema
{
    "type": "object",
    "properties": {
        "sendingNumber": {
            "type": "string"
        },
        "destinationNumber": {
            "type": "string"
        },
        "messageContent": {
            "type": "string"
        },
        "statusCallBackURL": {
            "type": "string"
        }
    }
}



7) Click on Insert new step(+ icon) after Http Trigger connector -> Add an Action -> In the search box, enter "twilio" to filter the connectors -> Under the actions list select the action you want. I selected Send Text Message (SMS) as we are going to send a message.



8) Now provide the necessary details for your connection like Connection name, Twilio Account Id, Twilio Access Token and select Create button










9) Give the necessary details for sending the SMS like From Phone Number, To Phone Number, Text, Status Call back (You can get this parameter by selecting it from "Add New Parameter" dropdown). You can pick these values from logic app Trigger.













10) It completes the message sending. But I want to send the message SID back to the user in response. So I modified the Response connector as below












11) Save the logic app. Once you saved the logic app it will generate an URL in the HTTP trigger connector.  Now you can trigger your logic app by posting your request to that URL.

I will explain the logic app for handling the Twilio SMS status call back in another post. 

Happy Coding 😀!

Gopikrishna

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment