My intention is to limit outgoing calls to regional only. For eg, if the caller is from Canada, that person can only call in Canada numbers. I am basically, trying to separate US and Canada numbers. I have already blocked other countries incoming/outgoing calls.
To do this: When the dial verb is done, I have a statusCallBack at initiated state. From the Call details, I get the ToCountry and depening on that, I update the callStatus to Cancelled/Completed following twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress/node#
The call is made :
const dial = twiml.dial({
hangupOnStar: true,
action: '/callResult',
timeLimit: 300,
});
dial.number({
statusCallbackEvent: 'initiated',
statusCallback: '/checkToCountry'
},numToCall);
CallBack func :
app.all('/checkToCountry', (req, res) => {
const twiml = new VoiceResponse();
console.log(req.body);
console.log(req.body.ParentCallSid);
console.log(req.body.CallSid);
if(req.body.ToCountry != 'US')
{
console.log("Not Calling allowed country : " + req.body.ToCountry);
client.calls(req.body.CallSid).update({status: 'canceled'}).then(call => console.log(call.to));
}
res.send(twiml.toString());
});
However, this doesn't seem to work. I am assuming this is because we can only do this when call is in-progress?
Is there a better way to do this ?