Last active
February 6, 2017 14:12
-
-
Save ObjectIsAdvantag/9d3239e9b87a42101bc7298c394296bf to your computer and use it in GitHub Desktop.
a Tropo script to learn SIP and SIP headers: on incoming call, speak the username of the calling SIP address; on outgoing call, speaks a basic text
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
// New incoming call | |
if (currentCall) { | |
answer(); | |
say("Welcome to Tropo SIP demo"); | |
wait(500); | |
say("Let's guess your username !"); | |
wait(500); | |
// Extract username from the "From" header: XXXXX <sip:[email protected]> | |
if (currentCall.getHeader("From")) { | |
var from= currentCall.getHeader("From").match(/\<sip\:(.*)\@(.*)>/); | |
if (from[1]) { | |
say("Found it! Hello " + from[1]); | |
wait(500); | |
say("<speak>which spells as <say-as interpret-as='characters'>" + from[1] + "</say-as></speak>"); | |
} | |
else { | |
say("Sorry, could not infer your username"); | |
} | |
} | |
else { | |
log("no SIP From header found ?!"); | |
say("Sorry, could not infer your username"); | |
} | |
wait(500); | |
say("Hope we'll see you soon on DevNet: Cisco's Developer Program"); | |
wait(500); | |
hangup(); | |
} | |
// script launched from the Tropo Token URL | |
// please either specifiy a sipaddress, a sip2sip username or a phonenumber if in US | |
else { | |
if (typeof sipaddress !== 'undefined') { | |
call("sip:" + sipaddress, { network: "SIP", headers: { "x-nickname":"Tropo scripting"}} ); | |
} | |
else { | |
if (typeof sip2sip !== 'undefined') { | |
call("sip:" + sip2sip + "@sip2sip.info", { network: "SIP", headers: { "x-nickname":"Tropo scripting"}} ); | |
} | |
else { | |
if (typeof phonenumber !== 'undefined') { | |
call (phonenumber); | |
} | |
else { | |
log("bad usage, no valid parameter found"); | |
} | |
} | |
} | |
wait(1000); | |
say("This is an outgoing call from Tropo"); | |
wait(500); | |
say ("Bye Bye dear Tropo developer"); | |
wait(500); | |
hangup(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment