[RELEASE] Using Twilio to Send SMS

twilio
sms

#1

With the demise of SMS messaging for non US phone numbers, many of us have been cut off.

There are some existing options out there for pushover and WhatsApp, but I prefer good old fashioned SMS.

Here is what you need to do to use Twilio SMS with webCoRE, I’m sure someone will figure out how to make the web calls to Twilio directly, but for now I’m passing the requests through Google Sheets / Script API.

Seems a bit long winded but that’s because I’ve carefully spelt out every single little step, most of it is just copy paste.

Step A - Register for a Free Trial Twilio account

  1. I wont go through the initial steps for this as Twilio walks you through the process, however please use my referral link by clicking here and we both get $10 credit :grin:
  2. When you are asked to verify your mobile number, choose the initial number you wish to send messages to. Until you upgrade to a paid account you can only send messages to verified numbers.
  3. Choose an available phone number of your choice, making sure it has the SMS capability.
  4. Take a copy of the of the ‘Account SSID’ and ‘Auth Token’ from the Twilio Dashboard.

Step B - Setup the Google Sheet

  1. Create a Google Account if you don’t already have one

  2. Click here to open the template (read only) spreadsheet shared on my Google Drive.

  3. Click File > Make a Copy, and save a copy of the template in your own Google drive.

  4. Within your copy of the template:

    • Enter your Twilio ‘Account SSID’
    • Enter your Twilio ‘Auth Token’
  5. Click the red button to generate a strong random code to secure communications between webCoRE and the Google API. Note that the first time you do this an authorisation page will pop up:

    • Click ‘Continue’
    • Select your google account
    • Click ‘advanced’
    • Click ‘Go to Send SMS (unsafe)’ - don’t worry, Goggle says this about all custom apps)
    • Click ‘allow’
  6. Set the ‘To’ field - During the free Twilio trial this can only be the phone number you verified in step A2 above. Paid accounts can send to any number worldwide.

  7. Set the ‘From’ field - During the free Twilio trial this can only be the phone number you chose in step A3 above. Paid accounts can appear as coming from any alphanumeric ID (i.e. ‘webCoRE’)

Note that because of the way Google Sheets handle strings starting with the + symbol, you must place an apostrophe at the start, i.e. '+447XXXXXXXXX**

  1. Click the blue button to trigger a test message. (this may require a re-authorisation the first time, not sure)

  2. Publish the Google Script for webCoRE control:

    • Click Tools > Script Editor
    • Click Publish > Deploy as Web App
    • Leave ‘Anyone, even anonymous’ selected (the strong code above is your safety net)
    • Click ‘Update’
    • Copy the ‘Current web app URL’ to a notepad for use in webCoRE shortly

Step C - Install the Master Piston in webCoRE

  1. Install the following master piston using the import code provided:

  2. Change the variable ‘GoogleAPIURL’ to the web app URL copied in the step above.

  3. Change the variable ‘smsCode’ to the strong code selected in step B4 above

  4. if you are still on the free trial, change the ‘smsFrom’ variable to the phone number you chose in step A3 above. Paid accounts can appear as coming from any alphanumeric ID (i.e. ‘webCoRE’)

  5. Save the piston

Step D - Install the Test Piston in webCoRE

  1. Install the following test piston using the import code provided:

  2. Change the variable ‘smsToNumber’ to the phone number you verified in step A2. Paid accounts can send to any number worldwide.

  3. You will need to rebuild the ‘execute piston’ action, linking to the master piston installed in step C above, instead of my version of the same. Make sure you select both variables to send with the execute command.

The test piston provided is just an example of how to trigger an SMS from any piston you like, just execute the master piston with those two variables selected.

When you are happy things work for you, upgrade to a paid Twilio account to enable custom sender ID’s, sending to any number and to remove the watermark from the text messages. Cost vary country to country, but in the UK it 4p per message segment, more when sending emoji.


Changes to ST SMS service (September 25, 2019)
#2

Hi Robin
Thanks for this. The loss of the text function is a big disappointment.
The link to your referral code doesn’t appear to work (in step A1).

Would you mind giving a short explanation which of the SMS functions should be used in Twilio? I managed to set up the Twilio to Whatsapp function for webCore some months ago, but never could figure out what I was doing. I simply followed the step by step instructions. By the way, I have to send a Whatsapp message to Twilio every 24 hours to keep the functionality alive. Do you know of a way to circumvent this requirement? (I have a paid account with Twilio).

Thanks again.


#3

I’ve fixed the referral link.

In Twilio, you need to pick a phone number, the option to do this is a big button on the dashboard during the initial trial, but a bit more hidden once already setup / on a paid account. Try going to the following page: https://www.twilio.com/console/phone-numbers/incoming

You just need to pick a phone number from the list that allows the SMS function.

I have no idea about the whatsapp method, though I did read about the whole 24h thing being somewhat annoying… this is not the case for SMS messaging over Twilio.


