Custom attribute in Twilio verb - twilio

I was looking into attributes of Dial verb. In Dial verb, we have an attribute hangupOnStar. So if we created a call using dial verb and set attribute hangupOnStar then in the middle of the call the user can hang up the call by pressing star (*) on his phone. And then next verb will get executed in the twiml response.
So my question is can we create our own custom attribute like toHangupPress (some_key)? I searched the web but didn't find any documentation in this regard.
Can we create custom attribute at any place in Programmable Voice of Twilio?

Twilio developer evangelist here.
You cannot create custom properties for TwiML, so it is not possible to hang up with any other keypress when using <Dial>.
If you are doing other things, then you can use <Gather> to take keypresses and react to them, however it's not possible to nest a <Dial> within a <Gather>.

Related

Twilio Gather followed by call forward (Dial) after user input without using another webhook

I'm using the Twilio C# SDK to initiate an outbound call from Twilio, during which user's DTMF input needs to be gathered (Press 1 to be transferred to sales, 2 for support...), and the subsequent action is to forward the call to a designated E164 number that matches the key.
So the VoiceResponse.Gather() method takes this action parameter that is a webhook Uri to which the user input will be posted and we can surely forward the call from there.
var twiml = new VoiceResponse();
twiml.Say("...");
twiml.Gather(numDigits: 1, action: webhookUri);
But is there a way to achieve this simple forward instruction within the current twiml object without involving an external webhook? Basically something that gathers the user input digit, correlates to a E164 number(using a predefined dictionary), then Dial directly.
Twilio developer evangelist here.
No, there is not a way to achieve the instruction after the <Gather> without another webhook. You must pass a URL as the action parameter and respond to the webhook with the next set of TwiML to direct the call onward.
If you do not want to host the application that responds to this webhook yourself, you could achieve this flow using Twilio Studio, which is a drag and drop editor for communications flows, or using Twilio Functions, which is a serverless environment where you can respond to incoming HTTP requests with JavaScript functions.

Redirect a call mid-call with Twilio

I am using Twilio Client in my application, and I was wondering if there's a way to redirect a call mid-call on key press.
To be more accurate, is there a way to set up a listener for a specific key and Gather on keypress? I saw that Twilio recommends using hang up on star for these kind of things, but this option only listens to the caller's key presses, and I want to have the ability to redirect even if the call is inbound.
So I found a nice solution.
Instead of making a call using a one dial from a client/number to a client/number, what I did is create a conference call even if there are only 2 people speaking. This way both of the sides use the Dial verb and I can use hangUpOnStar on both the caller and the recipient.

Can you use the Dial and Gather verbs together in Twilio?

I'm building an app where I have Twilio make a call, 'gather' the response from the callee and keep calling my backend because of the <Gather>.
However, I also want to be on the call live to hear what's happening in realtime. I was wondering if I can do this by using the Dial verb in conjunction.
This is what my flow looks like:
Twilio calls my server to get TwiML for a call it just made
Server returns a <Gather> response
Twilio calls server again with the data it 'gathered'
Server returns another <Gather> in response
...and so on.
This is what I'm trying to do:
(NEW:) I use webhooks to dial into a conference call 'C1'
Twilio calls server to get TwiML for a call it just made
Server returns a <Dial> followed by the gather response as earlier. I wanted the <Dial> to put the active call in the same conference C1 that I've already joined from another phone so I can listen to what's happening on the call.
Twilio calls server again with the data it 'gathered'
Server returns another <Gather> in response
...and so on.
So, what I'm trying to do here is to be on the conference before any of this happens so I can listen to Twilio interact with callee.
But looks if I try to append <Gather> to a <Dial> in a TwiML response, Twilio doesn't start 'gathering' from the conference call, but instead, waits for the conference call to finish first and only then execute the 'gather'.
PS: The closest approximation to what I want to do is set the record flag on beforehand when Twilio makes the call to the callee, and then listen to the entire conversation later to figure what happened but that's incredibly inefficient.
How can I help myself?
This is what my code looks like:
Gather g = new Gather.Builder().input("speech")
.action(BASE_URL + "/processSpeech?")
.timeout(4)
.build();
Conference.Builder conferenceBuilder = new Conference
.Builder("confie")
.startConferenceOnEnter(true)
.endConferenceOnExit(true)
.waitUrl("");
tmlb.dial(new Dial.Builder().conference(conferenceBuilder.build()).build());
VoiceResponse.Builder tmlb = new VoiceResponse.Builder();
TwiML tml = tmlb.gather(g).build();
Twilio developer evangelist here.
You can't use <Gather> within the context of a <Conference> so this flow is not possible. I'd suggest that you record the call and listen back to find out what happened. Though you say that is less efficient.
I'd like to help further, but I'm not sure what the exact use case here is. Perhaps you could share a bit more of what you are trying to achieve and I can update this answer?

How to SAY after DAIL

I have an incoming call that triggers an outgoing call. When the outgoing call is answered, I want to SAY an announcement, ideally without the original caller hearing it.
I tried to respond with a TwiML to the callStatusCallback and I also tried nesting the SAY node within NUMBER. Both didn't work. Any ideas?
Twilio developer evangelist here.
What you're referring to here is commonly known as a call whisper.
You can implement it by providing a URL to the <Number> verb in the TwiML you return that forwards the call. That URL should return some more TwiML, in this case <Say> with the text you want to read out. Then when the call is forwarded, Twilio will make a webhook to that URL when the user answers and only connect the calls when the TwiML is complete.
Let me know if that helps at all.

Need Twilio Call Summary

I have a scenario to make a call through twilio. When I call the twilio, it gives me multiple options to connect just like a conventional IVR. Then I select a specific contact to through my call, Twilio makes me connected to the selected contact successfully. When I fetch the call duration, it returns me the whole time span, from IVR start to call ending.
Is there any option to fetch the call duration of the call with selected person.
Please reply soon.
Twilio evangelist here.
Sure. It sounds like your probably using the <Dial> verb to dial a number number from your IVR. In that case you can use the action parameter of that verb.
The URL set in the action parameter will be requested when the person you <Dial>ed ends the call. In that request, Twilio includes a few extra parameters, including one called DialCallDuration:
http://www.twilio.com/docs/api/twiml/dial#attributes-action-parameters
Hope that helps.

Resources