Get SIP Invite Header on Watson Voice Agent - twilio

I'm doing an application in Java that connects a phone call to Watson Voice Agent to my user via Twilio and i need to pass some information to the Voice Agent and make it available to the assistant.
I'm passing the information on the sip invite header but I can't get the information on the assistant dialog.
My Twilio call class:
public String callPhone(String to, String from,String data)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("https://handler.twilio.com/twiml/xxxx?data_sent="+data))
.create();
return call.getSid();
}
My TwinML Bin code:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Sip>sip:{{From}}#us-south.voiceagent.cloud.ibm.com?X-data={{data_sent}}</Sip>
</Dial\>
</Response>
In my Voice Agent config I put the "Custom SIP INVITE header" as "data" (without quotes) and in the Assistant I try to access $vgwSIPCustomInviteHeader but the Voice Agent doesn't say anything where this value should be.

I've already solved it, for some reason if I use the header parameter with "_" the TwinML Bin doesn't seem to be able to send the value correctly, I changed the parameter to "dataSent" and now it works fine.

Related

Unable to get custom parameters passed using Twilio connect function for outgoing and incoming calls

Am trying to create a call center with Twilio, am almost there but now am stuck because i can't get custom passed parameters.
My main aim is to allow customers to call but first they should provide their emails and names first, then click call-customer button, i want to receive the custom parameters on the agent's side.
Now i try to pass the parameters but i can't retrieve them.
Here is my code to make and receive calls and to pass and get the parameters
(Customer side)This code allows outgoing calls, customers to make calls to the call-center agents
require __DIR__ . '/vendor/autoload.php';
use Twilio\Jwt\ClientToken;
$accountSid = '';
$authToken = '';
$appSid = '';
$capability = new ClientToken($accountSid, $authToken);
$capability->allowClientOutgoing($appSid);
$token = $capability->generateToken();
So according to the documentation i should pass the custom parameters like this:
var params = {"name": "John", "email": "john#gmail.com"};
Twilio.Device.connect(params);
(Agent side) This code allows incoming calls from customers to agents.
$accountSid = '';
$authToken = '';
$capability = new ClientToken($accountSid, $authToken);
$capability->allowClientIncoming('joey');
$token = $capability->generateToken();
In the agent side i use this code to receive customer information or custom parameters.
According to the documentation a code to get custom parameters is this:
if (connection.customParameters.hasOwnProperty("name")) {
let displayName = connection.customParameters.get("name");
console.log(displayName)
}
if (connection.customParameters.hasOwnProperty("email")) {
let customerID = connection.customParameters.get("email");
console.log(customerID)
}
but i get undefined
So when a customer calls this twilio function en-queues the call and assign it to an operator
here is the code:
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
twiml.say(" Please hold, while we connect you to one of our available agent ");
twiml.enqueue({
workflowSid: context.WORKFLOW_SID
}).task({}, `{"selected_skill":"operator"}`);
callback(null, twiml);
};
Then from here an available operator will accept the task then dial an agent
The operator dials the client like this
{"skills":["operator"],"contact_uri":"client:joey"}
Please help
Thanks in advance
Based on my take on the associated documentation, it looks like the parameters are only sent to the Twilio client via TwiML, as shown here.
https://www.twilio.com/docs/voice/client/javascript/changelog#160-aug-29-2018
Added support for custom incoming parameters from TwiML as Map Connection.customParameters. When a TwiML application sends
custom parameters using the noun, these parameters will be
added to Connection.customParameters
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Client>
<Identity>alice</Identity>
<Parameter name="foo" value="bar"/>
<Parameter name="baz" value="123"/>
</Client>
</Dial>
</Response>
It sounds like you are using the Task Router JavaScript SDK, maybe you can add these parameters as attributes to the task, and then access those tasks from the Task Router client SDK?

Passing custom CNAM through Twilio SIP Domain

