This post assumes that you have read the part 1 of this series, which covered making calls and sending messages programatically from twilio. This part will cover the handling of incoming messages and phone calls.
- Login to your twilio account and goto the 'Numbers' section. Here you can see all the numbers that you have registered with twilio and those you can use with twilio.
- Click on any of the listed numbers
- On the following page, you will see a textbox under Voice and another text box under Messaging section. Enter the URL to your page in this box so that twilio will invoke this page on receiving a call or message to the number you have selected.(Like a Landing URL or Call back reference). You may set the method to invoke your page(GET/POST), in the following drop down box.
- You may write the code to handle your call/message in this landing page. Try
file_put_contents("test.txt",json_encode($_REQUEST));
in your landing script so that you may see the various parameters passed to your page from twilio upon receiving a call or message, and you may use these parameters according to your logic. - You may optionally echo an xml (twiml) formatted string for twilio to respond to the incoming call or message. For example,
$toPhone = $_REQUEST['From']; //sender's number
will acknowledge the sms sender with another message.
$content = "Thank you for your response. Your sms response : ".$_REQUEST['Body'];
//xml response
echo '<?xml version="1.0" encoding="UTF-8"?><Response><Sms from="$twilio_number" to="$toPhone">'.$content.'</Sms></Response>';
No comments:
Post a Comment