Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Twilio sms request. Has provisions for stateful interactions, but not…

… fully working.
  • Loading branch information...
commit 09471cc5af1b872950dd27e12b5d5a1760193e69 1 parent 79c4299
@kamron kamron authored
Showing with 50 additions and 3 deletions.
  1. +50 −3 smsrequest.php
View
53 smsrequest.php
@@ -1,9 +1,56 @@
<?php
+require ('./query.php');
+// start the session
+session_start();
+
+// This is the state we're in
+$state = $_SESSION['state'];
+// Previous query (if there is one)
+$state = $_SESSION['query'];
+
+// Create the state if you're ready!
+if(!strlen($state)) {
+ $state = 'QUERY';
+}
+
+$sender = $_POST["From"] // The phone number that sent this message.
+$query = $_POST["Body"] // The text body of the SMS message. Up to 160 characters long.
+$pieces = explode(",", $_POST["Body"], 2); // Split the query into two
+
+$results = get_results($pieces[0], $pieces[1]); // Pass in the data
+
+$message=''; // The final message to be sent
+
+if(count($results)>1) // Handles if there is more than result
+{
+ if($state = 'MORE' && strcasecmp( 'MORE' , $query )==0) // Set back to QUERY after a MORE
+ {
+ $message=$results[0]." ".$results[1];
+ $state = 'QUERY';
+ $_SESSION['query']='';
+ }
+ else //
+ {
+ $message=$results[0]." ".$results[1];
+ $_SESSION['query'];
+ $state = 'MORE';
+ }
+}
+if(count($results==1))
+{
+ $message=$results[0]." ".$results[1];
+}
+
+if(empty($result))
+{
+ $message='No results found!';
+}
+
+$_SESSION['state'] = $state;
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-
?>
<Response>
-
-</Response>
+ <sms><?php echo $message; if(count($results)>1 && $state=='QUERY' ) ' Text MORE for more results.'; ?></sms>
+</Response>
Please sign in to comment.
Something went wrong with that request. Please try again.