So I am trying to take an incoming SMS and based on what the SMS says make a call with a specific recording.
For example:
I have a door sensor with a modem that can send a text to my twilio # when the door is open or when the door is closed.
If Twilio receives "door open" text then twilio will call my cell phone and plays recording that says "door is open"
If Twilio receives "door closed" text then twilio will call my cell phone and plays recording that says "door is closed"
<?php
require_once('/home/protranx/public_html/twilio-php- latest/Services/Twilio.php');
$sid = "SID";
$token = "Token";
$client = new Services_Twilio($sid, $token);
$alert = $_REQUEST['body'];
$TwilioNumber = "+twilio #";
$to = "+my cell #";
$url1 = "http://protran.x10.mx/Oak1_armed_door_open.php";
$url2 = "http://protran.x10.mx/Oak1_disarmed_door_closed.php";
$string1 = "door open";
$string2 = "door closed";
if ($alert == $string1){
$call = $client->account->calls->create($TwilioNumber, $to, $url1);}
elseif ($alert == $string2){
$call = $client->account->calls->create($TwilioNumber, $to, $url2);}
echo $call->sid;
header('content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
</Response>
I keep getting this error: Error: 12100 - Document parse failure
Any help would be greatly appreciated.
Thank you
Twilio evangelist here.
Hard to tell from your code, as it generally looks right.
One thing that occasionally trips me up is spaces being rendered before the start of the xml or between the xml declaration and the root element, so you might check for either of those that since those can be hard to catch.
For example, I'm not sure you need the newline that you have at the end of your xml declaration.
Hope that helps.
来源:https://stackoverflow.com/questions/21147543/how-do-i-take-an-sms-and-make-a-call-to-alert-someone-based-on-what-sms-says