Status call back URL in twilio - twilio

I want to get the status of my call while using twilio.
I am configuring a status call back url for the same which is accepting a Post verb. But not sure What should the method of the REST webservices have in its POST method? If Twilio is posting back the status, then what should the POST method of the webservices do? Not able to get a idea on this, please help..
I am programming it in .net

Twilio developer evangelist here.
The status callback requests will send all the regular parameters that any Twilio Voice webhook sends as well as a few extra parameters that you can find in the documentation here.

Finally I found a solution how to get back status from twilio. Just design an Http Handler and use the context property to get back the parameters. The handler should look like this:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim callsid = context.Request.Params.Get("CallSid")
Dim FromNumber = context.Request.Params.Get("From")
Dim ToNumber = context.Request.Params.Get("To")
Dim callStatus = context.Request.Params.Get("CallStatus")
' ...
End Sub

Related

Is there a way to print the POST request URL that the Twilio-API makes when sending SMS?

I need to have the exact request URL that Twilio makes when sending an SMS. Is there a way to print/log it? When I use the Message.getUri method, it gives me something that ends with .json which I think is the response from Twilio after making the request. From what I've read, it should look something like "https://api.twilio.com/2010-04-01/Accounts/<Account_SID>/Messages".
I'm using the Java API:
com.twilio.rest.api.v2010.account.Message
.creator(new PhoneNumber(toNumber), // to
new PhoneNumber(twilioFromNumber), // from
textMessage)
.create();
The URL is indeed
https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json
where ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is the account SID which you can find on your dashboard if you login in your Twilio account console at https://www.twilio.com/console
See more docs at (https://www.twilio.com/docs/sms/send-messages?code-sample=code-send-an-sms-message&code-language=curl&code-sdk-version=json#linkcode)

How do you forward Twilio calls to different URLs in the middle of a call? (Using Node)

I'd like the following functionality with Twilio/Node: either
my server receives incoming call and the call rings on our custom client; at some point during the call (ideally can work before answering or after answering) or if no one answers on the client, the call is transferred to a webhook on a different server (my CRM provider) so the CRM can deal with it. OR
same as above, but the incoming call posts the incoming call request to both my server & my CRM webhook for the incoming call; I think this might not be possible though, not sure
I'm able to receive a Twilio call on my server without problem, and able to receive Twilio calls in my CRM without problem. However, when I tried to forward a call to the CRM after first receiving it on my custom server/client, it seems to always disconnect abrubtly. Pls help!
The code I'm using to update the call is below. The url works normally if sending the call directly to the CRM webhook. The CallSid is from my custom client from the incoming call
client.calls(req.body.CallSid)
.update({method: 'POST', url: 'https://crm.crmprovider.com/ctiapi/xml/cticall/twilio?authtoken=abc'})
Appreciate any help!
Think I figured out the proper way to do this. Should be using an "action" with "dial" and then checking "DialCallStatus" in the action endpoint and dealing with various statuses as appropriate. Sample code:
// On server, receive call. This is the url Twilio is
// set to post webhook to when call comes in
app.post('/incomingCall', (req, res) => {
const twiml = new VoiceResponse();
// Dial client first; after, call /callAction
// I believe this will call /callAction if call is unanswered for 10 seconds or after a completed call or if there's no client open
const dial = twiml.dial({timeout:10, action: '/callAction'});
const client = 'whateverClientName'
dial.client(client)
res.type('text/xml')
res.send(twiml.toString())
})
app.post('/callAction',(req,res)=>{
const twiml = new VoiceResponse();
// Can set below if for other things like if call not completed, answered, or cancelled
// In this example we say if call's not completed, route call to 3rd party site's webhook to further deal with the ongoing call
if(req.body.DialCallStatus!=='completed'){
twiml.redirect({method: 'POST'},'https://thirdpartywebhook.com/abc')}
else {twiml.hangup()}
res.type('text/xml')
res.send(twiml.toString())
})
I didn't find Twilio docs super straightforward on this so hopefully this helps someone in the future!

Taskrouter problem using Laravel. Task not getting created?

I've followed every single step in the Twilio's documentation called Dynamic Call Center with Laravel.
My problem is that a call gets through the IVR, then after choosing a digit, nothing happens.
My guess is that its not creating a task. the code provided in the documentation just generate a task with json but thats it. I check my tasks in Twilio taskrouter console and nothing shows up.
I've provided all credentials, used ngrok, filled in all url callbacks.
public function enqueueCall(Request $request)
{
define('workflowSid', env('TWILIO_WORKFLOW_SID'));
$selectedSkillInstruction = new \StdClass();
$selectedSkillInstruction->selected_skill = $this->_getSelectedSkill($request);
$response = new Twiml();
$enqueue = $response->enqueue(['workflowSid' => workflowSid]);
$enqueue->task(json_encode($selectedSkillInstruction));
return response($response)->header('Content-Type', 'text/xml');
}
I expect a code that actually creates a task, but when I call this api via postman, a task is not created
The above code returns Twilio Markup Language (TwiML) which uses the enqueue verb and a workflowSid attribute. The enqueue verb is used with Programmable Voice. Have you tried associating your application with a Twilio phone number and then calling the Twilio number which should enqueue the call into a task router workflow?
TwiML Voice: Enqueue
https://www.twilio.com/docs/voice/twiml/enqueue#attributes-workflowSid
I have solved my problem. It turned out that everything was in order, the only problem is that I didn't know I need to press # after choosing from the IVR because all the demo I saw from Twilio only press a number and it gets routed.

How can I find the caller name with Twilio?

I want to get the caller name on either request url or status callback url. I am using C# code for purchasing the numbers.
option parameter is as below:-
options.VoiceUrl = ConfigurationManager.AppSettings["ServerUrl"] + "/Home/RaiseCallEvent";
options.StatusCallback = ConfigurationManager.AppSettings["ServerUrl"] + "/Home/EndCallEvent";
options.PhoneNumber = Number.PhoneNumber;
options.VoiceMethod = "GET";
options.VoiceCallerIdLookup = true; //for getting the caller name
options.StatusCallbackMethod = "GET";
IncomingPhoneNumber = TwilioClient.AddIncomingPhoneNumber(options);
I have done the VoiceCallerIdLookup as true now when twilio hits my voice url RaiseCallEvent or status call back url EndCallEvent then in which parameter I can get the caller name?
Twilio evangelist here.
If you've enabled VoiceCallerIdLookup on your IncomingPhoneNumber, then when Twilio makes its HTTP request to your Voice Request URL, it will include a parameter called CallerName. A complete list of all the parameters we send as part of the Voice Request is here:
https://www.twilio.com/docs/api/twiml/twilio_request
Hope that helps.

StatusCallback does not work as expected

Overview:
I am working on a VB.NET application that places a call into Twilio, the number is not a test number. I am using the C# library with the code written in VB.Net.
When I use this line of code:
Console.WriteLine(account.SendSmsMessage(Caller, to1, strBody))
I receive a text message on my phone however the post back is never posted to my website. I have included the URL of the site on the account under Messaging > Request URL.
When I reply to the message, Twilio does make a post to my site. From what I understand, a POST should have been made when Twilio was first sent a message from my application, however this is not the case.
When using this code, I do not get any text message and no POST is made.
Console.WriteLine(account.SendMessage(Caller, to1, strBody, PostBackURL))
I have tried SendSMSMessage, I have tried it with the URL on my account and without it,
nothing seems to effect the behavior.
I need the SmsMessageSid at the time the message is sent. From everything I have seen, Twilio does not provide a response other then what is sent to the PostBackURL, I could parse a response for the
SmsMessageSid however since there is no response that is not an option. If I am mistaken on that point that would be great, however it looks like the only way to get a reply is with the post back URL. Thanks for your help with this! Below you will find an excerpt of the code I am working with:
PostBackURL = "http%3A%2F%2F173.111.111.110%3A8001/XMLResponse.aspx"
' Create Twilio REST account object using Twilio account ID and token
account = New Twilio.TwilioRestClient(SID, Token)
message = New Twilio.Message
Try
'WORKS
'Console.WriteLine(account.SendSmsMessage(Caller, to1, strBody))
'DOES NOT WORK
Console.WriteLine(account.SendMessage(Caller, to1, strBody, PostBackURL))
Catch e As Exception
Console.WriteLine("An error occurred: {0}", e.Message)
End Try
Console.WriteLine("Press any key to continue")
Console.ReadKey()
I'm doing something similar with C# and like you, I'm not getting the POST to the callback URL. I don't know why that's not working, but if all you need is the sid when you send the message, you should be able to do this:
message = SendSmsMessage(Caller, to1, strBody))
and message.Sid will give you what you need, assuming no exceptions.

Resources