Receiving messages using Twilio and Meteor

126 Views Asked by At

I'm creating a web application that needs to be able to receive text messages using Twilio. I run ngrok to start a tunnel to my localHost: 3000. If I send a message to my Twilio number after I start my app on the localHost it works fine. The issue is that once I deploy the app to Galaxy, the app does not respond to incoming texts anymore. I have tried changing the app.listen('3000'); to many different ports i.e.(80,8080,443) and none of these work. What do I need to change or add to get this to work after it's deployed?

var express = require('express');
var bodyParser = require('body-parser');

var app = express();

app.use(bodyParser.urlencoded({extended: false}));

app.post('/message', function (req, res){
    console.log(req.body);
    var msgFrom = req.body.From;
    var msgBody = req.body.Body;

    res.send(`
    <Response>
        <Message>
        Hello ${msgFrom}. You said: ${msgBody}
        </Message>
      </Response>`);
});

app.listen('3000');
1

There are 1 best solutions below

0
philnash On

Twilio developer evangelist here.

You seem to have built an entirely separate app outside of Meteor for handling your webhooks. You don't need to do this, you can handle your webhooks from within Meteor.

I recommend you take a read through this blog post that implements webhooks for Stripe within Meteor. You can then apply that to Twilio webhooks.