473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP script for TWILIO keyword response

1
I have the following script for getting a response from the Twilio number when a sms is sent to it. However, when I run my script, it doesn't work for all keywords. I am not sure why? It runs for '1' and 'hello' as keywords but that's it.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
  4.  
  5. $from = $_REQUEST['From'];
  6. $body = $_REQUEST['Body'];
  7. $result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); 
  8. $result = trim($result); 
  9. $result = strtolower($result); 
  10. print_r($result);
  11.  
  12. /*Match the ‘Body’ field with index of keywords */ 
  13.  
  14. if( $result == '1' ){
  15.     $response = 'Hi, We will be in touch with you!';
  16.  
  17. }else if( $result == 'hello' ){
  18.      $response = 'Thank you!';
  19.  
  20. }else if( $result == 'Support' ){
  21.     $response = 'Thank you! An agent will be in touch shortly.';
  22.  
  23. }else if( $result == 'LINK' ){
  24.    $response = 'https://google.com';
  25.  
  26.  
  27. }
  28.  
  29. // header('content-type: text/xml');
  30. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  31.  
  32. ?> <Response> <Message><?php echo $response; ?></Message> </Response>
Jan 18 '17 #1
1 1732
Dormilich
8,658 Expert Mod 8TB
have you checked what the raw Twilio response contains?
Jan 19 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: José | last post by:
I'm programming a simple script to calculate response time from one server to another server. I put the time in secons in a variable. I take the web, and I take the time again, the difference is...
6
by: Paul Winkler | last post by:
This is driving me up the wall... any help would be MUCH appreciated. I have a module that I've whittled down into a 65-line script in an attempt to isolate the cause of the problem. (Real...
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
3
by: Lucvdv | last post by:
I want to return a 404 response from an ASP script (IIS 5). Response.Status lets me set the response string, but if I don't include any HTML text myself, the result is an empty page. Is there...
2
by: Robert | last post by:
I am attempting to run setup on a v7.2 EE CD using a response file as input. This should result in my existing server configuration being replicated on a new server. My problem is that I have 18...
3
by: Sehboo | last post by:
On my ASP page, when I click a button, I want to do three things: 1. Check for some values. 2. Open a new window and pass some values as query string. 3. Redirect to some other page Here...
3
by: DotNetJunkies User | last post by:
How can I dispay a web page in another instance of IE? Response.redirect replaces the current page, but I need to direct my user in a new browser instance. --- Posted using Wimdows.net NntpNews...
0
by: jose.mendez22 | last post by:
I'm trying to fire a pop-up window before I execute a lengthy stored procedure so I may utilize this window as a status window on number of records executed. After my response.write statements...
7
by: samuelberthelot | last post by:
Hi, I have the following in my asp page: <% response.write(Header) %> where Header contains HTML markup such ass <html> <body> .... I must write the code in the aspx file and not in the...
4
by: yawnmoth | last post by:
Is it possible to send http requests with curl but not have curl wait for the response? The reason I ask is because I'd like to code a web app that can sorta start time consuming processes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.