Last active
November 25, 2022 13:05
-
-
Save Anshul0305/84e8aa12a7fc6f395765678be247697a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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