[No Longer Supported] Twilio Notifications Driver - Supports SMS and Voice Calls

Sorry for the confusion - the TEXT's are not free (I pay per TEXT), but I dont have to pay the monthly fee for the phone number.

I have a paid accound (upgraded) but I don't have a paid phone number. However, I am able to send SMS text's from a (random) alphanumeric number. For instance, I can send the following SMS text:

From: My house in Denmark
To: +45XXXXXXXX
Message: The firealarm has gone off

I can send the above text via curl using the below command:

curl 'https://api.twilio.com/2010-04-01/Accounts/AC772ee08aeXXXXXXXXXXX0b4ed4/Messages.json' -X POST
--data-urlencode 'To=+45XXXXXXXX'
--data-urlencode 'From=My house in Denmark'
--data-urlencode 'Body=The firealarm has gone off'
-u AC772ee08aXXXXXXXXXX15360b4ed4:[AuthToken]

However, in the hubitat Twilio notifier I can only put in my Twilio "Account SID" and "Auth Token". When I his "save" I don't get the possibility to put in my number, because I dont have a number in Twelio. But if I had the possibility to manually put in my alphanumering ID I could send texts using the notifier.

Do I make any sense? :slight_smile:

OK I have not heard of this feature and it is not available in the US either so I will have to depend on you to test this for me. The API to get a list of Alpha Senders requires a ServiceSID:

Did you have to setup a service within your Twilio account and is this ServiceSID familiar? Thinking I could create an additional driver preference to enter this and if present it will not only check for phone numbers tied to the account but also the Alpha senders too.

YES, I also have a Service SID - it is something like MG03c2654XXXXXXXXXXXXXXXXXXXXX :slight_smile:

I did set it up under SMS/Messageing Service.

When I send a message I get this response in Twilio:

{
"sid": "SM5d10fd0XXXXXXXX6228cd3fac62b",
"date_created": "Mon, 04 Nov 2019 16:39:43 +0000",
"date_updated": "Mon, 04 Nov 2019 16:39:43 +0000",
"date_sent": null,
"account_sid": "AC772XXXXXXXXXXXXXXX60b4ed4",
"to": "+45XXXXXX",
"from": "Henrik",
"messaging_service_sid": "MG03cXXXXXXXXXXXXX6607",
"body": "Hello",
"status": "accepted",
"num_segments": "0",
"num_media": "0",
"direction": "outbound-api",
"api_version": "2010-04-01",
"price": null,
"price_unit": null,
"error_code": null,
"error_message": null,
"uri": "/2010-04-01/Accounts/AC772eXXXXXXXXXXXXXXXXX4ed4/Messages/SM5d10fdXXXXXXXXXXXX228cd3fac62b.json",
"subresource_uris": {
"media": "/2010-04-01/Accounts/AC772eXXXXXXXXXXXX360b4ed4/Messages/SM5d10XXXXXXXXXXXXXc62b/Media.json"
}
}

OK again I have no way to test this functionality so hopefully my updates to the Twilio Container driver will work. Basically if Service SID is populated it will check for Alpha Senders and add that to the Twilio Phone Number list.

Tried it - but I can't choose Twilio phone number. It shows the "Twilio phone number to use" but I cannot choose any number or alphasender.

When I go into the API and choose "Get Alphasender" I get this response:

{
"meta": {
"page": 0,
"page_size": 50,
"first_page_url": "https://messaging.twilio.com/v1/Services/MG03XXX607/AlphaSenders?ServiceSid=MG03XXXXX6f6607&__referrer=sms-mms&PageSize=50&Page=0",
"previous_page_url": null,
"url": "https://messaging.twilio.com/v1/Services/MG03cXXXX/AlphaSenders?ServiceSid=MG03XXXX38b6f6607&__referrer=sms-mms&PageSize=50&Page=0",
"next_page_url": null,
"key": "alpha_senders"
},
"alpha_senders": [
{
"date_updated": "2019-11-01T07:39:26Z",
"alpha_sender": "Hubitat",
"capabilities": [
"SMS"
],
"account_sid": "AC772XXXXXXXb4ed4",
"url": "https://messaging.twilio.com/v1/Services/MG03c26XXXXXb6f6607/AlphaSenders/AIce7a88dbXXXXXX9c751a",
"sid": "AIce7a8XXXXX4a9c751a",
"date_created": "2019-11-01T07:39:26Z",
"service_sid": "MG03c265XXXX6f6607"
}
]
}

