2 years ago
#5266
Omar Dajani
Twilio accept incoming call
I'm trying to allow users to accept incoming calls but I can't get it to work. This is what I have tried. If it is an incoming call, it will pause for 20 seconds. The user can then choose to accept the call on the client side which will invoke /answerCall
I would appreciate any tips/suggestions on whether I am on the right track or not. Thank you!
server.post('/voice', (request, response) => {
if (request.body.Direction == "inbound") {
const responser = new VoiceResponse();
responser.say('I will pause 10 seconds starting now!');
responser.pause({
length: 20
});
io.sockets.emit("incoming call", request.body)
responser.say('I just paused 10 seconds');
response.setHeader('content-type', 'text/xml');
response.send(responser.toString());
}
});
server.post('/answerCall', (request, response) => {
console.log("answered call: " + request.body.id);
console.log("caller is: " + request.body.caller);
client.calls(request.body.id).update({
url: 'https://5131-108-24-86-148.ngrok.io/routeCall',
method: 'POST'
})
})
server.post('/routeCall', (request, response) => {
const responser = new VoiceResponse();
const dial = responser.dial({ callerId: '+16672268690' });
dial.number({
statusCallbackEvent: 'initiated ringing answered completed',
statusCallback: 'https://5131-108-24-86-148.ngrok.io/statuscallback',
statusCallbackMethod: 'POST'
}, request.body.From);
response.setHeader('content-type', 'text/xml');
response.send(responser.toString())
})
javascript
twilio
twilio-php
twilio-click-to-call
0 Answers
Your Answer