Twilio Browser client Available or not - twilio

I am facing a problem with Twilio to detect the Twilio Browser client Available or not.
If Twilio client is not available then need to send the voicemail otherwise I am using to accept the call.
Twilio.Device.incoming(function (conn);
Thanks.

Sounds like you need agent presence. There are a couple ways to go about this. One (Recommended) is to use Twilio TaskRouter. https://www.twilio.com/taskrouter. This will handle agent presence for you (online, offline, busy, etc..) and much more
Your other option is to use a service like PubNub http://www.pubnub.com/ and bind the clint so you can get state information (online, offline, busy, etc..). This is more wok since you have to handle state yourself.

The following steps can be followed to achieve this
 1. Set a valid url to the action attribute of the Dial verb of the client
  Eg., The TwiMl to dial the client must be
  <Response>
   <Dial action="myapp/statusCallBack">
    <Client>jenny</Client>
   </Dial>
  </Response>
 2. If the client jenny is available, the connection object can be received via
  Twilio.Device.incoming(function (conn){conn.accept();});
 3. If the client jenny is unavailable, Twilio will request to the statusCallBack url with the parameter 'DialCallStatus=no-answer'. Now the following
  twiml can be returned to say Unavailable message.
  <Response>
   <Say>
    Please leave your name and number along with a short message.
   </Say>
   <Record maxLength="3600" action="myapp/recordedUrl">
   </Record>
  </Response>
 4. Now the voicemail url can be stored when the "myapp/recordedUrl" is called once the caller recorded the voicemail. For more info on record verb, visit this site
 Note that the voice mail is recorded on two cases, if the client is unavailable or the client does not accept the call.

Related

How to receive a browser call using twilio to a phone number using javascript

Ok guys, I've been viewing twilio tutorials for the last couple hours and I seem to just not get it. Can someone give me a basic rundown on how to do the following?
I want to create an app that uses the microphone/speaker of my computer to receive a call.
I have a twilio account with a twilio voice phone # but I just don't seem to get how to connect a JS Device object to a phone #. I think it has something to do with a capability/auth token but can someone give me a step by step on how a phone # can be called and the headset will receive a voice call and begin the conversation. The tutorials show how you can make twilio speak a written statement in twiML but I don't understand how to make it make an actual voice call.
My current guess is that I need to do the following in the browser to accept a call. But I'm not sure what needs to be inside the token.
//I don't know what needs to be in the token in order to connect this
//web page twilio 'Device' to. I use c# but if you have a node.js or php example that would be fine
fetch('https://mybackend/getPhoneToken').then((token) => {
const device = new Device(token);
device.on('incoming', call => {
call.accept();
});
});
Thank you for your help.
This is my first answer, let's see if I can help.
First you have to generate the access token by giving the Voice grant.
Generate access token with your account sid, API key ,API key secret and identity.
access_token = AccessToken(<Account_sid>, <api_key>,<api_secret>, identity=identity)
Note: Identity Should be unique for each user. You can put identity as twiliophonenumber_userid
Grant the Voice incoming Access.
voice_grant = VoiceGrant(outgoing_application_sid=<twiml_sid>,incoming_allow=True)
Add grant to the access_token
access_token.add_grant(voice_grant)
Initialise the Twilio device with this access_token. Then you can make the incoming call to the twilio number and receive the call on browser.
You just need only one Twiml App for all the twilio phone numbes. Create a Twiml App with Request Url and method. (Whenever the js device make/receive calls, then twilio will send a request to this URL to get further instructions)
In the above Request URL function, you have to tell twilio what needs to do with the request. Here is a sample function
function handle_calls():
if outgoing_call:
dial.number(customer_phone_number)
else:
# handle incoming call
dial.client(identity) # This is the same identity which we have given while generating access_token. This will trigger "incoming" event on Js device.
To differentiate between outgoing / incoming calls, you can send extra parameters to twilio while making outgoing calls and handle the request accordingly in the above function (pt. 6). See below sample function.
var params = {"direction":"Outgoing"} # Based on this parameter you can differentiate between outgoing/incoming calls.
device.connect(params)
You can setup status_callback events to better handle the call progress. have a look at this article...https://www.twilio.com/docs/voice/twiml/number#attributes-status-callback-event
Have a look at this article, you can get some more information - https://www.twilio.com/blog/generate-access-token-twilio-chat-video-voice-using-twilio-functions

Twilio Application Failed Message

I have been trying to build a app that redirect a Twilio number to another phone number when a customer call Twilio number.
When callback URL does not return proper Twilml, it says "Application has failed" message on the call.
However, I do not want my customers hear that message even though there is a error.
Is there a way to turn that message off?
Thank you.
Twilio evangelist here.
There is no way to disable the error message, but you can set a Fallback URL on your phone number that Twilio will request in case the Voice Request URL fails.
You could set the Fallback URL to a simple static XML file hosted somewhere like Amazon or Dropbox, or use a service like twimlbin.com to host some backup TwiML for you.

How to set the From identifier for Twilio Client (VoIP) outgoing calls?

Our application accepts phone calls or VoIP connections via the twilio.js client into our twilio endpoint. Phone calls are logged by caller ID, but VoIP connections all appear as Anonymous in the twilio call log, e.g.:
Date Direction From To Type Status Recording Duration
XXYY Incoming Anonymous --- Client Completed --- 17 min 7 sec
YYZZ Incoming Anonymous --- Client Completed --- 17 min 23 sec
Is there a way to set the From field for outgoing (client->twilio) calls? Looked through Twilio.Device.connect as well as the capability token docs and couldn't find any hints.
It all ties into the capability token step, in a completely undocumented (and apparently unknown to Twilio themselves) manner.
In order to get the twilio logs to identify the VoIP endpoint that called into a conference, we had to bind the client ID to the allow_client_incoming capability, and make sure the ID was a straight alphanumeric (e.g. dashes in the string prevented the ID from coming through).
In our server side (ruby) token generation step, it looks something like this:
capability.allow_client_incoming sanitized_client_id
Twilio evangelist here.
When Client connects to your TwiML app endpoint, the From parameter that is passed to the Voice Request URL should be the name of the client.
If that Voice Request URL includes the <Dial> verb telling Twilio to make an outbound phone call and bridge it with the Client call, you can set the callerId parameter:
<Dial callerId="+15555555555" />
Hope that helps.
What worked for me was to set the clientName parameter in the OutgoingClientScope capability.
This is a code sample in js:
capability.addScope(
new ClientCapability.OutgoingClientScope({
clientName: 'mike',
applicationSid: 'AP...'
})
);
None of the other answers worked for me.

Using Twilio to respond to an SMS with a http redirect to an external webapp

so, when i send a text message to twilio number, i want it to trigger a specific event in the webapp via http POST. For example, by making a http call to the webapp URL (http://webapp.com/triggerA) which it process to trigger an event A in the webapp.
Can I do this with twilio? If,so is there a sample piece of code which I can refer.
From what I understand from your question, I think you can do the following.
With Twilio, when you login into here
https://www.twilio.com/user/account/phone-numbers/incoming
You will find a list of your incoming numbers, I am assuming that you have already purchased a number. Once you click on a number in the list, you will find a page that where you can view and set various properties for the number you are looking at.
You will see a header called Messaging. Under that menu you will see a request Url.
you can set this to http://webapp.com/triggera as per your example. you can also choose whether you would like to use a http post or a http get request type.
the link below, will help you further for handling the data that Twilio passes your application.
https://www.twilio.com/docs/api/twiml/sms/twilio_request
Louis

twilio browser to browser incoming message shows +19999999999 instead of client name

I'm following the php quick start guide, and when I try call from one browser client to another browser client, I see the incoming messages shows that the call is coming from "+199999999" instead of the name of the client who is calling. Is anyone else experiencing this?
It appears that this happens when you don't specify a callerId. After adding a twilio number to the callerId variable, the incoming call message now shows the call is my twilio number instead of +19999999. For those who are wondering, you can also change your the callerId to a client name in the format of client:yourdesiredclientname for when you are dialing to a client.

Resources