How to list all available registered clients? - twilio

Using the twilio javascript client I can register a client like that:
capability.AllowClientIncoming("jenny");
Now let's say I have a number of people opening their browser and registering: "jenny", "benny", "teddy", "smitty"...
Is there a way I can list all the registered clients? Either with the twilio.js library or the REST API?

Twilio Evangelist here.
So you can use the Twilio.Device.presence() handler for this. It will be called once for each other client user, so you can create a list from that. If the state of any of the other client agents changes, the handler is called again.
Twilio.Device.presence(function (presenceEvent) {
console.log(presenceEvent.from + " available: " + presenceEvent.available;
});
There is a page to describe this feature on the Twilio Blog too. Lots more information on the Twilio Docs page.

Related

Can I use twilio studio flow with ultimate sms on same phone #?

I'm new to twilio. I have the "ultimate sms" plugin from codecanyon set up on my domain and connected to a twilio #. Is there a way to use the same # to set up a studio flow? I'd like to have people be able to send a text like "join" to my current twilio # and I can add them to a distribution list. As far as I can tell, I seem to only be able to set up 1 kind of messaging configuration for incoming messages. If possible, I'd like to use the same # for both workflows. Thank you!
Twilio developer evangelist here.
Twilio numbers process incoming messages by sending a webhook (HTTP request) to a URL. I have not used "Ultimate SMS", but I would assume the plugin requires you to set the Twilio webhook to your application so that it can manage the incoming requests.
Twilio Studio flows like to control the entire conversation, so is probably not a good idea for dealing with this.
You might be able to put some code between the incoming message and the webhook to do things based on whether the body starts with "join". Using a Twilio Function, you could write something like this:
exports.handler = async (context, event, callback) => {
if (event.Body.startsWith("join") {
// Subscribe the user to your list
const response = new Twilio.twiml.MessagingResponse()
response.message("You have subscribed to the list");
callback(null, response);
} else {
// Send the parameters on to the Ultimate SMS webhook URL and respond with the received response
const response = await getResponseFromWebhook(event)
callback(null, response.body);
}
}
This code is just a rough example, but hopefully you get the idea. You can proxy the webhook request through a Function like this (or an API endpoint written in any language if you don't want to use JavaScript or Twilio Functions) and peel off messages you want to by inspecting the body.

Bot Framework Twilio With Multiple Numbers

I have a bot that I've built that's running on the Azure Bot Service with a Twilio Channel. I'm sending Proactive activities via my Twilio channel. Everything is working fine. I just got a request that a customer wants to have their own phone number. I would like to just have 1 bot service running but have multiple Twilio phone numbers go into this.
My thought was that I could setup an API service which would then be the incoming message call back / webhook from Twilio which then would use the Directline API to the Bot Framework. It would essentially just replace the https://sms.botframework.com/api/sms service. The problem is that I'm not sure I could still have the proactive messages working - it seems like the Directline 3.0 API works only when a conversation is started first with it.
Does anyone have any thoughts on this if this would work or have any other ideas?
Thanks
Yes, the approach which you mentioned above would be ideal. Each Web App Bot/Bot Channels Registration can only be associated with one Twilio number. I will elaborate on the steps which you mentioned above:
Create a server running the Twilio SMS API code which forwards the messages to the bot via the DirectLine API. The user sends a message to this server.
For every activity sent to the bot, make sure to include the number: Activity.ChannelData = new { fromNumber: <123-456-7890> }. The Server forwards the message to the bot.
You will need to re-attach the fromNumber to the bot's outgoing activity so that your Twilio API server knows where to send the outgoing message to. The Bot sends the reply to the server.
The Twilio API server sends Activity.Text to the user. The Server forwards message from bot to user.
For the proactive messages part, you can add a conversation property to the address param, and set the id to the user's phone number.
Example:
bot.beginDialog(
{
user: { id: '+1234567890' },
bot: { id: '+9876543210' },
conversation: { id: '+1234567890' },
channelId: 'sms',
serviceUrl: 'https://sms.botframework.com'
},
);
Hope this helps.

Possible to use more than one Twilio studio flow with the same phone number?

I am trying to understand the relationship between phone numbers and studio flows.
Is it one flow per number, so I'd have to pay for a number for each of the flows?
Thanks
Edit: clarification.
Using a pay-as-you-go plan with a deposit and one $1/m phone number.
I need to answer this because the information provided by Twilio support, and my experience, contradict the answer I accepted earlier. Thank you to everyone who attempted to answer this.
My confusion was around the possibility to trigger multiple flows from the same number. This is possible, but the SMS replies to the flow messages drop off unless the flow is initiated from the phone number associated with this specific flow in the console.
So, if I have number-1 and flow-1, I need to associate number-1 with the flow-1 in the number settings. ONLY then will SMS responses to the flow actually go to the flow.
So, the answer to my question is:
Each flow needs its unique phone number, and the number needs to be associated with the flow in the number settings.
This requirement ensures that flows "know" the channel they're on, and will not change as the Twilio Studio moves out of beta.
Indeed in the console, you can only configure one flow for a number. When A MESSAGE COMES IN will trigger the configured flow.
If you have other flows that are not configured with a number, you can pass your Twilio number as from parameter when you trigger the flow via API call. If you don't pass the from number you'll get an error.
Sample Node.js code to trigger the flow via the REST API:
+19993335555 is your Twilio number
const accountSid = 'ACc0966dd96e4d55d26ae72df4d6dc3494';
const authToken = 'your_auth_token';
const TwilioClient = require('twilio')(accountSid, authToken);
TwilioClient.studio
.flows("FW9d816f0b90d2a10b913868462e339d29")
.engagements.create({
to: "+13335557777",
from: "+19993335555"
})
.then(function(engagement) {
console.log(engagement.sid);
});
Docs:
(https://www.twilio.com/docs/studio/user-guide#rest-api)

Twilio Browser client Available or not

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.

Twilio: Dial extension number along with twilio number

I am using Twilio for inbound calls, where user can call an application through Twilio-Number (brought from Twilio) and will be redirected to admin.
Now, We want Admin to call User using same Twilio-Number. We wabt to call this as <Twilio_Number>#<user_id>. We want to pass <user_id> as extension, so that when Admin clicks on the link with tel=<Twilio_Number>#<user_id>, it will initiate a phone-call to twilio-number.
In our app, we will find user's mobile using his id and redirect call to user's mobile number.
I have referred this doc: https://www.twilio.com/docs/howto/companydirectory
But would need few more details like:
How will Twilio recognize the extension number? And by which name is it provided in call-request parameters?
Currently, we received these parameters in twilio-voice call request
CallSid, AccountSid, ApiVersion, Direction, To, Called, Caller, From. In the same request-parameters, how I can get extension digits?
Thanks.
Have you had the chance to review the IVR information provided on Twilio's site? I believe it is a better solution for what you are trying to accomplish.
https://www.twilio.com/docs/howto/ivrs-the-basics
(Please follow the links to the next section at the bottom of the pages.)
After reviewing the documents, please open a support request with specific questions via https://www.twilio.com/user/account/support/ticket/create
Look forward to your ticket.
Take care!
I don't know if you solved this problem yet (probably yes) but what you can do is, create a record in DB with the extension (id agent) and when Twilio go to your callback url updated the records depending of the state.
Hope this works to you. I'm doing this with the same scenario.

Resources