[RELEASE] WhatsApp integration to SmartThings (2-way messaging)

I my piston got so big I had to break it up

My main piston that handles the incoming messages

1 Like

Same here. I had to break up my pistons to accomodate more commands as well.

BTW
is everything working on your end? I’m just curious as there are some users, including myself is currently seeing that the service is down. Looking at the Twilio logs, there is an error. I’m thinking that this could be a Twilio thing.

Looks like there was a problem either with Twilio or ST’s cloud. Everything is back to normal as before.

Its not been very reliable since the weekend
Messages not arriving
and today my webcore keep alive went weird too


The Twilio Debug complains alot about “[12300 - Invalid Content-Type]” anyone know how to stop that from happening

Haven’t seen the error on Twilio on my end. It was a little shaky a few days ago but things seem to have been back to normal now. You still having stability issues?

Need to test my webCoRE code but I mainly use it leaving places so. It’s hard to test.

The errors

1 Like

Hi , hoping to resurrect this thread in light of ST cutting off our SMS feed in the UK. I was trying to see if I can make this work to replace the SMS services by using a webcore piston activated by a virtual switch to indicate a changed state.

But I am struggling to get it to work (send a message to whatsapp).

I have followed the instructions (which were very good) and the webcore pistion now works without any errors.

You do need to use a different url to use the api thou (found this on Twilio help pages https://[account SID}:{auth token}@api.twilio.com/2010-04-01/Accounts)

but when I run the piston nothing happens. No errors in the logs but nothing


tried everything I can thing off
 does anyone have any ideas ? I am not familiar with Twilio and the Whastapp sandbox but it appears to be workign to a point. Help please.

Can you try setting up a simple piston just to make sure that you are able to get the message through to whatsapp? This is a simple piston that you can use:

Also make sure that you POST FORM data. Here is an example of how the post should look like:

Hope that helps.

Thank you for the reply . Here is the piston I made and couldnt get to work. I have changed the numbers to dummy ones and replaced the account sid and auth token as well. But these fields were populated correctly.

I have also attached the log screen shot from when I ran in webcore and as you can see no errors but nothing appears in Twilio

My areas of confusion were

  1. The URL for the Make a Post 
 in your example and all others it shows a webcore url
 surely that should be the API URL as I have in mine and as per the instructions I followed. Am I right on that one as that confused me totally.

  2. The main point that seems to confuse me is the workflow. As per the instructions I took the url link from the quick spec in webcore and pasted it into the twilio sandbox “when a message comes in” box. My thinking is that webcore send this message via that url to Twilio and then Twilio should interpret and send the whatsapp message accordingly. is that not the case 
 if that’s not correct please say as I’m confused as to the workflow here.

Many thanks

webcore%20piston%20log for your help.

regards

Andy

Sorry forgot to add , this is the setting re the web request - url with account asid and auth token removed thou.

When you share an annoymous snapshot of the piston from webcore, url’s are automatically switched to the default url. The actual url that yu should be using is:-

https://api.twilio.com/2010-04-01/Accounts/[twilioAccountSid]/Messages.json

Just replace [twilioAccountSid] with your Sid. You can get this from the gears icon on the top right of your twilio page and click on Settings.

The piston you have should work if all the credentials are correct. Just to go through to make sure everything is correct

The “To” field, this would be most likely your mobile number. Make sure that it is registered in your sandbox. You should see this number under ‘Sandbox Participant’.

On your second point -

  1. The main point that seems to confuse me is the workflow. As per the instructions I took the url link from the quick spec in webcore and pasted it into the twilio sandbox “when a message comes in” box. My thinking is that webcore send this message via that url to Twilio and then Twilio should interpret and send the whatsapp message accordingly. is that not the case 
 if that’s not correct please say as I’m confused as to the workflow here.

This is mainly for receiving messages. Let’s get you sorted out on sending message before we tackle the receiving bit.

Let me know how this goes.

Hi ,

Thank you for the help. I changed the url as suggested and another basic error I spotted (typo) and its working better in that it now shows int he Twilio console but with an error that is

(Error: 63016) Failed to send freeform message because you are outside the allowed window. Please use a Template.

Now I have looked into this and I cannot see where this could be wrong. I have a To, From and Body and the settings as suggested so now baffled ?

Tied to understand Twilio templates but cannot find any documents that show examples so a little stuck.

Regards

Andy

This is actually a security protocol from twilio or whatsapp. If a conversation between a registered number and your app is not active after 24 hours, you will need to reinitiate a new conversation. From your registered mobile send a whatsapp message as specified in your sandbox with “join x-y”. And then try firing the piston, it should work this time.

The problem here is that if there is no 2 way conversation after 24 hours, the link is killed and you will have to start all over again.

To overcome this, i have a Shortcut (on iOS) send a whatsapp message to the twilio number everytime i activate ‘Good Night’ - this is a shortcut that does other stuff as well like turn off lights, set phone to silent
and send a whatsapp message.

When twilio receives this message, it will fire another piston - the url you enter in “when a message comes in”.

I hope all this makes sense :slight_smile:

Hi, Thanks for coming back to me.

I thought that might be the case as I read it on Twilio site but wasn’t sure. Anyway tried it and it worked straight away 
 so now I need to work out how to integrate that into SHM alerts.

In the meantime your method using IOS shortcuts sounds interesting
 how to you link the good night routine to the IOS shortcuts as I cant see a way of doing that ?

Once again many thanks for you help.

Regards

Andy

Hi Again

Just an update. I used that piston and amended it so when the goodnight routine runs it sends a message via Twilio to keep the session alive. Did try IOS shortcuts and got them working via IFTTT as a test
 But that was the wrong direction for me as I was looking to use the shortcut to control ST, which I couldn’t figure out (well not just yet)

As my original goal was to find a way to replace the SMS that ST stopped sending in Sept, I have created a few more slightly modified pistons to do that based on status of virtual switches that are only activated by SHM if an alert such as security, smoke , leak etc occurs .

Got to say it works really well. Takes a bit of setup and some knowledge of webcore but easy once you have one working.

Thanks you again for all your help

Regards

Andy

Great to hear that you got things working.

Siri Shortcuts actually is the main initiator for the whole process. So when i say “Hey Siri, time for bed”, it kick’s off my good night routine like putting my phone to silent, turning on DND, set alarms, fires a webcore piston (using the ‘URL’ action - enter the piston that you want to fire and then use the ‘Get Contents of URL’ action to post any variables you would like to include to your webcore piston, in my case is the name of the sleeper - that way webcore can then trigger automation according to who is sleeping.) and finally sending a whatsapp message.

Thanks for your assistance in getting this working. My only downside it the 24 hr session limit on Twilio that seems to be less than 24 and does need the constant wake up to keep alive.

Looking at way to send the wake up message as part of the real message I need , so in other words send the key word wake up message followed a few seconds after by the real message
 shouldn’t be too difficult in webcore.

Regards

Andy

1 Like

Hi,
can you share your pistons? what are the On / Off / Status pistons?