Twilio - Can this be done in XOJO?

Twilio can easily send SMS messages but I am wondering if I can write a XOJO Web App or maybe a Console App to respond to Twilio receiving an SMS message and responding.

Here is a snippet of PHP code that will respond back to the sender of an SMS. I have created a working a server based on this code to open and used a MySQL db that is also used by a XOJO app on the same server. I have more complex logic to add and I really don’t want to do it in PHP. I would much prefer XOJO.

<?php header("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\ "; ?> <Response> <Message>Hello, Mobile Monkey</Message> </Response>

Here is the Twilio page that explains the process. Essentially you configure your Twilio number to point to a Website. When an SMS is received by Twilio it does a PUT (I think) to the Web site address. From there you can process some of the parameters and respond, if desired, with something that is XML formatted that goes back to the sender.

https://www.twilio.com/docs/quickstart/php/sms/hello-monkey

In PHP these parameters tell you two things about the message from the person sending the SMS.

$body = $_REQUEST['Body']; $from = $_REQUEST['From'];
The BODY is what the user entered into the message.
The FROM is their phone number.

From these you can interact with the DB and respond back to the person that sent the SMS.

BUT … maybe I just need to learn more PHP.

Not really what you’re looking for but maybe you can take some hints here and here .

It can be done. I created a service like this a long time ago.
A user sent a booking SMS to a number that was forwarded to my WE app that did some DB operations and sent a return message to the sender.

I think I used App.HandleSpecialURL and parsed the parameters and acted accordingly :slight_smile:

I’m not familiar with Twilio’s API though.

http://www.realsoftwareblog.com/2013/05/using-twilio-to-answer-phone-calls.html

Oops sorry Matteo I didn’t check your link before I posted :slight_smile: (Same link above)

The Twilio Answer Call app looks pretty simple. The key is the HandleSpecialURL. This is easier than I thought AND NO PHP.

Thanks.

EDIT - After a bit of reading I think this may be what I need but I will have to parse the parameters:

StringValue = aWebRequest.Entity


OK — I have the basics of this working

BUT

Can XOJO handle POST requests rather than GET?

If I understand correctly a GET will put all of the parameters in the URL which is less secure.

Thanks.

Xojo put GET parameters in the QueryString and POST parameters in Entity

So you can use both based on your needs