-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Twilio sms request. Has provisions for stateful interactions, but not…
… fully working.
- Loading branch information
Showing
1 changed file
with
50 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |