Skip to content

Instantly share code, notes, and snippets.

@Anshul0305
Last active November 25, 2022 13:05
Show Gist options
  • Save Anshul0305/84e8aa12a7fc6f395765678be247697a to your computer and use it in GitHub Desktop.
Save Anshul0305/84e8aa12a7fc6f395765678be247697a to your computer and use it in GitHub Desktop.
const unirest = require('unirest');
const { base64encode } = require('nodejs-base64');
function sendWhatsappMedia(MediaUrl){
// ENTER THE DETAILS BELOW
const AccountSID = "YOUR TWILIO ACCOUNT SID";
const AuthToken = "YOUR TWILIO AUTH TOKEN";
// DO NOT CHANGE ANYTHING BELOW
const data = request.body.originalDetectIntentRequest.payload;
const To = data.From;
const From = data.To;
const Authorization = base64encode(`${AccountSID}:${AuthToken}`);
console.log("From", From);
console.log("To", To);
console.log("Auth", Authorization);
console.log("MediaUrl", MediaUrl);
const req = unirest('POST', `https://api.twilio.com/2010-04-01/Accounts/${AccountSID}/Messages.json`)
.headers({
'Authorization': `Basic ${Authorization}`
})
.field('To', To)
.field('From', From)
.field('MediaUrl', MediaUrl)
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});
}
@yzmaya
Copy link

yzmaya commented Jun 13, 2022

Hi, thanks for your post, i have a question, what kind of setting need, to paste my id and token of twilio, because i try with account keys of producction and test, can you help me? regards of México

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment