Pass extension from Twilio to Asterisk - twilio

I am using twilio to manage our IVR, to handle SMS, and for a few other things. After a user calls and goes through the IVR (for example they press 2 for sales or they say they want extension 205) I need it to hand off to Asterisk.
Setting up the trunk isn't my issue. I need to somehow tag it so asterisk knows how to handle the call. If they chose ext 205 on twilio, I need asterisk to automatically ring ext 205.
I am using a minimal version of asterisk basically for sip registration and voicemail and the rest is done by twilio.
Does anyone know if there is a way to do this in code? Or is my best bet to create a different trunk for each extension. That seems like it would get messy.

Correct solution is make IVR on asterisk. This solution also will be MUCH less costly.
But if you really want... On twilio setup via SIP tag
https://www.twilio.com/docs/voice/twiml/sip
set url to sip:0000+exten#your_asterisk_ip
On asterisk setup trunk to twilio server or allowguest=yes and default context to 'goext'
After that goext context something like this
[goext]
exten => _0000XXX,1,Set(ext=${EXTEN:4})
same => n,Dial(SIP/${ext},,o)
0000 replace with some random code, that required for prevent bots calls when allowguest=yes.

Related

Twilio Flex Voice Mail to Unavailable

We have set-up our Flex, and stuck on one of the last steps. We are a small office, and have a main number that clients call us on. If they ask for a specific employee, more importantly, if the specific employee is required to answer the client issue, and they are marked UNAVAILABLE, it doesn't appear we have access to send the call to voicemail (the transfer button is grayed out).
Is there a work around? A way to direct call the VM? Do we need to tweak our flow? If not, it appears we need to be logged in 24/7 to have access to VM's. A fairly inefficient and expensive option.
OK, I think I know what the issue is. A call comes through to one agent in Flex, but they need to transfer it to the other agent. If the other agent is also available, they can transfer the call no problem. If the other agent is not available, you would like to transfer the call to that agent's voicemail, but there's no way to do that right now.
The issue is that Flex is built around available agents and doesn't have voicemail built in. You've added voicemail as part of the Studio Flow, but this is not integrated to the Flex interface at all.
I would solve this with a Flex plugin that does a couple of things:
Add a button to the agent transfer list for unavailable agents to send to their voicemail.
That button would trigger a request to a Twilio Function, sending it the Call's Sid and the agent you want to transfer to.
The Function could then use the calls API to update the call, redirecting it to the existing voicemail handlers that you have for your agents.
I'm afraid I don't have example code for this plugin, but there is great documentation on building Flex plugins that you can follow to get up to speed.

I need to be able to transfer call from Twilio Elastic SIP Trunk to Twilio Autopilot

When a customer dials my Twilio number, I need Twilio to first try to call my PBX system. Currently using 3CX. If the call is not answered by a person, I need to find a way to send that call back to Twilio and go to another resource. For my purposes, that resource is Twilio AutoPilot.
Basically, if a human doesn't answer the phone, I want the robot to try and help the customer instead.
The only thing I've been able to come up with so far is to create another Twilio number and have that number be the fallback within the PBX. The problem with that solution is with Twilio, you cannot mask the number to match the CallerID of the customer calling in, and I would really like to be able to know that number. Also you are creating 2 call paths, which could make this an expensive option.
The only other solution I could think of, which would use 3 calls paths, would be to use another provider that does allow me to mask the caller id, and then send that to the Twilio number.
I am not a programmer, I have basic coding knowledge, but just barely.
Any help would be appriciated. Thanks
You can use Programmable Voice with a SIP Dial to initially contact your PBX (it will appear the same way an Elastic SIP Trunk call will appear to your PBX). The easiest way is to use the Connect Call to Widget in Studio. If that call fails, say 3CX returns a 404 - Not Found, Studio can continue to the next Widget via the Connected Call Ended path which can then perform additional steps of your choosing. The CallerID is maintained this way as well.
Elastic SIP Trunking is not designed for this particular call flow but rather a simple conduit from/to the PSTN.
Happy Path
Fallback Path

How to send a voice message using Twilio-Client-Javascript or using Twiml - Our understanding & possible approach

