Created
January 28, 2011 16:16
-
-
Save mheadd/800473 to your computer and use it in GitHub Desktop.
A simple PHP script that runs n Tropo scripting that stores user input on multiple text channels to a CouchDB instance.
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
| <?php | |
| // 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."); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment