Skip to content

Instantly share code, notes, and snippets.

@mykwillis
Created May 26, 2020 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mykwillis/4c8ae9775f06b004b55d8645861e873e to your computer and use it in GitHub Desktop.
Save mykwillis/4c8ae9775f06b004b55d8645861e873e to your computer and use it in GitHub Desktop.
Direqt Fetch for Twilio Functions
var axios = require('axios'); // Add 'axios' to Dependencies at https://www.twilio.com/console/functions/configure
exports.handler = function (context, event, callback) {
delete context[AUTH_TOKEN];
axios
.post(
'https://webhooks.direqt.io/twilio',
{ context, event },
{ params: { apiKey: context.DIREQT_API_KEY || event.DIREQT_API_KEY } }
)
.then(function (response) {
if (response.status !== 200) return callback();
var twiml = new Twilio.twiml.MessagingResponse();
twiml.message(response.data);
callback(null, twiml);
})
.catch(callback);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment