Twilio自动回复器没有发回短信(Twilio autoresponder not sending sms back)

编程入门 行业动态 更新时间:2024-10-28 10:27:06
Twilio自动回复器没有发回短信(Twilio autoresponder not sending sms back)

尝试启动并运行默认的自动应答代码。 我已经在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号码发短信“猴子”时,会收到警告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>

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

Trying to get the default Autoresponder code up and running. I've hosted it on heroku with no issue, I can text the number, and apparently, twilio number does receive the text, but I haven't received any responses back to my own personal phone.

<?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(); } ?>

When I sms 'monkey' to the twilio number, I get a Warning 12200 Schema validation warning. This is what was in the inspector about the error:

<?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>

Which tells me that it received the text to know I sent that keyword. But re: the TwiML, this is the same format for my TwiML Bin -- it's assigned to that messaging service.

最满意答案

Twilio开发人员在这里传播信息。

你的问题是你正在使用<Sms> TwiML动词 。 <Sms>用于在语音呼叫期间发送消息。

相反,你想使用<Message> 。 这对你来说应该是一个快速的改变,你只需要在你的代码中用message代替sms 。 这是你的猴子功能应该看起来像什么:

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; }

让我知道这是否有帮助。

Twilio developer evangelist here.

Your problem is that you're using the <Sms> TwiML verb. <Sms> is used for sending messages during a voice call.

Instead, you want to use <Message>. It should be a quick change for you, you just need to replace sms with message in your code. Here's what your monkey function should look like instead:

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; }

Let me know if that helps at all.

更多推荐

本文发布于:2023-08-04 09:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1414878.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动回复   短信   Twilio   sms   sending

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!