1

here is my problem. I send sms to my twilio app and according to the text in them, i want a sms in reply on a different number. Well i'm starting from an example, my app receives sms, replies to the same number asking to type some words but when it gets the reply, no sms arrives to the other number (both numbers are registered in twilio in the code below i have edited the last numbers)

Here's the code

<?php
include 'Services/Twilio.php';
include 'config.php';
    // make an associative array of callers we know, indexed by phone number
    $people = array(
        "+3932034091XX"=>"3934781415XX",
        "+3934781415XX"=>"+3932034091XX",
        "+14158675311"=>"Virgil",
        "+14158675312"=>"Marcel"
    );


$name=$people[$_REQUEST['From']];

function index($name){
    $response = new Services_Twilio_Twiml();

    $response->sms("Reply $name with one of the following keywords:
batteria, dog, pigeon, owl.");
    echo $response;
}

function batteria($name){
$dest=$name;

$client = new Services_Twilio($TWILIO_ACCOUNT_SID, $TWILIO_AUTH_TOKEN);
$sms = $client->account->messages->create(

        // Step 6: Change the 'From' number below to be a valid Twilio number
        // that you've purchased, or the (deprecated) Sandbox number
            $TWILIO_NUMBER,


            // the number we are sending to - Any phone number
            $dest,

            // the sms body
            "Hey  Cambia la batteria!"
        );



}

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

function pigeon(){
    $response = new Services_Twilio_Twiml();
    $response->sms("Pigeon. A stout seed- or fruit-eating bird with
a small head, short legs, and a cooing voice, typically having gray and
white plumage.");
    echo $response;
}

function owl(){
    $response = new Services_Twilio_Twiml();
    $response->sms("Owl. A nocturnal bird of prey with large
forward-facing eyes surrounded by facial disks, a hooked beak,
and typically a loud call.");
    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 'batteria':
        batteria($name);
        break;
    case 'dog':
        dog();
        break;
    case 'pigeon':
        pigeon();
        break;
    case 'owl':
        owl();
        break;

/* Optional: Add new routing logic above this line. */
    default:
        index($name);
}
?> 

thanks to everyone

Leon81
  • 11
  • 1

0 Answers0