SMS / Twilio
Introduction
Wattyo is integrated out of the box with Twilio SMS sending functionality. This way you can easily send SMS from the application.
The Integration is built as an implementation of the NotificationChannelInterface what means that is fully integrated with the notification manager.
Twilio Environment
Twillio offers two environments: Production and Sanbox.
Environment | Description | When to use |
---|---|---|
Production | The real production environment. Any SMS sent from production will be actually sent and it will have an associated cost | Production Environments or specific tests/demos |
Sandbox | In this environment you can simulate sms sending with no cost. You can check the SMS status in the control panel but it will never reach the actual recipient. | Development, Tests, Demos. |
Setup
It’s necessary to setup the Twillio integration by:
- Update the Twillio custom metadata with the correct Phone numbers and account id from your Twilio Account.
- You must set the “user” and “password” token in the External Named Credential for twilio.
- Go to Principals, edit the Authorization record, and add the parameters “user” and “password” with the corresponding values.
Note: For whatsapp testing you need to use the Production credentials but with the from number: +14155238886 (global sandbox phone number for whatsapp)
- Go to Principals, edit the Authorization record, and add the parameters “user” and “password” with the corresponding values.
External Credentials
In the Twilio SMS External Credentials, go to Named Principal and set the correct values for user and password.
Both the user (API Key) and the password must be taken from the Twilio’s Control Panel.
Keep in mind that you depending on if you want to connnect to Production or Sandbox you will need to set one credential or another.
Twilio Setting CMT
In the Twilio Settings Custom Metadata you will need to configure the SMS record. Here you have to set two parameters:
Field | Description | Example |
---|---|---|
From Phone | The Phone Number (with prefix) the system will send the sms from. In production you should set one of the numbers configured in the Twilio Conrtol Panel. | +15005550006 |
User | The User Token taken from Twilio Control Panel | ACde26cba4f90fab17cc43cc66fbbe28ae |
The User must be set here apart from the External Credential because Twilio API requires to pass the User in the URL and there is no way to achieve that with the Named Credential.
sendNotification()
The sendNotification() method from TwilioNotification class, simply builds the required request depending on the NotificationEnvelope. The same method also handle the Whatsapp Notifications.