Need help formatting a Webhook to call Twilio

First a little background. I have several projects that need to send SMS texts for various notifications. I use a service called Twilio to actually send those SMS messages. I was (and still am) unable to figure out how to format a Webhook request to fire off directly to Twilio, so I use an intermediate service from Script.io

I need to eliminate the use of Scriptr.io and have the Webhook go directly to Twilio. The code (json?) to fire these requests in Scriptr.io looks like:

var callResult = http.request({
	"url" : "https://api.twilio.com/2010-04-01/Accounts/xxx...mytoken...xxx/Messages.json",
	"method": "POST",
	"params": {"From": "2055551212", "To": “6095551212”, "Body": “Text I want to send”},
	"authCreds": ["xxx...mytoken...xxx "]
});

[NOTE: I’ve simplified some things – the phone numbers, text, etc are actually done using some variables – I’ve hard-coded the above just to make it clearer what this is doing.]

My question is how do I format a new Webhook to call Twilio with the above set of parameters? Specifically, what do I put for Full URL, Form, and Headers? The text (“Text I want to send”) will be passed as part of the Publish call.

The Webhook I’m currently using to call Scriptr.io look like:

Name		      Mail for scriptr.io
Event Name	      Mail
Full URL	      https://api.scriptrapps.io/Mail/
Request type	  POST
Request format	  Web Form
Form		      {
		             “sms”: “{{sms}}”
		          }
Headers	          {
		             “Content-type”:  “applications/x-www-form-urlencoded”,
		             “authorization”:  “bearer: xxx…my token…xxx”
		          }
Enforce SSL	      Yes

Any help in reformatting this Webhook to call Twilio directly would be appreciated. Thanks.

The SmsWebhookRK library sends to Twilio using a webhook. You don't need to use the library, you can just look at how the webhook is set up and do the same thing.

2 Likes

Perfect! Thank you