Skip to main content

Twilio

warning

The document is a continuation of the previous document, if you have landed directly on this page then, Please read from page Get started.

What is Twilio?#

Oops!, No Image to display.
  • Twilio is a cloud service which allows you to send SMS and Whatsapp messages programmatically using code.
  • Twilio is a paid service and you will have to pay per SMS/Whatsapp message.

Setup:#

Requirements for using Shunya Interfaces Modbus client API's are:

  1. Twilio account with mobile number assigned from the Cloud platform.
  2. Twilio auth token from the Cloud platform.
  3. Twilio SID from the Cloud platform.
  4. Configuration of Twilio in Shunya Interfaces.

Configuration:#

User needs to configure Shunya Interfaces to connect to the Modbus server, by writing the configuration file in /etc/shunya/config.json.

Example configuration for Twilio#

/etc/shunya/config.json should contain entry.

"twilio": {
"twilioAccountSid": "xxxxxxxxxxxxxx",
"twilioAuthToken": "xxxxxxxxxxxxxxx"
},

Using the Twilio Shunya Interfaces API#

2 primary uses of Twilio Shunya Interfaces API's are

  1. Send SMS message
  2. Send Whatsapp message

Sending SMS message#

The steps given will help you send SMS message via Twilio Cloud Service.

Step 1: Write Code to send SMS message via Twilio Cloud Service.#

int temp = 60;
/* Create the Twilio object */
twilioObj sms = newTwilio("twilio"); /* Argument = JSON Title, Load settings from JSON file */
/*Send Sms
From Number: "911765765789"
To Number: "911475289631"
Message: "Temperature is above X deg C"
*/
sendSmsTwilio(sms,"+911765765789","+911475289631",
"Temperature is above %d deg C", temp);

That is it done.

info

Checkout ready-to-use Twilio SMS example#

Ready to use example provides sample code and sample cmake, which can be used to quickly get-started using the component.

Step 2: Compile and Run code#

To compile and Run code

  1. Clone the Example
    git clone https://gitlab.iotiot.in/repo-public/examples.git
    cd examples/simple-examples/send-sms-twilio
  2. Compile the program
    mkdir build && cd build
    cmake ../
    make
  3. Make sure that you have written the configuration in "/etc/shunya/config.json"
    {
    "twilio": {
    "twilioAccountSid": "xxxxxxxxxxxxxx",
    "twilioAuthToken": "xxxxxxxxxxxxxxx"
    }
    }
  4. Run the code
    sudo ./send-sms-twilio

Sending Whatsapp message#

The steps given will help you send Whatsapp message via Twilio Cloud Service.

Step 1: Write Code to send Whatsapp message via Twilio Cloud Service.#

int temp = 60;
/* Create the Twilio object */
twilioObj whatsapp = newTwilio("twilio"); /* Argument = JSON Title, Load settings from JSON file */
/*Send Whatsapp
From Number: "911765765789"
To Number: "911475289631"
Message: "Temperature is above X deg C"
*/
sendWhatsappTwilio(whatsapp,"+911765765789","+911475289631",
"Temperature is above %d deg C", temp);

That is it done.

info

Checkout ready-to-use Twilio Whatsapp example#

Ready to use example provides sample code and sample cmake, which can be used to quickly get-started using the component.

Step 2: Compile and Run code#

To compile and Run code

  1. Clone the Example
    git clone https://gitlab.iotiot.in/repo-public/examples.git
    cd examples/simple-examples/send-whatsapp-twilio
  2. Compile the program
    mkdir build && cd build
    cmake ../
    make
  3. Make sure that you have written the configuration in "/etc/shunya/config.json"
    {
    "twilio": {
    "twilioAccountSid": "xxxxxxxxxxxxxx",
    "twilioAuthToken": "xxxxxxxxxxxxxxx"
    }
    }
  4. Run the code
    sudo ./send-whatsapp-twilio

Facing errors with the component?#