We are working on a requirement where we are initiating a call from Twilio client SDK [Javascript]. We have an ASP.Net MVC Core application handling incoming Webhook request from Twilio Twiml app. To initiate a call from a client side, we are using Twiml dial verb and providing from and to number. Further our requirement is to send a voice message as soon as an answering machine is detected.
As we have used Dial verb of Twiml, we can't pass detect answering machine and hence can't send voice message. This is by design of Dial verb as it is an attended calling mechanism. After going through a documentation, I have found that, REST API allows to detect and answering machine and also allows sending a voice message. Twilio REST API shall be used for an unattended call initiation and rule based workflow. Twiml Dial verb uses VoiceResponse class to initiate a call whereas Twilio REST API uses CallResource to initiate a call.
I wanted to confirm my understanding before I start working on possible alternatives.
We are thinking of implementing above use case with below steps
Make a Twilio REST API call to initiate an unattnded phone call with answering machine detection option enabled.
If API responds with answered_by value as human or unknown then we will invoke a webhook that shall patch the call using Twiml Dial verb.
If API responds with answered_by value as machine then it shall use a Twiml which contains a voice message that can be sent to callee.
The above is correct. Is there a specific question, however?
Twilio’s Answering Machine Detection Now Generally Available
https://www.twilio.com/blog/answering-machine-detection-generally-available
We have developed an outbound call mechanism using TwiML app and Dial verb using Javascript SDK & ASP.Net Core MVC with Twilio SDK. We came across an issue where we found that answering machine detection and voice message drop is not supported by Dial verb. We are taking a different approach where we will use Twilio REST API to initiate a call. It has a provision to detect an answering machine and respond to an outcome of answering machine detection such as patching an agent or sending a voice message. Further, There are 2 possible configurations and workflows.
MachineDetection:Enable
Possible values for answered_by are machine_start, human, fax or unknown.
1.1 If value is machine_start then we can't send a voice message as it is not waiting for "beep" after which a voice message can be send.
1.2 If value is human then we can invoke a webhook for patching a user into current call.
1.3 If value is fax then we shall not take any action [Out of scope]
1.4 If value is unknown then we may patch a user to take action. This can be a deciding factor for making user productive. More number of requests ending in Unknown shall degrade the desired outcome.
MachineDetection:DetectMessageEnd
Possible values for answered_by are machine_end_beep, machine_end_silence, machine_end_other, human, fax or unknown.
2.1 If value is machine_end_beep then we can use a TwiML url to send a voice message to a callee.
2.2 If value is machine_end_silence then we can use TwiML url to send a voice message to a callee. Such scenarios needs to be handled with this default action and improved over period of time.
2.3 If value is machine_end_other then we can use TwiML url to send a voice message to a callee. Such scenarios needs to be handled with this default action and improved over period of time.
2.4 If value is human then we can invoke a webhook for patching a user into current call.
2.5 If value is fax then we shall not take any action [Out of scope]
2.6 If value is unknown then we may patch a user to take action. This can be a deciding factor for making user productive. More number of requests ending in Unknown shall degrade the desired outcome.
Rerference:
https://www.twilio.com/docs/voice/answering-machine-detection
https://www.twilio.com/docs/voice/answering-machine-detection#webhook-parameters
Based on above workflows we are deciding to use MachineDetection:DetectMessageEnd configuration option. We do have a query regarding point number 2.4. Below is a scenario,
We have made an API request to initiate a call with MachineDetection:DetectMessageEnd configuration. A callee has picked a phone and introduced himself/herself. Twilio has detected a human and set answered_by to human. This has triggered a webhood which as patched a user to current call. It is very much possible that a user who has joined the conference is not aware of who is at other end and can end up asking who is this? This may anoy a callee and affecting overall customer engagement.
This is the scenario shared by our client based on his experience.
I would like to know how fast Twilio can detect "answerd_by"?
Is there a mechanism that can allow a recording of a callee to be played after patching a call so that a user is aware of who is at another end. Is it something Twilio can provide or we need to use the recording feature to do so?
I understand that Twilio has various options to tweak AMD parameters through a Web API however, we may not have enough data to tweak them before the start of the project. We might get there after rolling this feature in production.
Also our client mentioned that sometimes, a voice message is not delivered completely?
Is this something observed by Twilio customers too?
If so what are the best practices to ensure this shouldn't happen?

Is it mandatory to create a TwiML app in order to receive calls?

Im starting to integrate Twilio into our app and we need to receive the inbound notifications from Twilio. I noticed that I can also set up the webhook url straight into the number.
So, my questions is? which is preferable? Set up the url into the number or direct into the TwiML app? The advantage I see is that I can add parameters straight into the number (One number, one campaign) instead of a single url for all my numbers.
Are there other considerations that I need to take in count?
Twilio developer evangelist here.
It is not mandatory to create a TwiML app to receive calls, you can, as you say, set up a URL for each number you purchase.
TwiML apps do have benefits as you scale. For example, if you have multiple numbers, perhaps from different countries, which all point at the same URL, then using a TwiML app would mean that if you needed to change the URL in the future you could change it one place, not for every number. TwiML apps have the added benefit of a friendly name that you can use to describe what the URL does, rather than trying to guess from the URL itself.
The only downside to using a TwiML app that I can think of is that there is a level of indirection between what your number is doing and you have to go to the TwiML App section of the console when you are actively setting it up and experimenting.
My advice is that for short term experiments or work with single numbers to just use a URL and as you scale, move that to a TwiML app so that you can reap the benefits.
Let me know if that helps at all.

URL Scheme for Phone Call

Much like the "mailto" URL prefix launches the user's default mail program and starts a new email with specified address, is there a similar URL scheme that would initiate a phone call? Perhaps "phone," "call," or "sip"?
Incidentally, I'm targeting a platform that is using Cisco CUPS, so there may be a platform-specific way for me to initiate a call that is particular to Cisco, but I thought I'd ask the more general question first. However if anyone knows specifically how to programmatically initiate a call via CUPS, that would be great too.
The official standard for providing a telephone number as a URI is here: http://www.ietf.org/rfc/rfc3966.txt
It basically says use tel: as the prefix, and start the number with +[international dialling code] before the number itself. You can put non-numeric characters as separators (e.g. -) but they must be ignored. So a London (UK) number might be:
tel:+44-20-8123-4567
A New York (US) number:
tel:+1-212-555-1234
There is such a URI scheme: tel. It has an elaborate syntax, but here is a simple example of its usage:
tel:123-4567
For the full specification, refer to http://www.ietf.org/rfc/rfc3966.txt .
I'm after the same sort of functionality for Microsoft Office Communicator. After a bit of investigation I found that the following URI syntax will initiate a (VoIP) phone call via communicator:
tel:+number
eg: to get communicator to call my extension:
tel:+7780
sip: (or sips:) is the official URI scheme for SIP, and I think callto: was used by Skype, but is deprecated.

Resources