Simply responding to a text message may only involve returning some TwiML, but sometimes you might want to programmatically make decisions based on things like the body of the message or the country the message was sent from. As in the example above, this requires you to access information contained in the HTTP request sent from Twilio.
Let's walk through how to access this information in more detail with Node.js and the Express framework.
Development Environment Setup
Let's start by making sure we have the right software installed and set up that we'll need to use for the rest of this post. Throughout this post, you will need:
- Node.js and npm installed (do this first if you haven't already)
- A free Twilio account and a Twilio phone number
- The npm modules for Express, the body-parser middleware, and the Twilio Node library
Here is a good guide to follow in general if you are going to be doing more with Twilio and Node.js and have any more questions.
To install these npm modules, navigate to the directory where you want this code to live and run the following command in your terminal to create an npm package for this project.