-
-
Save danyork/807926 to your computer and use it in GitHub Desktop.
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
<?php | |
/* | |
* A script demonstrating how to store user inut in an external database. | |
*/ | |
// A function to store a document in CouchDB using cURL. | |
function saveData($callerID, $channel, $network, $text) { | |
$doc = json_encode(array("callerID" => $callerID, "channel" => $channel, "network" => $network, "text" => $text)); | |
$url = COUCH_DB_HOST.":".COUCH_DB_PORT."/".COUCH_DB_NAME; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json")); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $doc); | |
curl_exec($ch); | |
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != '201') { | |
return false; | |
} | |
return true; | |
} | |
// The details of our CouchDB instance. | |
define("COUCH_DB_HOST", "http://markh.couchone.com"); | |
define("COUCH_DB_PORT", "5984"); | |
define("COUCH_DB_NAME", "tropo"); | |
// Properties of $currentCall object we want to persist. | |
$callerID = $currentCall->callerID; | |
$channel = $currentCall->channel; | |
$network = $currentCall->network; | |
$text = $currentCall->initialText; | |
// Logic to store document in a CouchDB instance and respond to user. | |
if(saveData($callerID, $channel, $network, $text)) { | |
_log("*** Answer saved successfully. ***"); | |
say("Thanks for your input."); | |
} else { | |
_log("*** Oops! There was a problem saving the answer. ***"); | |
say("Sorry, I didn't get that. Try again later."); | |
} | |
?> |
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
/** | |
* A simples script to demonstrate event injection in Tropo. | |
*/ | |
log('************ Session ID is ' + currentCall.sessionId + ' ************'); | |
say('http://hosting.tropo.com/59718/www/audio/on-hold-music.wav', { | |
allowSignals: 'exit' | |
}); | |
say('You are no longer on hold.'); |
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
/** | |
* A simple hello world app for Tropo. | |
*/ | |
say('Hello, world!'); |
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
// A simple outbound message script for Tropo. | |
message(messageToSay, {"to":"tel:+1" + numberToCall, "network":"SMS"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment