Search code examples
node.jsmeteortwilio

Twilio Voice and Meteor.js - Can’t Get req.body In WebApp.handlers.use()?


I’m working on getting Twilio Voice working with my Meteor app. Code on the client pings the Twilio server, which then sends a POST request to my server endpoint, including the ‘to’ phone number or customer id in the body.

Note: WebApp is automatically included by Meteor. It makes it easy to add REST endpoints. It's Express under the hood, so any code you use with Express can be used here.

My endpoint is hit, but req.body is “undefined”:

WebApp.handlers.use('/voice', async (req, res, next) => {
    //this code executes:
    console.log('req?.body: ', req?.body) //logs "req?.body:  undefined"
    [.....]
});

How can I capture the POST request parameters?


Solution

  • Fixed.

    import bodyParser from "body-parser";
    
    WebApp.handlers.use(bodyParser.urlencoded({ extended: true }));
    WebApp.handlers.use(bodyParser.json());
    
    WebApp.handlers.use('/voice', async (req, res, next) => {
        //req.body is now accessible
    
        [.....]
    });