I am trying to build a statuscallback into my web app. I have set up a Twilio function:
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
if(event.To) {
const attr = isAValidPhoneNumber(event.To) ? 'number' : 'client';
const dial = twiml.dial({
callerId: event.From,
});
dial[attr]({
statusCallbackEvent: 'completed',
statusCallback: 'https://pink-dragonfly-9052.twil.io/calls/events',
statusCallbackMethod: 'POST'
}, event.To);
} else {
twiml.say('Thanks for calling!');
}
callback(null, twiml);
};
function isAValidPhoneNumber(number) {
return /^[\d\+\-\(\) ]+$/.test(number);
}
And I am trying to receive the statuscallback in the backend of my application with:
const Router = require('express').Router;
const router = new Router();
router.get('https://pink-dragonfly-9052.twil.io/calls/events', (req, res) => {
console.log("requested");
});
But the back-end router does not receive the response. I have set up the 'https://pink-dragonfly-9052.twil.io/calls/events'
url in my TwiML as the status callback URL as well.
How do I receive the statuscallback then?
Thanks a lot.