Twilio自动回复器没有发回短信

时间:2016-10-25 04:32:34

标签: php heroku sms twilio

尝试启动并运行默认的自动回复代码。我把它托管在heroku上没有任何问题,我可以发短信,显然,twilio号确实收到了文字,但我没有收到任何回复到我自己的私人电话。

<?php
    require __DIR__ . '/vendor/autoload.php';
    use Twilio\Rest\Client;

    $sid='A...'; //blocked out the token
    $token='6....'; //blocked out the token
    $twilioNum='+1...'; //blocked out the number 


    $client = new Twilio\Rest\Client($sid, $token);

    function index(){
    $response = new Twilio\Twiml();
       $response->sms("Reply with one of the following keywords: monkey, dog, pigeon, owl.");
       echo $response;
    } 

    function monkey(){ 
       $response = new Twilio\Twiml();
        $response->sms("Monkey. A small to medium-sized primate that typically has a long tail, most kinds of which live in trees in tropical countries.");         

        echo $response;
    } 

    function dog(){
        $response = new Twilio\Twiml();
        $response->sms("Dog. A domesticated carnivorous mammal that typically has a long snout, an acute sense of smell, and a barking, howling, or whining voice."); 
        echo $response;
    } 


    $body = $_REQUEST['Body'];

    $result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); 
    $result = trim($result); 
    $result = strtolower($result);

    if(stripos($body, "monkey") !== FALSE) {
        monkey();
    } else if(stripos($body, "dog") !== FALSE) {
        dog();
    } else if(stripos($body, "hello") !== FALSE) {
        index();
    }
    ?>

当我将'monkey'发送到twilio号码时,我收到警告12200 Schema验证警告。这是检查员关于错误的内容:

<?xml version="1.0" encoding="UTF-8"?>
<Response><Sms>Monkey. A small to medium-sized primate that typically has a long tail, most kinds of which live in trees in tropical countries.</Sms>    </Response>

这告诉我它收到的文字知道我发送了该关键字。但是重新:TwiML,这与我的TwiML Bin的格式相同 - 它被分配给该消息传递服务。

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

您的问题是您使用的是<Sms> TwiML verb<Sms>用于在语音通话期间发送消息。

相反,您想使用<Message>。这应该是一个快速更改,您只需要在代码中将sms替换为message。以下是您的猴子功能应该是什么样的:

function monkey(){ 
   $response = new Twilio\Twiml();
   $response->message("Monkey. A small to medium-sized primate that typically has a long tail, most kinds of which live in trees in tropical countries.");         

    echo $response;
} 

让我知道这是否有帮助。