How do I take an SMS and make a call to alert someone based on what SMS says?

蓝咒 提交于 2019-12-04 06:41:08

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!