Skip to content

Instantly share code, notes, and snippets.

@ShelbyZ
Last active October 14, 2018 18:20
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 ShelbyZ/a515ff013a24dbc5ca10fbb9765780fb to your computer and use it in GitHub Desktop.
Save ShelbyZ/a515ff013a24dbc5ca10fbb9765780fb to your computer and use it in GitHub Desktop.
Twilio Function template for A or B
function AorB (event) {
try {
console.log(JSON.stringify(event));
} catch {
// no-op
}
let response = new Twilio.Response();
response.setStatusCode(200);
let body;
if (event.a) {
body = event.a;
} else if (event.b) {
body = event.b;
} else {
console.log('a and b both undefined');
}
console.log(`responding with body: ${body}`);
if (event.json && event.json.toLowerCase() == 'true') {
response.appendHeader('Content-Type', 'application/json');
body = JSON.parse(body);
}
response.setBody(body);
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment