Created
May 26, 2020 02:53
-
-
Save mykwillis/4c8ae9775f06b004b55d8645861e873e to your computer and use it in GitHub Desktop.
Direqt Fetch for Twilio Functions
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
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