If you are using Node Express, here is a snippet that worked for me:
app.post('/respondToMessage', function(req, res) { var twiml = new twilio.TwimlResponse(); console.log('sms message =', req.body.Body); twiml.message('respondToMessage'); res.type('text/xml'); res.send(twiml.toString()); });
You are analyzing the Body JSON attribute from a response, which usually looks like this:
{ "ToCountry": "", "ToState": "", "SmsMessageSid": "", "NumMedia": "", "ToCity": "", "FromZip": "", "SmsSid": "", "FromState": "", "SmsStatus": "", "FromCity": "", "Body": "The attribute you're parsing for", "FromCountry": "", "To": "", "MessagingServiceSid": "", "ToZip": "", "NumSegments": "", "MessageSid": "", "AccountSid": "", "From": "+", "ApiVersion": "" }
source share