As I can understand from this I have defines my alphasender as "Hubitat".

I am not sure what this sid is: AIce7a88dbXXXXXX9c751a - Found out - it is called the Alpha Sender SID.

OK I uploaded a new version. I added a bunch of extra debugging. Please open the Logs in another browser tab, toggle the Enable debug logging on the container driver and click Save Preferences. While refreshing the page it should log a bunch of things, please post them or PM them to me so I can analyze.

Strange - it says:

dev:5472019-11-05 07:24:26.276 errorgetAlphaSenders: Invalid Service SID was probably entered. Twilio Server Returned: groovyx.net.http.HttpResponseException: NOT FOUND

dev:5472019-11-05 07:24:25.623 debugGenerating Alpha Sender list...

dev:5472019-11-05 07:24:25.616 debugPhone list generated, phoneNumbers: []

dev:5472019-11-05 07:24:24.709 debugGenerating Twilio phone number list...

dev:5472019-11-05 07:24:24.705 debugAPI credentials validated

dev:5472019-11-05 07:24:23.810 debugValidating API Credentials...

dev:5472019-11-05 07:24:23.712 debugInitializing Virtual Container

I have asked Twilio to look at this topic as it says I have put in an invalid Service SID.

That error is part of my code, not an official Twilio error.

Is their message.

Try this API and see if you can get a list of your Alpha Senders as that is what my updated code is executing. If you have success please post your curl example.

