How to send a whatsapp message through twilio via zapier webhook

Viewed 2910

Currently trying to create a Whatsapp message to be sent via This custom Javascript code on Zapier shown via Twilio API. It successfully reaches out to twilio but returns "Authentication Error - No credentials provided".

var messagesUrl = "https://api.twilio.com/2010-04-01/Accounts/<accountSID>/Messages.json";
var payload = {
 "To": "whatsapp:<tonumber>",
 "Body" : "Hey This is a test",
  "From" : "whatsapp:<fromnumber>"
};
 var options = {
 "method" : "post",
 "payload" : payload
};

options.headers = {
 "Authorization" : "Basic <accountsid>:<accounttoken>"
};
fetch(messagesUrl, {options, body: JSON.stringify(payload)})
 .then(function(binaryResponse) {
  return binaryResponse.json();
})
.then(function(jsonResponse){
  callback(null, {result: jsonResponse});
}).catch(callback);

What is the best approach to take to simply send a confirmation text on whatsapp to prospects on zapier? Thanks in advance

4 Answers

fetch takes an options object as its second argument. You're currently doing:

fetch (messagesUrl, {
  options: {
    method: 'post',
    payload: payload,
    headers: {
      Authorization: '...'
    }
  },
  body: JSON.stringify(payload)
}) // ...

You shouldn't have a nested option object. Assuming the twilio stuff is set up correctly (I have no idea), this should work:

fetch (messagesUrl, {
  method: 'post',
  payload: payload, // probably remove this, it's not part of the syntax (see below)
  headers: {
    Authorization: '...'
  }
  body: JSON.stringify(payload)
}) // ...

all options you can pass to the second argument: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Syntax

Thank you for your help, i ended up solving this by using a much simpler Custom web hook POST method, i was over-complicating it. Details on how i did this for anybody else wanting to send whats-app messages through Twilio on Zapier Below:

Method

Post

URL

https://api.twilio.com/2010-04-01/Accounts/<accountSID>/Messages.json

Data

To=whatsapp:%2B<toNumber>&From=whatsapp:%2B<fromNumber>&Body=Put your message body here

Note: The + of your E.164 number will concatenate hence the %2B to replace it

Basic Auth

<AccountSID>|<AccountToken>

Headers

Content-Type | application/x-www-form-urlencoded

I found this post very very interesting. I also use ZAPIER and TWILIO and I would like to have a customer who registers on my googlesheet receive a confirmation whatsapp message.

I can't configure ZAPIER. I did a lot of tests but I don't understand much about programming and I certainly made a mistake.

When I launch the test from ZAPIER it gives me this error: The request could not be sent to Webhooks by Zapier. The app returned "A 'To' phone number is required.".

I have attached the image with the inserted configuration. Where did I go wrong? How should I correct it?

enter image description here

UPDATE: my approved template on whatsapp is this:

Ciao {{1}}, la tua registrazione è avvenuta con successo.
Ricordati che lo SCONTO che hai scelto è attivo fino al {{2}}. 
Ti aspettiamo - nei prossimi giorni - nel tuo Centro LIGHT di fiducia.

Nell'attesa ti facciamo ancora i migliori Auguri
Staff LIGHT

The generated text is this

Ciao%20%7B%7B1%7D%7D%2C%20la%20tua%20registrazione%20%C3%A8%20avvenuta%20con%20successo.%0ARicordati%20che%20lo%20SCONTO%20che%20hai%20scelto%20%C3%A8%20attivo%20fino%20al%20%7B%7B2%7D%7D.%20%0ATi%20aspettiamo%20-%20nei%20prossimi%20giorni%20-%20nel%20tuo%20Centro%20LIGHT%20di%20fiducia.%0A%0ANell%27attesa%20ti%20facciamo%20ancora%20i%20migliori%20Auguri%F0%9F%8E%81%F0%9F%8E%89%F0%9F%8E%8A%0AStaff%20LIGHT

Error Reported:

ERROR 63016 Failed to send freeform message because you are outside the allowed window. Please use a Template.

DESCRIPTION Failed to send freeform message because you are outside the allowed window. Please use a Template.

Its better to watch this video to be able to understand the complications around the message templates and zapier customization

You will face some issues if you didn't control the new lines in the templates and to avoid message failure

Related