Can someone help to revise the suggested code from Twilio to search through the incoming sms body to send different responses? https://www.twilio.com/help/faq/sms/how-do-i-build-a-sms-keyword-response-application
Need to alter code so that it searches the incoming SMS for keyword "logging" e.g. "Need help logging in", then the a different response will send.
/* 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();
}