Created
November 9, 2015 21:38
-
-
Save nikmartin/239b58140366642233ef to your computer and use it in GitHub Desktop.
Google Apps Script to produce Twilio TWIML
This file contains hidden or 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 doGet(e) { | |
var toNum = e.parameter.PhoneNumber; | |
var fromNum = e.parameter.CallerId; | |
var action = e.parameter.Direction; | |
var record = e.parameter.Record; | |
Logger.log(e); | |
var output = ContentService.createTextOutput(); | |
var xml = createDialTWIML(fromNum, toNum, action); | |
output.setMimeType(ContentService.MimeType.XML); | |
output.setContent(xml); | |
return output; | |
} | |
function createDialTWIML(fromNum, toNum, action, record) { | |
var root = XmlService.createElement('Response'); | |
var say = XmlService.createElement('Say') | |
.setAttribute('voice', 'alice') | |
.setAttribute('language', 'en-US') | |
.setText('This call will be recorded'); | |
root.addContent(say); | |
var dial = XmlService.createElement('Dial') | |
.setAttribute('callerId', fromNum) | |
.setAttribute('timeout','60') | |
.setAttribute('record','record-from-answer'); | |
var number = XmlService.createElement('Number').setText(toNum); | |
dial.addContent(number); | |
root.addContent(dial); | |
var document = XmlService.createDocument(root); | |
var xml = XmlService.getPrettyFormat().format(document); | |
Logger.log(xml); | |
return xml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment