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?
- 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:
- Twilio account with mobile number assigned from the Cloud platform.
- Twilio auth token from the Cloud platform.
- Twilio SID from the Cloud platform.
- 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
- Send SMS message
- 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
- Clone the Example
git clone https://gitlab.iotiot.in/repo-public/examples.git
cd examples/simple-examples/send-sms-twilio - Compile the program
mkdir build && cd build
cmake ../
make - Make sure that you have written the configuration in "/etc/shunya/config.json"
{
"twilio": {
"twilioAccountSid": "xxxxxxxxxxxxxx",
"twilioAuthToken": "xxxxxxxxxxxxxxx"
}
} - 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
- Clone the Example
git clone https://gitlab.iotiot.in/repo-public/examples.git
cd examples/simple-examples/send-whatsapp-twilio - Compile the program
mkdir build && cd build
cmake ../
make - Make sure that you have written the configuration in "/etc/shunya/config.json"
{
"twilio": {
"twilioAccountSid": "xxxxxxxxxxxxxx",
"twilioAuthToken": "xxxxxxxxxxxxxxx"
}
} - Run the code
sudo ./send-whatsapp-twilio