Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created January 31, 2011 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mheadd/804867 to your computer and use it in GitHub Desktop.
Save mheadd/804867 to your computer and use it in GitHub Desktop.
Tropo example scripts
<?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", "");
define("COUCH_DB_PORT", "");
define("COUCH_DB_NAME", "");
// 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.");
}
?>
/**
* 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.');
/**
* A simple hello world app for Tropo.
*/
say('Hello, world!');
// 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