#4

Thank you for the write up. This would have taken me a couple of days, at least, to set up, and not as elegant as your commands. I had to experiment to get 2 numbers to text to, but I did get it. Thanks again.


#5

Thanks Robin. Looks like I’m out of luck - not available in South Africa.

Just to make sure - I get to this page:

It seems that I have to click “Get Started”. That takes me to this page:

Which takes me here:

:sob:


#6

I wonder what would happen if you just purchased a UK number? May or may not charge more, not sure?

You’ll be changing the sender ID to something alphanumeric anyway, worth a try and if it’s silly money per message then just release the number back to the pot.


#7

If you send me a PM with your SA phone number, I’ll send you a message from my UK Twilio number and see what it cost in the logs.


#8

Update:

I was able to send @949BFN a text message (to South Africa) via Twilio, using a UK Twilio phone number, required a few settings tweaks though:

  • The Twilio number chosen must not be one of the ones listed as for ‘domestic use only’. Domestic only numbers are identifiable by the crucifix symbol next to the phone number when picking from the list. There’s no filter for this in the search but if you search for only mobile numbers, not local numbers, you will have loads to pick from.

  • You need to have a paid account

  • You need to activate permissions for sending messages to specific international countries, which is done via the following page: https://www.twilio.com/console/sms/settings/geo-permissions

  • You need to check that your phone carrier is supported by Twilio in your country, by searching on the following page, and scrolling down to ‘All SMS pricing…’ near the bottom of the page: https://www.twilio.com/sms/pricing/za

  • I was unable to use a custom alphanumeric sender ID, thus the ‘from’ field had to be the Twilio phone number I was sending from, not for example ‘webCoRE’.

Caveat is that Twilio takes about 30 minutes to update message logs and it seems to need 24 hours to populate the price of each message, this as of writing I have no idea what my test message to @949BFN actually cost me… will update this thread when that becomes clear.


#9

Thank you Robin, I got it working.
The URL for the GET request in the first piston is left empty when importing the piston. (Tried it twice).
For anyone else having the same issue, the URL for the GET request:
{GoogleAPIURL"?type=SMS&code=“smsCode”&to="$args.smsToNumber"&body="$args.smsBody"&from="smsFrom}

@RobinWinbourne: Any suggestions how to set up two recipient numbers? (I’ll play around in the meantime to see if I’m able to figure it out.)


#10

You have to send an API request for every number… but you could in theory tweak the middle man (the Google Script) to split one combined call into multiples… but probably not worth it.


#11

I set up 2 different outgoing pistons, the second with smsToNumber1, then added a second GET statement with the smsToNumber1 in each piston that required both numbers to go out on set for the second number. Works like a charm


#12

Here’s a version of the ‘Master Piston’ which can send to up to 4 different numbers selectively (just drag copy the code block if you need more numbers):

Requires you to set 4 global variables (@contact1, @contact2, @contact3, @contact4), set the value of these global variables to the required phone numbers, including the country code i.e. +447xxxxxxxxx

In the triggering piston, you just need to set and send ‘smsToNumber’ to the desired number, or combination of numbers.

Examples:

  • smsToNumber = 1 - send to contact 1
  • smsToNumber = 2 - send to contact 2
  • smsToNumber = 13 - send to contacts 1 and 3
  • smsToNumber = 1234 - send to all 4 contacts

As correctly pointed out by @949BFN, the GET URL’s are lost (made anonymous) when imported, thus the URL’s are as follows:

GoogleAPIURL"?type=SMS&code="smsCode"&to="@contact1"&body="$args.smsBody"&from="smsFrom

GoogleAPIURL"?type=SMS&code="smsCode"&to="@contact2"&body="$args.smsBody"&from="smsFrom

GoogleAPIURL"?type=SMS&code="smsCode"&to="@contact3"&body="$args.smsBody"&from="smsFrom

GoogleAPIURL"?type=SMS&code="smsCode"&to="@contact4"&body="$args.smsBody"&from="smsFrom


#13

Sending an SMS to South Africa from a UK Twilio number cost 2p per segment vs 4p per segment for sending to a UK number… so @949BFN will be paying half what I do lol.


#14

Borrowing from other pistons on the forum, I created a master piston to deal with all text messages:

The piston is able to send text messages to a single (primary) - or multiple users.
My Mobile Numbers are stored in Global Variables, but you can obviously change it to local variables.

Three global dynamic variables have to be created:
@smsNotificationTrg (Message to Primary Mobile Number)
@smsNotificationTrgAll (Message to Both Mobile Numbers)
@smsNotification (Contents of the Text Message)
E.g.:

All one has to do to send an SMS from within any other pistons, is to add the following to commands to set variables:


I.e. the contents of the text message

and

Which will trigger the Master Piston. If the message should only go to the primary (first) mobile number, @smsNotificationTrg should be use in place of #smsNotificationTrgAll.