I have a Twilio phone number configured to direct inbound calls to a PHP webhook. The webhook uses some of the addon information to try and find a useful caller name. I'm also using Twilio's built-in CNAM lookups, but they don't work right in Canada (I always get the caller's number as their name).
The webhook is designed to forward calls to a Twilio SIP Domain first, where I expect I'll be answering most of the calls. Other calls, if deemed urgent, will be forwarded via PSTN.
I've reached the point where I can pull out a relevant name, but I'm having difficulty trying to forward that information to my FXS (HT802). As per the device's documentation:
http://www.grandstream.com/sites/default/files/Resources/ht80x_administration_guide.pdf
Auto: When set to “Auto”, the HT801/HT802 will look for the caller ID in the order of P-Asserted Identity Header, Remote-Party-ID Header and From Header in the incoming SIP INVITE
I'm not able to find a means to pass these headers via a SIP noun in TwiML. Based on Twilio's documentation:
https://www.twilio.com/docs/voice/twiml/sip#custom-headers
UUI (User-to-User Information) header can be sent without prepending x-
https://www.twilio.com/docs/voice/api/sending-sip#sip-x-headers
If you send headers without X- prefix, Twilio will not read the header. As a result, the header will not be passed in the output.
For context, here's a reduced snippet of the PHP code I'm using so far. Note: I'm not actually doing anything with the $callerName value yet.
<?php
// Simple "starting value", in case we can't resolve the name.
// (will also resolve the numbers used for unknown/blocked IDs)
$callerName = FriendlyFormatPhoneNumber($_POST['From']);
use Twilio\Twiml;
$addOns = null;
if (array_key_exists('CallerName', $_POST)) {
$callerName = $_POST['CallerName'];
} elseif (array_key_exists('AddOns', $_POST)) {
$addOns = json_decode($_POST['AddOns']);
$teloName = $addOns->results->telo_opencnam->result->name;
// If we pulled a telo name, and it doesn't seem to be a phone number
// (in case that could happen), use the telo name.
if (isset($teloName) && preg_match('/.*[0-9]{4,}, $teloName') == 0) {
$callerName = $teloName;
}
}
$response = new TwiML;
$dialParams = array(,
'timeout' => 20,
'hangupOnStar' => false,
'answerOnBridge' => true,
'action' => API_BASE_URL . '/dial-callback.php'
);
$dialer = $response->dial($dialParams);
$dialer->sip('sip:101#mytwiliodomain.sip.us1.twilio.com;transport=tls');
echo $response;
Long story short: How do I pass a custom caller name to my SIP devices using TwiML and the Twilio SIP Domains? I don't want to overwrite the number, just the name. And only on the inbound calls to the devices registered to my Twilio SIP domain.
In case it helps: Don't worry about translating to PHP if that's not your field; I can translate from TwiML :)
Unfortunately, this is not possible with Twilio SIP Domains. Currently, there is no way to set the Caller Name via TwiML.

Twilio TwiML How do I pass URL parameters to TwiML script?

I want to pass a parameter via URL for TwiML to read from when it addresses the person on the other end of the phone. I can't seem to get it to work right. I've tried all sorts of things.
Here is my ASP.NET VB Code...
Dim XClient As New TwilioRestClient(accountSid:=accountSID, authToken:=authToken)
XClient.InitiateOutboundCall(from:=From, [to]:=SendTo, url:="http://mywebsite.com/TestURI.xml?test=Todd")
Here is my XML...
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice">$test</Say>
<Pause length="1"/>
<Say voice="alice">Do you enjoy hotdogs? I do.</Say>
<Pause length="1"/>
<Say voice="alice">Please work so that I can enjoy my lunch in peace!</Say>
</Response>
How do I get this TwiML script to report "Todd" from the URL? Any help is much appreciated. Thank you!
TwimL Bins has has the concepts of templating you can leverage (and also not have to host the TwiML on your own servers).
How to use templates with TwiML Bins
https://support.twilio.com/hc/en-us/articles/230878368-How-to-use-templates-with-TwiML-Bins
Pass in the URL parameter and then reference it in the TwiMLBin as a Template.
<Say>{{Test}}</Say>
You can also use Twilio Functions (Node),https://www.twilio.com/console/runtime/functions/manage, with JavaScript ES6 template literals to do similar:
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let testParam = event.test;
twiml.say(`Hello ${testParam}`);
callback(null, twiml);
};
What you'll need to do is generate a dynamic XML (TwiML) response that can incorporate any query parameters into the XML response. I don't know ASP.NET or Visual Basic very well, but most web programming languages have a way to generate dynamic responses in response to HTTP requests.
Here's an example in the Twilio docs of how to generate a TwiML response from an ASP.NET MVC application - it might not be precisely the same technology you are working with, but it might help you get pointed in the right direction:
https://www.twilio.com/docs/voice/quickstart/csharp?code-sample=code-make-an-outgoing-call-using-twilio-and-c&code-language=C%23&code-sdk-version=5.x

Twilio autopilot handoff action is not working with Twiml Bin

