有人可以帮助修改Twilio建议的代码来搜索传入的短信机构以发送不同的响应吗? https://www.twilio.com/help/faq/sms/how-do-i-build-a-sms-keyword-response-application
需要更改代码,以便它在传入的SMS中搜索关键字“logging”,例如“需要帮助登录”,然后会发送不同的响应。
/* Controller: Match the keyword with the customized SMS reply. */
function index(){
$response = new Services_Twilio_Twiml();
$response->sms("Hi. Received your message. We will contact you via email on file.");
echo $response;
}
function password(){
$response = new Services_Twilio_Twiml();
$response->sms("Hi. Received your message. We will contact you via email on file. #Password");
echo $response;
}
function logging(){
$response = new Services_Twilio_Twiml();
$response->sms("Hi. Received your message. We will contact you via email on file. #Logging");
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 'password’':
password();
break;
case 'logging':
logging();
break;
/* Optional: Add new routing logic above this line. */
default:
index();
}
答案 0 :(得分:0)
来自Twilio的Ricky再次来到这里。
很高兴你有东西在你的东道主上工作!如您所见,当前代码示例仅在某人将确切的单词“logging”作为其邮件正文发送时才匹配。如果你想匹配字符串中的文本(例如:“需要帮助登录”),我会使用PHP的stripos
函数。有了这个,你可以这样做:
> m_list[2,2] <-'4'
> m_list
[,1] [,2]
[1,] "1" 3
[2,] 2 "4"