SMS Gateway - Twilio API for WhatsApp
The Twilio API for WhatsApp SMS Gateway delivers SMS messages internationally to WhatsApp users.
There are some important differences that are unique to WhatsApp compared with the regular Twilio SMS API. WhatsApp divides messages into two different types: Template messages and Session messages. These determine when you can initiate a message to a WhatsApp user.
You can get further information on Template messages and Session messages here:
Rules and Best Practices for WhatsApp Messaging on Twilio
https://www.twilio.com/docs/autopilot/channels/whatsapp
When setting up your Account in the fmSMS file follow the instructions in the Gateway Notes field. You will need to enter your Twilio Account SID in the Username field and your Twilio Auth Token in the Password field in the Accounts Screen - you can find these from your online Twilio account under the Account menu > API keys & tokens:
Incoming Messages/Replies
You can get incoming messages/replies to your Twilio number into the fmSMS file in in several ways:
- Manually Download Incoming Messages
- Use Webhooks to have Twilio push these automatically to fmSMS using the supplied PHP files
- Use Claris Connect Webhooks
- Use Otto Webhooks
Using Webhooks is the preferred method as it saves you from having to poll/check for any new messages - with Webhooks new messages are forward to fmSMS automatically by Twilio as they are received.
Manual Download Incoming Messages
You can download incoming messages manually via the Account Details screen. Simply enter the date range you wish to download messages between and click the Get Incoming Messages button:
Any incoming messages to your Twilio number that have not been previously downloaded will then be downloaded. You could also setup a FileMaker Server script schedule to have this run on a scheduled basis (e.g.every hour) to save you from having to manually download/check for new messages - your script would just need to handle the incrementing of the timestamps.
Manual Download Incoming Messages
You can download incoming messages manually via the Account Details screen. Simply enter the date range you wish to download messages between and click the Get Incoming Messages button:
Any incoming messages to your Twilio number that have not been previously downloaded will then be downloaded. You could also setup a FileMaker Server script schedule to have this run on a scheduled basis (e.g.every hour) to save you from having to manually download/check for new messages - your script would just need to handle the incrementing of the timestamps.
We recommend testing this out using the Twilio WhatsApp Sandbox first. To receive incoming SMS messages to your Twilio number, including replies to previously sent messages, you will need to use the supplied dedicatedNumberReply.php webhook file to act as the webhook receiver. See our Webhooks guide for what you need to do host the dedicatedNumberReply.php file on your chosen web server. Once you have the publicly accessible URL for this file you can enter this into your Twilio Sandbox settings as follows:
- go to the Twilio Sandbox for WhatsApp configuration page here: https://www.twilio.com/console/sms/whatsapp/sandbox
- under Sandbox Configuration in the WHEN A MESSAGE COMES IN enter the URL in the adjacent field
- set the HTTP method to POST.
- click Save
It should look similar to this screenshot:
To receive incoming SMS messages to your Twilio WhatsApp number, including replies to previously sent messages, you will need to use the supplied dedicatedNumberReply.php webhook file to act as the webhook receiver. See our Webhooks guide for what you need to do host the dedicatedNumberReply.php file on your chosen web server. Once you have the publicly accessible URL for this file you can enter this into your Twilio account settings as follows:
- login to your Twilio account via their website
- click on Phone Numbers in the side navigation (or go to https://www.twilio.com/console/phone-numbers/incoming)
- Click on your Twilio WhatsApp Number to edit it, then under Messaging selected Configure with Webhooks/TwiML
- select A Message Comes in “Webhook” and enter the URL in the adjacent field
- set the HTTP method to POST.
- click Save
It should look similar to this screenshot:
Twilio Claris Connect Webhooks Setup
Please visit the Twilio Webhooks using Claris Connect guide for instructions on setting up Claris Connect Webhooks for your Twilio number.
Twilio Otto Webhooks Setup
Please visit the Webhooks using Otto guide for instructions on setting up Otto Webhooks for your Twilio number.
Message Scheduling
Twilio first introduced Message Scheduling on August 24, 2022. Support for Message Scheduling was added in v4.2.11 of fmSMS. You will first need to create a Messaging Service and copy the Twilio MessagingServiceSid into the Custom Text 3 field in the Accounts Screen. For more information on using Messaging Services visit: