While TeamDesk does not support sending SMS messages directly, it is still possible via built-in third-party services integration features. In this article we’ll show how to use Call URL actions and webhooks to build SMS chat via Twilio services.

A while ago we wrote an article outlining SMS Chat using Twilio, but due to features missing in TeamDesk at the time of writing we needed to use polling and some JavaScript code in Twilio to make it work. But now with webhooks we can do it in much more simpler way.

First thing you’ll need is to register an account with Twilio. Once registered, navigate to the console and note Account SID, Auth Token and phone number.

Twilio Account Settings

Create your copy of the sample database, navigate to Setup | Database tab | Database | Variables and fill in values of Account SID and Phone Number variables. Then, navigate to Setup | Database tab | Tools | 3rd-Party Accounts | Twilio and put Account SID into Username and Auth Token into Password fields.

In the core of the sample there is Messages table which basically needs three fields. From is the source phone number. We’ll use the variable as its default, but you can potentially have multiple numbers to send from. To is the phone number to send the message to and Body is the message text.

Then there is Call URL action that calls Twilio API to send the message.

The action is attached to a record change trigger that fires when record is added. Create new record, put recipient’s phone number and message text, save and voilà! The message is sent. But it’s not guaranteed whether and when it will be delivered 🙂

Checking SMS delivery status

The process of sending message is asynchronous. With API call above you instruct Twilio to queue the message, but it takes some time for the message to be delivered. Or there might be an error due to, say, phone number is wrong. If you are interested in obtaining delivery status, a bit of extra work is required.

First, we would need to setup the webhook.

Then we’ll need two more columns in our Messages table. One is Message-ID of text type. It will store unique message identifier reported by Twilio. Another column is Status, also of text type with the word “pending” as default value. Add two assignments to our Call URL action

and modify the body of the request to include StatusCallback parameter – it’s already on a Call URL setup screenshot.

Now the record in the message table has Message-ID. The change in message status received in webhook also has the Message-ID. Relate Message and Message Status tables by equality of Message-ID columns, add a RecordSet column and a record change trigger to update Message table’s Status from the record received in webhook.

Receiving SMS chat replies from Twilio

Twilio is capable to handle incoming SMS messages by calling some URL with the phone numbers and SMS content payload. So, we need another webhook in our database:

Incoming SMS chat webhook

Setting up this one is a bit tricky. New webhook automatically creates new table to store incoming data. We want our data to go straight into Messages table. So, you would need to edit the webhook and select Messages table from the dropdown prior to creating the assignments.

Once webhook is set up, copy its URL. Then visit Twilio console again, select your phone number and scroll down until you see Messaging section. Then paste webhook URL into the text box in a A Message Comes In sub-section.

Incoming SMS chat settings

Save.

Now you’ll be able to receive messages sent to your Twilio phone number straight into your TeamDesk database.

Author
Date
Share