1

I am trying to set up a twilio messaging response using Twiml. I am using the documentation from this page: Twilio Documentation.

I believe I have done everything correctly and have set up the MessagingResponse exactly as displayed in the doc. When I send a message saying 'hello' from my phone to the http POST route, the req.body.Body reads as 'undefined' and I get an SMS response coming from my 'else' statement saying 'No Body param match...' when I am in fact expecting a response saying "Hi!". Is there something that I'm missing?

If it helps at all, here is my repo: https://github.com/branaust/FitFH

Twilio Documentation

My Implementation

Top of controller

App.js file

Route

UPDATE: Alright after a couple hours I have found the solution. For whatever reason, I needed to add the body parser directly into my route file.new user route file

Brandon Austin
  • 162
  • 1
  • 1
  • 10

1 Answers1

0

For those who are facing this issue, I realised I wasn't using body parser at all, which meant that I wasn't getting the body in my router at all ‍♂️

I fixed it by using body parser in the main index file (where you initialise the express module. Also, you don't need to use a separate module, you can just use express to parse the body:

// index.js

const app = express();
app.use(express.json());
app.use(
  express.urlencoded({
    extended: true,
  })
);

Reference: https://stackoverflow.com/a/24344756/749512

nkhil
  • 1,452
  • 1
  • 18
  • 37