Twilio Node.js - Creating Conference Participant with statusCallback - twilio

I'm trying to add a participant to an existing conference. It works just fine, but now I want to add a statusCallback to be called when the ringing begins for the new participant.
Here's the line where I'm creating the new participant:
client.conferences(conferenceName).participants.create({
from: `client:${fromAgentId}`,
to: `client:${toAgentId}`,
statusCallback: statusCallbackUrl,
statusCallbackEvent: "initiated ringing answered completed",
statusCallbackMethod: "POST",
});
As I said, the new participant is successfully getting added to the conference, but the statusCallbackUrl never gets called.
According to these docs https://www.twilio.com/docs/voice/api/conference-participant?code-language=Node.js#parameters-1 it looks like the participants.create() method should accept a statusCallback, so I have no idea why it's not working. If anyone has an idea, I'd love to hear from you.

Answering my own question here.
It seems like it's a problem with the Twilio docs. Regarding the statusCallbackEvent parameter, the docs state:
Can be: initiated, ringing, answered, and completed. Separate multiple values with a space.
However, rather than separating multiple values with a space, the statusCallbackEvent parameter should be an array of values.

Related

Twilio statusCallback: answer call or not

I use Twilio to make phone calls during which the user can reply by pressing key. My problem is that I want to manage 4 cases:
1) the user answer and press 1
2) the user answer and press another key than 1
3) the user answer and press no key
4) the user don't answer
For cases 1, 2 and 3, everything is OK:
I have a "Gather" in my XML, with an "action" URL, a time-out and a actionOnEmptyResult="true"
For managing case 4, I use a statusCallback url, with 'statusCallbackEvent' => ['answered','completed']
What I notice in my Log is that I receive exactly the same data in case 3 (user answer but press nothing) and in case 4 (user don't answer the call).
Maybe this came from the fact after a few "rings" the call fall in voice-box, fooling Twilio which believe it's an "answer" event.
In my LOG I see (case 3 or 4) this 3 events:
Call to my statusCallback with CallStatus = in-progress
Call to my return hook with msg = Gather End and Digits = ""
Call to my statusCallback with CallStatus = completed
So my question is: how can I know the difference between "answer the call and press nothing" and "don't answer the call" ?
Edit: if I refuse the call, result is the same. So I get the same "hook" and statusCallback call, with same data if the user pick-up and give no reply, if he doesn't pick up or if he refuses the call...
Twilio developer evangelist here.
You may want to handle the "doesn't answer the call" slightly differently. If the user doesn't answer, your action URL is still called but the parameter CallStatus sent to the webhook will be no-answer. In this case you can <Hangup/> the call and mark it as not answered.
There is one other issue. If the call is answered by a voicemail then your call will attempt to continue as normal. You can put this down as a call that was answered but didn't enter anything, or you can try using Twilio's answer machine detection to detect whether a human or machine answered the call. If it's a human you continue as usual, but if a machine answers you can also mark it as not answered and <Hangup/> the call.
Let me know if this helps at all.

Need help understanding how sending a redirect instruction in Twilio taskrouter works using Twilio Functions

I am trying to use the redirect instruction to take the customer and worker into a conference call in that is of fixed length (using timeLimit) but is variable in the sense that the timeLimit is determined by calling another function.
I am having issues understanding the documentation regarding this instruction. I know I must pass a call_sid and a url, but is the call sid the sid of the customers call to my number or the conference call I will redirect to and if it is the customer's call_sid how do I get it.
Also with the twiml url is this what I use to redirect the customer or worker to the call?
And where in this step would I create the conference call?
As you can see I'm lost regarding the API and would appreciate any guidance on where to look.
EDIT CODE:
exports.handler = function(context, event, callback) {
callback(null, {"instruction": "redirect",
"call_sid": "I DONT KNOW WHAT GOES HERE",
"url": "I DONT KNOW WHAT GOES HERE",
});
};
This is my assignment callback url but I don't know what the last two arguments are exactly asking for. This is the doc I'm using for reference at the bottom of the page https://www.twilio.com/docs/taskrouter/handle-assignment-callbacks

Joining a Webex conference using Twilio api

I want to join Webex conference using Twilio api. I am using Call class like this:
Call call = Call.creator(toNum, fromNum, twiMLUrl).setSendDigits(dialCode).setStatusCallback(STATUS_CALLBACK_URL).setStatusCallbackEvent(callbackEvents).create();
Here fromNum is my Twilio number, toNum is the phone number provided by Webex and dialCode is the participant code
I am unable to join the conference. I feel it is because webex asks to enter "1" to confirm the participant code in the end while joining.
Is there a way in api to send that "1" to confirm?
Twilio developer evangelist here.
It's a little bit blunt, but you can send pauses as part of the sendDigits parameter. Every "w" you send as part of the string will pause for half a second.
It might take a bit of testing, but you should be able to make your dialCode out of the initial code, say "1234", a few pauses and then the final "1". Like 1234wwwwww1.
Let me know if that helps at all.

Twilio Call Status

How do I know whether or not a call is answered?
For StatusCallback, I can set the following values:
initiated
ringing
answered
completed
When Twilio sends me statuses, I don't see a value for "answered" what I see are the following:
no-answer
busy
completed
initiated
failed
I'm wondering why there is no status returned for:
answered
though I'm setting "answered" as one of the values for StatusCallback.
What confuses me is that Twilio sends "Completed" irrespective of whether or not the call was answered or not.
I need a definite status for the call being answered. If the call is not answered then I need to retry again later or build a business logic around it.
When the call is not answered, then I get "not-answered".
When the call is answered, then I get "completed", but "completed" does not necessarily mean the call was actually answered assuming that the call went to the voicemail box or something.
On a side note, I am also setting the "IfMachine" parameter in the call request. Though I know that it is an experimental feature, I get the call status as "completed" as in this case, my expectation is "not-answered".
How do I know if the call was actually answered?
Megan, also from Twilio!
Just wanted to clear a few things up here. You mention using StatusCallback which expects a URL. The answered value is actually set using StatusCallbackEvent as you can see here in the docs.
I don't know what language you're using but an example in Python (you can find other languages on that docs page):
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "YOUR_ACCOUNT_SID"
auth_token = "YOUR_AUTH_TOKEN"
client = TwilioRestClient(account_sid, auth_token)
call = client.calls.create(
url="http://demo.twilio.com/docs/voice.xml",
to="+14155551212",
from_="+18668675309",
method="GET",
status_callback="https://www.myapp.com/events",
status_callback_method="POST",
status_events=["initiated", "ringing", "answered", "completed"],
)
print call.sid
And a final note about using IfMachine. For the time being, we actually recommend that you use Twilio's <Gather> verb to detect if a human picks up as explained in this question here.
Hope this helps!

Twilio - Get the most recent Conference call

I'm trying to find the fastest way to get a Conference Sid from an ended call's request. Since the Participant is removed from the Conference when the call ends, searching isn't possible (and not implemented in the PHP library anyways). I'm assuming the call left the most recent Conference, since its 'action' parameter is associated with its Dial into the Conference.
How do I get the most recent Conference using the PHP helper library?
Twilio evangelist here.
I don't think there is a way to just get the last conference directly from the API. What you can do is use the helper library to get a list of the conferences.
$client = new Services_Twilio('AC123', '123');
foreach ($client->account->conferences as $conference) {
print $conference->date_created;
}
When you do, each conference should include a DateCreated and a DateUpdated property that you can sort by to find the last one created or updated.
Hope that helps.

Resources