0
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say> Connecting call to Pinto </Say>
        <Dial record ="record-from-answer" timeout="10" hangupOnStar ="true">
            <Number>XXXXXXXX</Number>
        </Dial>
  <Say> Pinto is not picking up the call, now connecting call to Management </Say>
        <Dial record ="record-from-answer" timeout="10" hangupOnStar ="true">
            <Number>XXXXXXXX</Number>
          </Dial>
  <Say> No one is picking up right now. Please text us at +12022171828 </Say>
</Response>

Above is the call forwarding flow for one after another.

What I'm looking here is, If 1st user attended the call, then it should not initiate the call to 2nd number and also it should not say text message which is at last line If 1st user disconnected, then redirect call to 2nd number - if 2nd number not picking up the call then it should say text message which is at last line if 1st user disconnected, then redirect call to 2nd number - if 2nd number picked up the call then it should not say text message which is at last line

Also I want to Implement Transcribe & Transcribe call back by using TwiML. So, please help me like how we need to do with that?

1 Answers1

0

To carry out this flow, you cannot perform the entire thing in one TwiML response. Instead, you will need to provide the <Dial> element with URL in the action attribute so that once the first call completes, Twilio makes a webhook to find out what to do next.

So, your first TwiML response should look like:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say> Connecting call to Pinto </Say>
  <Dial record="record-from-answer" timeout="10" hangupOnStar="true" action="/complete">
    <Number>XXXXXXXX</Number>
  </Dial>
</Response>

Above I've added action="/complete" to the <Dial> and this means we need an application to be able to respond to HTTP requests to /complete as well. We also need this to be an application and not a static response as we need to work out whether the call was answered or not and decide on what to do next and what TwiML to respond with.

We can do this because one of the parameters that Twilio sends to the action URL is DialCallStatus. This parameter can be "completed", "busy", "no-answer", "failed" or "canceled" and this tells you what happened in that first call.

So, in your case, you will want to check the DialCallStatus and if it is "completed" then you do not need to return the next <Say> and <Dial>. If, however, the DialCallStatus is one of the other statuses, you do want to return the next <Say> and <Dial>. That <Dial> should include another action URL that makes the same choice at the end of the second <Dial>.

I'm not sure what language you are building with, but a pseudo-code idea of this would look like this:

post '/complete' do
  if params["DialCallStatus"] != "completed"
    return "<Response><Hangup/></Response>"
  else 
    return "<Response><Say>Pinto is not picking up the call, now connecting call to Management</Say><Dial ....></Response>"
  end
end
nobody
  • 19,814
  • 17
  • 56
  • 77
philnash
  • 70,667
  • 10
  • 60
  • 88
  • Hello @philnash, Thanks for giving this clarification. I'm new to this twilio and I would like to know how to get/set action URL. Also having another doubt like can we directly use TwiML Bin for call forwarding, voice mail, transcribe? – Karthick Selvaraj Sep 24 '21 at 12:38
  • The action URL is set in the XML, see the example in my answer. You can use TwiML Bins for static TwiML responses, but to create dynamic responses like when you need to respond differently based on the call status, you will need an application of some sort. If you don’t have one, then you could look into Twilio Functions. – philnash Sep 24 '21 at 12:43
  • I'm not sure what language you are building with - as of now I'm just trying with TwiML. Here after only have to check like which language is suitable – Karthick Selvaraj Sep 24 '21 at 12:50
  • You can build with whatever language you want, you just have to be able to respond to HTTP requests and return XML. – philnash Sep 24 '21 at 12:52
  • One more I would like to know is, I'm majorly using Front application to view the entire status which come from Twilio. Majorly looking for - 1) I want to forward the recorded calls, voice mails, transcribed data to Front Application (https://front.com/) - does Twilio supporting this integration? Because in Front I'm getting Twilio one-on-one chat responses - so preferring for all. If this allows to show the records in front, how can we do that? – Karthick Selvaraj Sep 24 '21 at 13:33
  • Also I want to Implement Transcribe & Transcribe call back by using TwiML. So, please help me like how we need to do with that? Connecting call to Jordan +XXXXXXXX Done with the call and Hang up Is this method is right for Transcribe process? – Karthick Selvaraj Sep 24 '21 at 13:37
  • action="/complete" = Whether we have to define like this or we need derive any twilio function for that? – Karthick Selvaraj Sep 30 '21 at 11:59
  • Twilio doesn't do anything special for sending things to Front. Front has implemented the Twilio API in order to manage the messaging workflow. I don't know about the Front side of things, but you can get webhooks for call recordings and transcriptions and I assume you can use that to then send things into Front. – philnash Oct 01 '21 at 04:56
  • As for for your recording. If you want to record a call between two people you do not need to use the `` element. That is for single person recordings, like leaving a voicemail. You have the `record="record-from-answer"` attribute on the `` which should do the trick. – philnash Oct 01 '21 at 04:57
  • And the `action="/complete"` attribute means that you need to implement an endpoint at the path `/complete` in your application that can receive the HTTP request from Twilio with the results of the ``. I gave a psuedocode example of what that might look like in my answer, but you can [read more about the action URL and its request format here](https://www.twilio.com/docs/voice/twiml/dial#action). – philnash Oct 01 '21 at 04:59
  • is there any possibility to integrate Twilio group chat conversation sin Front (https://front.com/) – Karthick Selvaraj Oct 01 '21 at 09:39
  • I don’t know, that’s likely the sort of thing you should ask Front. – philnash Oct 01 '21 at 09:56