Skip to content Skip to sidebar Skip to footer

Twilio Api - Storing Replies From Incoming Text Messages

I am using Twilio API to receive SMS text messages. I want to store the number and the body of the received message. It is being received in an xml php page, I want to use it in a

Solution 1:

PHP won't store the information about the text message anywhere, so you are going to lose it. What you describe means that your PHP file will be loaded two times. The first time, the Twilio server will load your PHP file and read the Evil <Response>.

The second time, you will load the PHP file in your web browser. The $_POST variable depends on information in your browser (and in the Twilio request), so it won't be the same for both cases. That means you need to save the data somewhere, so it doesn't get lost. You can use a database, or write it to a text file, when Twilio makes the request and then load the data from the file or the database later. This also helps in case you receive more than one incoming text message - you can store all of them in the file or in the database.

Solution 2:

You're not storing it anywhere in this code. You're just outputting it. You'll need to save it to a database of some sort instead of echoing it back to Twilio (which is going to ignore anything outside of a <Response> block.

JavaScript won't work in this for two reasons - it's an XML file, and Twilio doesn't execute JS code.

Post a Comment for "Twilio Api - Storing Replies From Incoming Text Messages"