I have a Twilio autopilot task from an incoming call, which performs a greeting then asks a question before redirecting to a new task called 'callnumber'. This all works fine.
The 'callnumber' task looks like this
{
"actions": [
{
"handoff": {
"channel": "voice",
"uri": "https://handler.twilio.com/twiml/TWIMLBINID"
}
}
]
}
TWIMLBINID actually has the correct ID from the Twiml Bin.
This is the Twiml content in the bin:
<Response>
<Say>I will put you in contact with our customer care specialist.</Say>
</Response>
Unfortunately I'm not hearing this Response spoken out and instead just get the standard 'an error has occurred' voice message.
I've tried a few different versions of this, even calling an xml file hosted on my own public web server and seeing the same problem. Also tried the dial verb and still seeing this issue.
I feel like I may have missed some configuration, after seeing similar posts like: Twilio autopilot doesnt say what it is supposed to say
Any help is much appreciated!
I was able to get the TwiML Bin working with similar JSON, when I have it associated with a Task that has samples.
So, for example, a call comes in to your Autopilot assistant and initially triggers the Assistant Initiation Task of hello_world where you modified the predefined JSON with a listen action.
{
"actions": [
{
"say": "How can I help you today?"
},
{
"listen": true
}
]
}
You then respond so the task associated with your handoff JSON/TwiML Bin is executed (based on the samples you provided). If you try to call the handoff task directly, it fails.
I have the same JSON for "actions" of the task-seems perfect.
But 2 Small differences for the TwiMLbin :
1)don't forget to put the xml tag in the TwiLbin :
It should be :
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>For this question, I will put you in contact ...</Say>
</Response>
2)I don't understand how your twiMLbin has such an hyperlink. Normally the syntax is
https://handler.twilio.com/twiml/******SID******
and the SID can not be chosen and mine has 34 characters. (do not use the "friendly name" of the twiMLbin). You have a button in the twiMLbin to copy-paste it directly.
for me it works. Otherwise please provide some more elements
-do you have queries associated to the autopilot task ? if you have task(s) that do not have any queries, the model will refuse to build (you can check this in the screen "natural language router" / tab "build models").
-are you sure you don't have conflicting query that triggers another task than the one you think (typically with short queries, they "vampirize" other intents). For that please provide the logs of the queries (query Vs Task) of your autopilot assistant.
nb : I confirm what philnash said : you should really try with a phone call. I experienced also some "glitches" with the Twilio simulator.

Twilio :making a call

I'm not having much luck making a call via Twilio...
I want a button to click while I'm in the office that puts me through to a clients number that I've typed into a web page.
I can do "Click to call": http://www.twilio.com/docs/howto/click-to-call , but that's for the user to phone the company - what I'm after is my company phone phone to call the user.
I thought it would be a simple case of setting the From/To fields in InitiateOutboundCall, and leaving the URL field blank.
It didn't work at all.
I then tried with an empty XML page, because I thought "When the call connects, I don't want the system to do anything else, like saying a message, I just want the two people to talk!
e.g.:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Response> </Response>
When I do that, the client's phone rings, and it says "Company X" on it, but when the phone is picked up it rings off,
I tried with this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Response>
<Dial>
<Number>123456</Number>
</Dial>
</Response>
And it called the client's phone, then called the staff's phone - but that's the click-to-call I mentioned above.
Please help!
Protected sub makeCall()
Dim options As New CallOptions()
Dim ACCOUNT_SID = ""
Dim AUTH_TOKEN = ""
options.Url = xxxxxxxxxxxxxxxxxxxx?
options.From = "+Number listed in Twilio callers page"
options.To = "+My mobile number"
WriteLine(""):WriteLine(""):WriteLine("")
Dim TwilClient As New TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
WriteLine("TwilClient created.")
Dim outboundCall = TwilClient.InitiateOutboundCall(options)
WriteLine("Call created.")
WriteLine("Call status: " & outboundCall.Status)
If Not IsNothing(outboundCall.RestException )
WriteLine("ERROR!: " & outboundCall.RestException.Message)
End If
IndentLevel +=1
WriteLine("")
WriteLine("SID: " & outboundCall.Sid)
Session("mycallsid") = outboundCall.Sid
Unindent
End Sub
Twilio evangelist here.
Just to clarify, do you want to make a phone call right from within the browser?
If that's the case, you'll need to use Twilio Client, which has a JavaScript SDK that you can use to create an audio connection from your browser to Twilio. Once thats created, you can tell Twilio to connect to a second number and we will bridge the two calls together.
This quickstart shows you how to use Twilio Client with C# to be able to make and receive phone calls from a browser:
http://www.twilio.com/docs/quickstart/csharp/client
Hope that helps.
Devin

Resources