PHP script for TWILIO keyword response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dash12
    New Member
    • Jan 2017
    • 1

    PHP script for TWILIO keyword response

    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.

    Code:
    <?php
    
    require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
    
    $from = $_REQUEST['From'];
    $body = $_REQUEST['Body'];
    $result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); 
    $result = trim($result); 
    $result = strtolower($result); 
    print_r($result);
    
    /*Match the ‘Body’ field with index of keywords */ 
             
    if( $result == '1' ){
    	$response = 'Hi, We will be in touch with you!';
        
    }else if( $result == 'hello' ){
         $response = 'Thank you!';
    
    }else if( $result == 'Support' ){
        $response = 'Thank you! An agent will be in touch shortly.';
    
    }else if( $result == 'LINK' ){
       $response = 'https://google.com';
    
    
    }
    
    // header('content-type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    
    ?> <Response> <Message><?php echo $response; ?></Message> </Response>
    Last edited by Dormilich; Jan 19 '17, 08:52 AM. Reason: please use code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    have you checked what the raw Twilio response contains?

    Comment

    Working...