0
votes

Trying to get the default Autoresponder code up and running. I've hosted it on heroku with no issue, I can text the number, and apparently, twilio number does receive the text, but I haven't received any responses back to my own personal phone.

<?php
    require __DIR__ . '/vendor/autoload.php';
    use Twilio\Rest\Client;

    $sid='A...'; //blocked out the token
    $token='6....'; //blocked out the token
    $twilioNum='+1...'; //blocked out the number 


    $client = new Twilio\Rest\Client($sid, $token);

    function index(){
    $response = new Twilio\Twiml();
       $response->sms("Reply with one of the following keywords: monkey, dog, pigeon, owl.");
       echo $response;
    } 

    function monkey(){ 
       $response = new 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 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;
    } 


    $body = $_REQUEST['Body'];

    $result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); 
    $result = trim($result); 
    $result = strtolower($result);

    if(stripos($body, "monkey") !== FALSE) {
        monkey();
    } else if(stripos($body, "dog") !== FALSE) {
        dog();
    } else if(stripos($body, "hello") !== FALSE) {
        index();
    }
    ?>

When I sms 'monkey' to the twilio number, I get a Warning 12200 Schema validation warning. This is what was in the inspector about the error:

<?xml version="1.0" encoding="UTF-8"?>
<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.</Sms>    </Response>

Which tells me that it received the text to know I sent that keyword. But re: the TwiML, this is the same format for my TwiML Bin -- it's assigned to that messaging service.

1

1 Answers

0
votes

Twilio developer evangelist here.

Your problem is that you're using the <Sms> TwiML verb. <Sms> is used for sending messages during a voice call.

Instead, you want to use <Message>. It should be a quick change for you, you just need to replace sms with message in your code. Here's what your monkey function should look like instead:

function monkey(){ 
   $response = new Twilio\Twiml();
   $response->message("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;
} 

Let me know if that helps at all.