Twilio Rest API / Node Js call status no working - node.js

I'm creating a tool that can automatically call someone when I click a button.
So far, I've tested three solutions: The first one was using the rest API call, the second one was using node js SDK that is available in the Twilio console using the function & assets feature, and the last one was using Twilio Studio feature.
All of them are not giving me the satisfaction of creating something that can be used in production.
The main problem is the call status given to the StatusCallback url parameter.
For example:
if you set a timeout value by default or something higher than the duration of the ringing time, it will send you a completed status. The timeout value needs to be smaller than the maximum number of ringtone that your carrier set by default if you want to receive a no-answered status.
If your phone is on "airplane mode" and you make a call to it using Twilio, the statusCallback will be sent to the URL as "completed".
If you make the same phone call and imagine that the user rejects the call by clicking on the red phone instead of the green phone, the statusCallback will send you a completed status.
So it's been a week since I've coded a NodeJS solution using Twilio Functions, making POST requests using Postman, and also creating a flow to test it using Twilio Studio. Every time that I've tried those three solutions, with the three same scenarios described above, I've never been able to obtain a real valuable/informative status that can help me to resend the call until someone answers or, based on the status, send an SMS to the person to inform him that we have tried to call him and that he either was not available or rejected the call.
Has one of you already tested that and maybe succeeded in having anything else than a "completed" status? That is no use in case you need to handle those cases.
Thank you for your help.

Related

Does Twilio provide any APIs or services that can detect if call has been placed on hold by the receiver?

I'm placing a call from my React Native application using Twilio and the outbound call works fine. Now I want to create something that will detect when I am put on hold by the receiver. The idea here is to make my app hold for me and get back to the caller once the hold has ended.
I searched the twilio docs and services but could not find any thing regarding this use case. How would I go about doing this?
Twilio developer evangelist here.
Unfortunately, there is no mechanism to make this happen, even if there were something in the SIP signaling from the carrier, such as a re-INVITE.
In the world of SIP, putting a call on hold often involves sending a re-INVITE with different media parameters, such as saying a=sendonly in the session description. Even if this were passed end-to-end through the PSTN to Twilio, we do not generate webhooks to inform the customer’s app of this fact.
There are some good SO questions about placing a Twilio call on hold and retrieving it later--the Enqueue verb might be helpful.

How do I Redirect live Call from Twilio Flex to Twilio Studio IVR?

I am having problem in transferring the live call. What I have to achieve is, Agent can transfer live call to IVR where IVR ask for rating "Please rate this call from 1-5" and then saves the rating via rest API.
Here is the first IVR where call is sent to flex
Here is the second IVR where flex agent should send the call
I know about Assignment Callback to redirect call to new Twiml document like
{
"instruction": "redirect",
"call_sid": "CA123456789",
"url": "http://example.com/assignment_redirect",
}
How can I use this to redirect Call to Twilio studio again, In studio all are widgets.
This is only semi-possible right now.
Studio Flow executions are a bit different from normal webhooks that return TwiML, since they MUST be the first webhook hit by the call. (For voice calls, it is also a best practice to make sure the same Studio Webhook is configured as the secondary handler and call status handler for the phone number in question, which suggests that Studio is a bit more robust in how it operates than a typical TwiML App.)
The workaround is to use the <Dial> verb to create a new call to the Studio Flow that you wish to redirect to. This assumes that each Flow that handles incoming voice has its own phone number(s).
That said, I have been told that a feature request is underway for sometime in 2021 that would allow for different flows to be linked together, so this may change in the future.
I am not exactly sure how you specify a webhook for once the Flex agent is finished with the call -- it looks like you have already done some research into the TaskRouter functionality that enables this. But assuming you can specify a webhook URL (assignment_redirect in your example), all you should need to do is create a TwiML Bin containing your <Dial> verb to the satisfaction survey Studio flow you want to receive the call, and use that TwiML bin as the webhook URL.

How to use Dialogflow Phone gateway and handling it in backend platform like nodejs

