Search code examples
twiliotwilio-api

Custom flow for twilio call forwarding


I'm reviewing Twilio voice API documentation but unable to find a solution as per following call flow. Plz recommend that I have to use a combination of APIs to achieve the flow.

following is the use case.

  1. An inbound call comes in. I have the incoming web url set and on that URL I'm serving twiml to dial outbound call using call.create API. The issue is that I want to play a twiml.play or twiml.say to receiving party to whom call is being forwarded so that they may know who the caller is.

  2. If the receiving person (to whom call is being forwarded) makes the phone busy or don't pick the up phone or has a voice mail then system should play back recording to main call who dialled inbound call to my twilio number that all agents are busy plz call again and if the agent picks the forwarded call then both should connect and convers with each other.

Plz suggest how this combination can be achieved as I'm unable to find any answer despite reading various questions and answers here.

Regards,

Aamer


Solution

  • After exploring the twilio documentation I have found that this flow can be developed in the following manner.

    1. In case of incoming call the webhook is invoked which is assigned to that specific twilio number against the incoming action url.

    2. In that specific url there can be two options which can be used. Either to take the incoming caller in a conference call and place them there with the wait music and then use the conference call Api to add participant in that conference. However, in my case I need to play a certain greeting to caller2 so therefore, instead of taking the caller1 to conference, I have created another call using twilio client.call api and used its twiml attribute. Code is given below:-

      client.calls.create({ twiml: <Response><Play>https://abcxyz.com/static/media/agentgreet.mp3</Play></Response>, to: agentId, from: calledNumber )}

    So in this way when someone pickups the call then a custom greeting is played. Another way to implement above is to use twiml.dial() function and then dial.number() function subsequently which can also do the same but its more tricky to handle.