I want to create a Twilio Function that will trigger two webhook endpoints for AutoPilotHQ & FrontApp.
I\'ve tried what\'s suggested here which suggest create the fo
Does this below Twilio Function work?
Make sure you add querystring and axios as Twilio Function dependencies.
const axios = require('axios');
const qs = require('querystring');
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.MessagingResponse();
let {
ApiVersion,
SmsSid,
SmsStatus,
SmsMessageSid,
NumSegments,
ToState,
From,
MessageSid,
AccountSid,
ToCity,
FromCountry,
ToZip,
FromCity,
To,
FromZip,
ToCountry,
Body,
NumMedia,
FromState
} = event;
let requestBody = {
ApiVersion,
SmsSid,
SmsStatus,
SmsMessageSid,
NumSegments,
ToState,
From,
MessageSid,
AccountSid,
ToCity,
FromCountry,
ToZip,
FromCity,
To,
FromZip,
ToCountry,
Body,
NumMedia,
FromState
};
let url1 = "https://example.com/1";
let url2 = "https://example.com/2";
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}};
Promise.all([
axios.post(url1, qs.stringify(requestBody), config),
axios.post(url2, qs.stringify(requestBody), config)
]).then(result => {
callback(null, twiml);
}).catch(err => {
console.log(err);
callback(err);
});
};