How can I use Twilio for end-to-end SMS exchanges?

For some reason, it’s very difficult for me to understand how the Twilio model works; as a result, I try to encode the solution by guessing (something that I hate doing). Hope someone can help with the confusion.

I have already set up forwarding, so when someone sends text to my Twilio number, I get it on my phone. The problem is that when I reply to this text, it goes to Twilio instead of returning to the original sender.

I tried passing my number as the "from" string in the tag, but this is rejected by Twilio as an invalid Twilio number.

<?php header('Content-Type: text/html'); ?>
<Response>

  <!-- ****** This gets rejected: ****** -->
  <!-- Message to="<?=$_REQUEST['PhoneNumber']?>" from="<?=$_REQUEST['From']?>" -->

  <Message to="<?=$_REQUEST['PhoneNumber']?>">
    <?=htmlspecialchars(substr($_REQUEST['From'] . $_REQUEST['Body'], 0, 1600))?>
  </Message>
</Response>
+4
source share
1 answer

Twilio, , .

, Twilio, .

, : , /, , -.

<?php
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>

<?php 

$myPhoneNumber = "+15557779999"; 

if ($_REQUEST['From'] == $myPhoneNumber) {
    $message = explode("/", htmlspecialchars(substr($_REQUEST['Body'], 0, 1600)));
    $theOtherPhoneNumber = $message[0];
    $theOtherMessage = $message[1];
    echo(
        "<Response>
          <Message to=\"{$theOtherPhoneNumber}\">
            {$theOtherMessage}
          </Message>
        </Response>"
    );  

} else {
    $message = htmlspecialchars(substr($_REQUEST['From'] ."/ " .$_REQUEST['Body'], 0, 1600));
    echo(
        "<Response>
          <Message to=\"{$myPhoneNumber}\">
            {$message}
          </Message>
        </Response>"
    );

}

?>

, . , Twilio, , , . :

+15553331111/ Hey, how is going?

Twilio , - . https://www.twilio.com/docs/tutorials

+2

All Articles