我已经搜索了高低,找不到答案,但找不到它。我正在尝试将Twilio供电的sms响应器集成到我的房地产网站中。到目前为止,我能够响应单个关键字并提供适当的响应。
但是,使用它的方式将要求应用程序通过短信文本字符串查找字符串中的任何关键字并进行适当的响应。
例如,我可以让以下内容完美地运作:单个关键字'列出'发短信,然后它提供响应。但是,如果有人发短信“你能告诉我在任何一条街道的123上市情况吗?”'响应者将无法回应。
我需要一种方法让它找到'列出'该字符串中的(或任何其他关键字)并响应该关键字而不是忽略整个事物。
这就是我正在处理的事情(显然我的关键字会有所不同):
<?php
/* Include twilio-php, the official Twilio PHP Helper Library,
* which can be found at
* http://www.twilio.com/docs/libraries
*/
include('Services/Twilio.php');
/* Controller: Match the keyword with the customized SMS reply. */
function index(){
$response = new Services_Twilio_Twiml();
$response->sms("Reply with one of the following keywords:
monkey, dog, pigeon, owl.");
echo $response;
}
function monkey(){
$response = new Services_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 Services_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;
}
function pigeon(){
$response = new Services_Twilio_Twiml();
$response->sms("Pigeon. A stout seed- or fruit-eating bird with
a small head, short legs, and a cooing voice, typically having gray and
white plumage.");
echo $response;
}
function owl(){
$response = new Services_Twilio_Twiml();
$response->sms("Owl. A nocturnal bird of prey with large
forward-facing eyes surrounded by facial disks, a hooked beak,
and typically a loud call.");
echo $response;
}
/* Read the contents of the 'Body' field of the Request. */
$body = $_REQUEST['Body'];
/* Remove formatting from $body until it is just lowercase
characters without punctuation or spaces. */
$result = preg_replace("/[^A-Za-z0-9]/u", " ", $body);
$result = trim($result);
$result = strtolower($result);
/* Router: Match the ‘Body’ field with index of keywords */
switch ($result) {
case 'monkey':
monkey();
break;
case 'dog':
dog();
break;
case 'pigeon':
pigeon();
break;
case 'owl':
owl();
break;
/* Optional: Add new routing logic above this line. */
default:
index();
}
在此处找到:https://www.twilio.com/help/faq/sms/how-do-i-build-a-sms-keyword-response-application
我发现了这个:
/* Read the contents of the 'Body' field of the Request. */
$body = $_REQUEST['Body'];
// Check to see if contains the word "logging"
if(stripos($body, "logging") !== FALSE) {
// message contains the word "logging"
} else {
// message does not contain the word "logging"
}
在此处找到:twilio sms keyword autoresponder search incoming body
但它似乎不起作用,或者我无法弄清楚如何正确实施它。
FWIW,我不是程序员,但对此的理解有限。我只是想尝试构建自己的工具,因为开箱即用的解决方案对我不起作用。感谢您的帮助,随时提出您需要的任何问题。