how to execute dialing a queue in twilio php? - twilio

How do I execute this code?
$response = new Twiml();
$dial = $response->dial();
$dial->queue('support', ['url' => 'about_to_connect.xml']);
echo $response;
I'm using laravel and used this function on button click. All I get is a Twiml return.

Twilio developer evangelist here.
Let me explain the use of TwiML within Twilio applications. TwiML does not initiate phone calls, it is used to react to events within phone calls.
When you receive an incoming call to your Twilio number or when you make a call via the Voice API which connects, Twilio then needs to ask your application what to do with that call. It does so by making an HTTP request to the URL you provide for the phone number or via the API request. Your application needs to respond to that request with TwiML to provide the instructions for the call.
In your case, it looks like you're trying to make a call to a number and then connect that user to the first person waiting in the support queue. To do that, you should keep the TwiML you have, just don't execute it on the button click.
Instead, when your user clicks the button you should make the API call to generate the call and direct Twilio to call this TwiML when the call connects.
This tutorial on click to call using Twilio and Laravel should help with this.

Related

Get Whatsapp Number of user in Twilio autopilot

I am trying to create a chatbot using Twilio Autopilot which integrated with WhatsApp. So my flow is like, if user messages on registerd number, Twilio WhatsApp senders webhook will get trigger and it will call Autopilot chatbot task. Task will process the data and it will send reply.
In all above flow I want to capture the WhatsApp number of the user who is asking the question. that number I want in autopilot, so Autopilot will send that number to Twilio function and I want to save that number in my Database using external API's call from Twilio function.
How I will get WhatsApp number inside Twilio Autopilot chatbot for user who is asking questions?
Thanks in Advance
Autopilot can respond using static actions defined within the task, but it can also send a webhook request to fetch Actions JSON from your server. That webhook request contains details about the user you are talking with, including the parameter UserIdentifier which, in a WhatsApp chat, will be the user's WhatsApp number.
If you are currently responding to tasks from Actions JSON defined in the Twilio console, you can add a webhook by using a "redirect" action at the end of a set of actions to a URL you control and then responding to that with a "listen" action to wait for the next task. Alternatively, you could just set a URL for the webhook and respond with your Actions JSON from your own app.

Connect Twilio Outbound call to Watson Assistant

I'm trying to make an outbound call using Twilio's API and connect the number that i'm calling to my Watson Voice Agent(that is linked to my Watson Assistant). I can call the phone but the call isn't redirected to the assistant.
I'm using the Twilio API for java. I've set my Twilio number's SIP trunk to use my Voice Agent's SIP
This is the method implementation
public String callPhone(String to, String from)throws URISyntaxException{
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Call call = Call.creator(
new com.twilio.type.PhoneNumber(to),
new com.twilio.type.PhoneNumber(from),
new URI("http://www.example.com/sipdial.xml"))
.create();
return call.getSid();
This is my call:
tw.callPhone(phoneIWantToCall,TwilioPhoneNumber);
tw.callPhone("sip:TwilioPhoneNumber#us-south.voiceagent.cloud.ibm.com",TwilioPhoneNumber);
I receive a call from my Twilio number but it isn't directed to my Assistant
Twilio developer evangelist here.
The issue here is that you are creating two separate calls that don't connect.
Instead of generating two calls using the REST API, you need to return TwiML from the URI in your URI parameter that connects the call to the person to the Watson agent. So you should set the URI in your callPhone method to a URL in your own application. And that URI should return TwiML that includes <Dial> to connect to the agent in this case using <Sip>.
The TwiML should look a bit like this:
<Response>
<Dial>
<Sip>sip:TwilioPhoneNumber#us-south.voiceagent.cloud.ibm.com</Sip>
</Dial>
</Response>
Let me know if that helps at all.

change the voice for twilio number incoming call

We have a twilio number.
When ever any one call on that twilio number then there is an automated voice of twilio play. Can we customize this to a new message?
Thanks,
Rajendra
Twilio developer evangelist here.
You can customise Twilio calls as much as you want! I recommend you take a look through this QuickStart for handling incoming phone calls with Twilio which should get you up and running.
To quickly describe it though, you have a Twilio number and that number has a Voice Request URL configured in the number's settings. When you make a call to that Twilio number, Twilio makes an HTTP request to the URL. That URL needs to return TwiML (a set of instructions to Twilio in XML) which tells Twilio what to do with the call.
If you update the URL to something you control and then return different TwiML, then you can change the message and do a whole lot of other stuff with your Twilio number.

Dialling Offline Twilio Client

I need to make calls to some Twilio clients that will received the call through the browser. The problem is, these clients don't necessarily have their browser open.
I know normally, a user would have to open up the browser and through the twilio util capability and twilio device to turn their browser into a device. And THEN they can receive incoming call.
Is there way to dial clients, when they haven't initialize their twilio client yet?
Twilio evangelist here.
If you try to dial a client who is not online Twilio will view that as a no-answer. You can get a notification of this by providing a URL for the <Dial> verbs action parameter.
When the call ends Twilio will make a request to this URL with a parameter named DialCallStatus which you can use to determine what happened when Twilio tried to dial the Client.
Hope that helps.

Can you do peer to peer calls with Twilio?

If I wanted to create an interoffice phone system with Twilio can you call between two registered clients on Twilio, i.e. can I call my co-worker in the office across from me?
Bonus prize, if you can do that, can you enqueue the call to the other person, essentially creating a multi-line phone for people?
Thanks!
Twilio evangelist here.
Sure, you can absolutely make a Client to Client call. The Twilio Client for JavaScript Quickstart has a walk-through showing you how to do this:
https://www.twilio.com/docs/quickstart/php/client/browser-to-browser-calls
You can also use the Queue verb in a client-to-client call.
Lets say you want to put Call A (lets call them 'customer') into a queue. To do that you would create a new TwiML App and point it at a URL that returns the <Enqueue> verb. When you initiate that client you would use that TwiML Apps SID to generate the Capability token.
Now for Call B (lets call them 'agent'). If you want to connect them to callers in your Queu, you would create another TwiML app whose URL returns TwiML with the <Dial> verb containing the <Queue> noun. This tells Twilio to connect the 'agent' with the first caller in the queue. As with the 'customer', when you initialize the 'agent', you would use the 'agent' specific TwiML App SID to generate the Capability token.
Hope that helps.
Devin

Resources