When I use this curl: curl 'https://messaging.twilio.com/v1/Services/MG03c2654cf67dXXXXXXX6f6607/AlphaSenders/AIce7a88XXXXXXXXX44a9c751a' -u AC772ee0XXXXXXXX0b4ed4:[AuthToken] I get this responce (I have anonymised several numbers via X'es):

200 - OK - The request was successful.
{
"date_updated": "2019-11-01T07:39:26Z",
"alpha_sender": "Hubitat",
"capabilities": [
"SMS"
],
"account_sid": "AC772XXXXXXXXXXXXXXXX5360b4ed4",
"url": "https://messaging.twilio.com/v1/Services/MG03c2654XXXXXXXXXXXXX6f6607/AlphaSenders/AIXXXXXXXXXXXXXXXXXX9c751a",
"sid": "AIce7XXXXXXXXXXXXXXX844a9c751a",
"date_created": "2019-11-01T07:39:26Z",
"service_sid": "MG03c2XXXXXXXXXXXXXXX6f6607"
}

And this curl: curl 'https://messaging.twilio.com/v1/Services/MG03c26XXXXXXXXXXX6f6607/AlphaSenders' -u AC772eeXXXXXXXXXXXXXXXX4ed4:[AuthToken] gets me this:

200 - OK - The request was successful.
{
"meta": {
"page": 0,
"page_size": 50,
"first_page_url": "https://messaging.twilio.com/v1/Services/MG03c2654XXXXXXXXXXXXXX607/AlphaSenders?ServiceSid=MG03c265XXXXXXXXXXXXXX8b6f6607&__referrer=sms-mms&PageSize=50&Page=0",
"previous_page_url": null,
"url": "https://messaging.twilio.com/v1/Services/MG03c26XXXXXXXXXXXXXXd38b6f6607/AlphaSenders?ServiceSid=MG03c26XXXXXXXXXXXXXXXXXX38b6f6607&__referrer=sms-mms&PageSize=50&Page=0",
"next_page_url": null,
"key": "alpha_senders"
},
"alpha_senders": [
{
"date_updated": "2019-11-01T07:39:26Z",
"alpha_sender": "Hubitat",
"capabilities": [
"SMS"
],
"account_sid": "AC772eXXXXXXXXXXXXXX415360b4ed4",
"url": "https://messaging.twilio.com/v1/Services/MG03c2654XXXXXXXXXXXXXXX38b6f6607/AlphaSenders/AIce7a88XXXXXXXXXXXXXXX4a9c751a",
"sid": "AIce7a8XXXXXXXXXXXXXXXXXX751a",
"date_created": "2019-11-01T07:39:26Z",
"service_sid": "MG03c26XXXXXXXXXXXXXXbd38b6f6607"
}
]
}

OK I had some extra parameters similar to the phone numbers API call to force a JSON response - something I am used to including for other Twilio APIs. Maybe this newer API doesn't allow those so I removed them on line 133 of the driver.

Please download and give it a try to see if it works. If not please provide debug output. Also please feel free to play around with line 133 of the code.
https://raw.githubusercontent.com/mlritchie/Hubitat/master/Drivers/Twilio%20SMS/Twilio-Container

Okay, now there is progress - the logs shows that it has found the alphasender "Hubitat"!

However, after I clicked save prefferences all prefferences dissapear, and in the device settings it just says: "No prefferences defined for this device", and also state: ContinerSize: 0, State Variables: vsIndex: 1.

I tried to create a device with label and phonenumber which also is shown in the logs:

dev:5772019-11-06 13:33:53.230 warnUnable to create device.

dev:5772019-11-06 13:33:53.189 debugAttempting to create Virtual Device: Label: SMS, Phone Number: +4530703119

dev:5772019-11-06 13:33:10.913 warnjava.lang.String cannot be cast to java.util.Map$Entry

dev:5772019-11-06 13:33:10.870 debugphoneList: '[]', alphaSenderList: '[Hubitat]'

dev:5772019-11-06 13:33:10.864 debugAlpha Sender list generated, alphaSenderList: [Hubitat]

dev:5772019-11-06 13:33:10.857 debugAlphaSenders response: 200

dev:5772019-11-06 13:33:10.038 debugGenerating Alpha Sender list...

dev:5772019-11-06 13:33:10.034 debugPhone list generated, phoneNumbers: []

dev:5772019-11-06 13:33:09.217 debugGenerating Twilio phone number list...

dev:5772019-11-06 13:33:09.213 debugAPI credentials validated

dev:5772019-11-06 13:33:08.244 debugValidating API Credentials...

dev:5772019-11-06 13:33:08.154 debugInitializing Virtual Container

I really appreciate your help!!!

@henrik.kristensen I believe I have a working solution as I asked a UK coworker to validate the receipt of a SMS. Please delete your Twilio devices in your device list and start over.

  • Add the Twilio Container driver in your Drivers Code area
  • Add the Twilio Device driver in your Drivers Code area
  • Navigate to Devices and create a new device using the user Twilio Container driver you just uploaded
  • Set your Account SID and Auth Token and toggle the Alpha Sender preference and click Save Preferences
  • Assuming your SID and Token validate, you will have an opportunity to enter your Alpha Sender preference and click Save Preferences again.
  • At the top enter your Device Label and E1.64 formatted phone number and click Create Device
  • Reload the browser page and scroll to the bottom and you should see a child Component Device for your phone
  • Click that link and enter text in the Device Notification box and the top and click the Device Notification and validate the receipt of the SMS
  • Assuming success you can now utilize this notification device in Rules and other areas of HE.
1 Like

YES!!!!! IT WORKS!!!!!!

Thank You so MUCH for your help - this is so awsome!!!!!!!!

1 Like

Awesome glad to hear it’s working.

1 Like

Is this driver no longer around? I get a no page exists when I click on the Github link above.

https://raw.githubusercontent.com/mlritchie/Hubitat/master/Drivers/Twilio%20SMS/Twilio-Container

https://raw.githubusercontent.com/mlritchie/Hubitat/master/Drivers/Twilio%20SMS/Twilio-Device

Excuse my Ignorance. So I put both the Container and Device code in Drivers Code. Then I would first have to select the Container as device, not Device?

Hope that made sense.

Thank you @aaiyar for posting links.

@j715 I have neglected to update this post since @chuck.schwer included this as a stock driver.

Differences from mine:

  1. Have parent container driver that creates children so you only have to enter the Twilio API once. It will create children versus button at top.
  2. Added support for Alpha Sender for @henrik.kristensen. This is something I’ve been meaning to alert @chuck.schwer about to consider for stock driver.

Otherwise unless you need the above features the stock driver works great.

Reason I was looking at this, was wondering if it could be modified to use the voice API also. Looks like a minor modification. I thought I would play around with it a little then let you know what I found out.

I have a friend who still likes to get phone calls when an alarm occurs. Can't budge him from this.

That’s much more involved and something g I have done at work. Twilio needs a callback URL for the actual content to speak which will more involved.

1 Like