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.
来源:https://stackoverflow.com/questions/32155664/twilio-browser-client-available-or-not