Last active
October 14, 2018 18:20
-
-
Save ShelbyZ/a515ff013a24dbc5ca10fbb9765780fb to your computer and use it in GitHub Desktop.
Twilio Function template for A or B
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
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