I'm trying to understand phone gateway implementation in dialogflow but dont see much of documentation for how to handle in backend code using nodejs or any third party apps like twilio,viber etc.
My doubt is whether is it available for now or not and is their any documents regarding phone gateway which can be done through google mini device for voice calling?
Please correct me if I'm wrong about what I understand.
Dialogflow phone gateway is a great feature provided by Dialogflow. It is simple to activate. Just follow the instructions in the Integrations tab.
All your intents and webhook will just work fine as they do in the bot. But the response type is little different from other platforms. So check that once before building responses.
It only supports speech response that is returned to the user in the phone call.
as per Google documentation, it uses the V2Beta1 version of the API. It means you have all the normal fields of the V2 API inside the body and parameters of the webhook call (+1 "MlEnabled" field, but not important for the telefony gateway). See more here https://dialogflow.com/docs/reference/v2-beta-v2-migration-guide-api . I have also been searching for extra fields like the phone number who is calling (to use it in backend tasks like CRM lookup), but this is not there yet (I analysed the JSON response, there is nothing so far).
Some tip to integrate with Twilio (my use case too) : you can perfectly route the twilio call to a simple Twilio callflow (like checking for opening hours) then to the incoming DialogFlow number (as you would do with the black number of an IVR provider) and transfer the Dialogflow call to another incoming phone numbers (controlled by Twilio) where you do the rest of the callflow (typically the skill based routing).
Example : after the call, Twilio checks for opening hours > OK > forward to Dialogflow phone nbr for intent recognition > identify intent nbr1 > route to phone nbr1 of Twilio which is connected to a routing/queue to agent group nbr1 (idem for intents nbr2, 3, 4 ...).
In this example, some useful fields are missing in the JSON like the phone nbr of the caller(CLI), the phone number dialed, eventually some UUI ISDN field, ... that you would like to use for a CRM lookup and CTI popup. Let's keep an eye on it and maybe Google will add it in V2beta2 ...?

Return response to Google Assistant via API

I have a Actions on Google project that uses api.ai for its actions. This is working well and I can see request/responses appear on the google assistant interface (On mobiles and simulator)
One of my usecases for api.ai needs to broken into 2 parts, in that we have to inform the user that the processing has started and then inform them again once its completed (without them reprompting for the output).
Im trying for a way to inform the user who is using the Google assistant when the processing is completed, but have failed so far. Something like this
User: I would like to see if my loan request is approved
Google Assistant: Hold on, let me check and let u know .
.... (Makes a webservice call to the backend asynchronously)
.... After few seconds ...
.... Postback to google assistant from the webservice
Google Assistant: Thanks for holding, your request is approved.
Im not sure how to do the "postback to google assistant" call. I have tried to get the SessionId from the Api.AI call and then use that to make a event request , but that doesnt seem to send the response to the assistant. Google Assistant seems to be using the formats defined in https://developers.google.com/actions/reference/rest/Shared.Types/AppRequest, but Im unsure how to get the ConversationToken and use that for sending the response back to the user.
Short answer: you can't do that.
Slightly longer answer: At least right now, there is no good way to send a notification. Your Action can only respond to a specific statement from the user. You can say something like "ask again in a minute and I should have a result for you", but that isn't a great experience. At Google I/O 2017, they announced that notifications would be coming to the Google Home at some point... but gave neither a time frame nor any information about an API.
Long, but probably still unsatisfying answer: You can look into Transactions which let them initiate purchase or request of some sort and then "check out". Once they have checked out, you would confirm that a transaction is being processed with an OrderUpdates and then can send updates with the status of the "order". These status updates can turn into notifications or user's can query the state of the order at any time. Transactions don't require payment, so this may work depending on your needs.
However, there are a few things to note. This is still in developer preview, so things may change in the future. It also doesn't work on all surfaces where the Assistant runs, so while it does work on Assistant on phones, it does not work on the Google Home right now.

Sending POST requests to Google Action/API.AI or sending responses which take more than 5s

My fulfillment needs to do a lot of processing after receiving a certain request from Google Action/API.AI and the default response timeout is 5s.
https://developers.google.com/actions/components/fulfillment#nodejs
Is there any way I could send a delayed response or send a POST request after the results are ready?
The short answer is no - you must respond within 5 seconds, and there is no way to send a notification back through the Assistant at this time.
The slightly longer answer is that we know notifications are coming - but we don't know if there will be an API for them. There have been rumors about other ways that may be coming that allow us to work around the 5 second limit.
The even longer answer is that, if you are using Action Transactions (ie - allowing the user to purchase or reserve something) you can send updates after the fact. However, Transactions are still in developer preview and don't work on all surfaces (they don't work on Google Home at all, for example).

Resources