[RELEASE] Using Twilio to Send SMS

twilio
sms

#1

UPDATED METHOD:

Original Post:

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, bonus is that you can reply to messages received and trigger automations based on that reply:

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 - Import this example piston and enter your Twilio details:

  • Change ‘To’ to your mobile number, (+1 format for US)
  • Change ‘From’ to your purchased Twilio Number (do not use an alphanumeric sender ID if you are planning to use the reply feature)
  • Change ‘AccoutSID’ - Get this from Twilio Dashboard
  • Change ‘Auth’ as follows:
  • Note - It is best to place ‘AccountSID’ & ‘Auth’ into global variables, so they can be used across multiple pistons, it was just easier to use local variables in this tutorial.
  • The POST request URL was anonymized in the piston snapshot above, should be https://api.twilio.com/2010-04-01/Accounts/{AccountSID}/Messages.json
  • In Twilio, go to your phone number (https://www.twilio.com/console/phone-numbers/incoming ) and change the ‘Message comes in Webhook’ to your pistons external URL.

Once you are happy, upgrade to a paid account for continued use.


Changes to ST SMS service (September 25, 2019)
Can't get SMS notifications to work
Migrating to HE. Any major loss of functionality?
#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}

@Robin: 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.


#15

can anyone help me out…i get error when i try to test piston


#16

new to scipting… i get this error

Error executing virtual command [].httpRequest: (1ms) java.lang.NullPointerException: Cannot invoke method replace() on null object


#17

It’s inherently hard to diagnose issues people have with this one, all I can say is it still works for me thus you must have missed a step in the setup.

Perhaps post your piston screenshots so we know which version you are trying. I don’t recall using the replace() function in my examples.

There error is in webcore, any issues on the Google or Twilio sides would not display in webcore.


#18

ok i figured ot the URL but having problems getting it to send message. the e2i82 piston

i changed the execute line to
{GoogleAPIURL"?type=SMS&code=“smsCode”&to="$args.ToNumber"&body="$args.smsBody"&From="smsFrom} as per the image on your tutorial
when i test it runs with no errors but text do not go through. I can go to google sheets and i can use the blue button and my texts go through


#19

Is it a trial account with Twilio or have you paid?

I note that your smsFrom variable is ‘webCoRE’, but that will only work for a paid account. For a trial account smsFrom needs to be your Twilio phone number.

See sections B7 and C4 in the install guide, post 1.

You also havnt setep the rest of the variables, i.e. GoogleAPIURL and smsCode… work through instructions section C.


#20

i used the twilio number instead of webCore… i have since got a paid account…have not tested with webCore only with twilio number