Configuration of Twilio with cnMaestro Webhooks

      Twilio is a developer platform for communications. Software teams use Twilio API to add capabilities like voice, video, and messaging to their applications. Twilio is mainly used as an SMS service provider for websites and apps.

Twilio supports HTTP basic authentication. This allows you to protect the URLs on your web server so that only you and Twilio can access them.

Following is a simple example of configuring Twilio integration with cnMaestro Webhooks using an application/xwww-form-urlencoded custom template.

To send a cnMaestro alarm as an SMS directly to a person’s phone, we are going to use Twilio’s API to programmatically send text messages. First, Login to Twilio or create a new account. https://www.twilio.com/

  1. After login to your Twilio account, you will be navigated to your “console dashboard”. 
  2. Make a note of the Account SID, Auth Token values on the main twilio.com/user/accountpage – you will need it when you configure the cnMaestro Webhooks as Basic Authentication’s username and password.

Add the Account SID to https://api.twilio.com/2010-0401/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json , this URL will be used as cnMaestro webhooks URL.

  1. Go to Phone numbers under All Products and Services in the console to get the phone number or click on the red plus (+) icon to add a new number and note down the assigned number to use as from number.

  1. Login to cnMaestro and Navigate to Application >Settings >Webhooks.
  2. Click Add Webhook. Fill the Account SID and Auth Token from Twilio for URL and Basic Authentication and expand Advanced Configuration.                                                                       

Using the custom payload option in cnMaestro, we will specify a custom payload adapted to Twilio’s format.

{

"Body": "<message>",

"From": "+<country_code><Twilio_number>",

"To": "+<country_code><destination_number>"

}

For this example, we are using the following custom template with variables $DEVICE_IP and $ALARM_SEVERITY in the formatted message.

{

"Body": "$DEVICE_IP has generated an alarm of severity $ALARM_SEVERITY",

"From": "+12********",

"To": "+91**********"

}

  1. Once an Alarm occurs in cnMaestro, the following message will be sent to the destination number from Twilio number. Notice the variables have been replaced with actual values.

Learn more about Twilio and expected JSON format at https://www.twilio.com/docs/usage/api

1 Like