尝试启动并运行默认的自动应答器代码。我把它托管在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();
}
?>
当我向twilio号码发送"monkey"时,我得到一个警告12200模式验证警告。以下是检查器中关于错误的内容:
<?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>
告诉我它收到了文本,知道我发送了那个关键字。但是re: the TwiML,这是我的TwiML Bin的相同格式——它被分配给那个消息服务。
这里是Twilio开发者布道者。
你的问题是你正在使用<Sms>
TwiML动词。<Sms>
用于语音通话时发送消息
应该使用<Message>
。这对您来说应该是一个快速的更改,您只需要将代码中的sms
替换为message
。下面是monkey函数的样子:
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;
}
如果有帮助请告诉我