Twilio Autopilot Handof with memory for on call conversation - node.js

I have an twilio autopilot similar to appointment schedule sample in twilio, I want it to have a memory before its even initiated, I have a B2C service, where I provide the platform to connect with their customers. Now each business offers different service so I want to be able to identify whose call my bot is attending and respond to the person based on that information.
Right now I have hardcoded business ID, but I want businesses to be able to handover to the bot with their business ID, I have read the documentation but it doesn't say how to handle call redirect as my Bot would be handling calls only.

Twilio developer evangelist here.
You can do this with Twilio Studio!
"Inbound Context lets you add data to the Autopilot Memory before starting a dialogue with the bot. In a Studio flow, it allows you to pass Flow variables created by other widgets in your flow seamlessly into Autopilot to be used in bot conversations. You can then parse these variables directly from the Memory JSON included in Autopilot's request to your application" (more info here):
-Memory.CarMake
-Memory.CarModel
You could alternatively use a URL like this one to pass Inbound Context with Memory where any message sent to a bot with this URL will insert CarModel, CarMake, and CarYear into the Autopilot Memory.
https://channels.autopilot.twilio.com/v1/<ACCOUNT_SID>/<ASSISTANT_SID>/twilio-messaging?Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}
That URL would go for a SMS bot and go in where you place the webhook URL for your Twilio phone number, but you could similarly modify it for WhatsApp (https://channels.autopilot.twilio.com/v1///twilio-messaging/whatsapp?Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}), Voice, Custom Channels (https://channels.autopilot.twilio.com/v1///custom/{YourCustomChannelName}?Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}) etc.
TwiML for voice would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Connect action="https://www.example.com/autopilot">
<Autopilot Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}>UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Autopilot>
</Connect>
</Response>
Let me know if this helps at all!:D

You can utilize Inbound Context, as detailed below.
Inbound Context
https://www.twilio.com/changelog/inbound-context
Inbound Context lets you add data to the Autopilot Memory before
starting a dialogue with the bot. It can help you make the bot
experience more personalized and contextual by making information like
names, purchase histories, account numbers etc. stored in third-party
systems available directly in the bot conversation.

I found a way to handle it, and it may not be the best way, but its really helpful for me.
So what I have done is I created an API that responds back with Twml
Similar to this
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Connect action="https://www.example.com/autopilot">
<Autopilot Memory={"CarModel":"Diablo","CarMake":"Lamborghini","CarYear":"2019"}>UAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Autopilot>
</Connect>
</Response>
Now I purchased number and set its webhook URL to the API I created, within that API, I can pass parameter and then create memory with those params
Here is my API handler in Nodejs:
const VoiceResponse = require('twilio').twiml.VoiceResponse
const voice = (req, res, next) => {
const response = new VoiceResponse()
const connect = response.connect()
connect.autopilot({
TargetTask: 'greeting',
Memory: `{"companyId": "${req.params.id}"}`
},
process.env.AUTOPILOT_SID)
res.type('text/xml')
res.send(response.toString())
}
I hope this helps somebody who is looking to create dynamic memory based on different numbers, or to create a bot that works for multi-tenant platform

Related

How can I get all envelopes status and their signers status in one request?

Is it possible to call the DocuSign API with the "docusign-client"-library in order to get status information about all envelopes with all of their recipients/signers in one request?
When we call the "EnvelopesApi.ListStatusAsync" method of the docusign client library we just retrieve an array of envelopes but without the status information of their signees.
public async Task<EnvelopesInformation> GetListStatus(EnvelopeIdsRequest envelopeIds, ListStatusOptions opt) {
return await Request(async api => await api.ListStatusAsync(settings.AccountId, envelopeIds, opt));
}
It seems that this information have to be determine in second request by calling
"EnvelopesApi.ListRecipientsAsync" method for every envelope.
Maybe someone have an idea or know how to call the API properly.
Are there any options we have to consider by calling the API or do we need to configure something in the DocuSign dashboard?
Thanks!
Remarks: In our environment we can't use webhooks. So we have to poll the DocuSign API.
No, it's not possible and maybe we should understand your statement about "we can't use webhooks".
My guess is that you have firewall or some private network and you can't have calls from outside into these servers. That's not a reason not to use webhooks.
There's a simple solution to this involving an intermediary cloud account that gets your webhooks and a queue mechanism for you to check for messages.
Here is a blog post by Larry that can help if you are willing to consider webhooks.
Yes, you're right. The main reason why we can't use webhooks is because the applicationn is behind a firewall and our customer do not want to make any changes on that.
Also I know the possibility of using DouSign with services like Azure or AWS to get notification about their bus-messaging system but this is something we do not want to implement yet. Maybe in the future.
We found out that we can use the "EnvelopesApi.ListStatusChangesAsync" method to get all of the status information we're interested in.
var options = new ListStatusChangesOptions {
envelopeIds = ids,
include = "recipients"
};
var result = await client.ListStatusChangesAsync(options);

How to send client Call sid to newly transferred agent using Twilio node.js library without using Database

I'm working on a conference call scenario and want to transfer live call from one agent to other agent. When I transfer the call is there any method that I could use to send the Conference Name, ConferenceSid and client Call Sid to new agent. as response.send() sends values to existing client. Is there any method we can use to send these parameters to new agent? The API used is as follows.
client.conferences(conferences.sid)
.participants
.create({
from: '+183xxxxxxxxx',
to: `client:${agentNumber}`
})
.then(participant => console.log(participant));
Twilio developer evangelist here.
In this cold transfer scenario you already have the conference sid, as you show in your code. So, to find the conference name you can use the REST API to look it up.
client.conferences(conference.sid)
.fetch()
.then(conference => console.log(conference.friendlyName));
You can also fetch the conference participants. One of the call sids will be the call you created to your agent and the other will be the caller that is already on the line.
client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.participants
.list()
.then(participants => {
participants.forEach(participant => console.log(participant.callSid));
});
Using these two API calls you can get the information for your new agent.
Let me know if this helps at all.

In a chatbot conversation using dialogflow, Is there a way to make the bot speak first?

Is it possible to format a conversation so that the bot initiates conversation using dialogflow in a web demo integration?
The objective is to say something like “Hi, I’m a bot, I can do x” to establish that it’s a chatbot rather than a human.
Can anyone suggest any idea for this?
You can set a welcome intent, then send a /query request containing an event parameter. Set the event parameter to WELCOME and your chatbot will respond with whatever conversation opening you set.
More info here: https://dialogflow.com/docs/events
If you are using something other than the API for interacting with your Dialogflow agent (Slack, Facebook Messenger, etc.) you will need to add an appropriate event under "intents" in your console (such as the "Facebook Welcome" event).
For interacting with your Dialogflow agent via the API, see below.
In the API interaction quickstart documentation, Dialogflow gives you the SessionClient's detectIntent method for sharing messages with your bot.
Each language has a different solution. But on an abstract level, you want to change the request object that you send to Dialogflow to include a "Welcome" event (no input message required), as Omegastick described.
For example, in Node.js, your request object would look like this:
// The text query request.
const request = {
session: sessionPath,
queryInput: {
event: {
name: "Welcome",
languageCode: languageCode
}
},
};
This assumes you have an appropriate intent set up in your Dialogflow console to handle Welcome events. One is provided by default that you can observe.
You can also add contexts, so that your agent gives a different greeting message based on some condition.

Multi Tenancy in Microsoft bot framework webchat

I have successfully hosted an instance of microsoft's Botframework web chat using directline on public domain, I want to make a chatbot in such a way that my customers can have their own channels completely separated from each other and I cannot find any kind of documentation anywhere, Kindly suggest me if this is possible and how?
I have written the complete code in Node.js and have very less idea about c#.
It seems that there is no such feature for uniform customized chat channel in bot framework. So we can leverage new builder.Message().address(address) to send messages to specific users from the official sample at https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/core-proactiveMessages/simpleSendMessage/index.js.
So I had a quick test which will save the users' addresses into an address list in server memory as a "customize channel", and trigger a key work to send message to these addresses in list as a broadcast in this "customize channel":
let channel_address = [];
bot.dialog('joinChannel',(session)=>{
channel_address.push(session.message.address);
}).triggerAction({
matches:/join/i
})
bot.dialog('broadcast',(session)=>{
channel_address.forEach((address)=>{
bot.send(
new builder.Message(session).address(address).text(session.message.text)
)
})
}).triggerAction({
matches:/^broadcast: .*/
})
Test Step:
Open two emulators connect to your local bot
in both emulators, type "join"
in either emulator, type text like broadcast: hi there

Getting customized message from GCM using Web push notifications

I'm using Web push notifications with Chrome, and they work great. But now I want to deliver a custom message in my notifications. I can have my Service Worker call out to my site to get content, as is done at https://simple-push-demo.appspot.com/—which is fine if I want every recipient to see the same message.
Is there any way to get either the recipient’s registration_id or the message_id that GCM returns? If I could get either of these and include them in the callback to the service, I could customize the response.
Also, any info on when we might be able to include a payload in the call to GCM?
The registration_id and message_id fields aren't exposed, but if the user is previously authenticated to your app, any fetch() to the server from your Service Worker will include credentials (and session information) which you can use to identify them.
If that doesn't work for your case, you can store user/session information in IndexedDB.
Payloads are coming soon—likely Chrome 50 or 51—based on the Web Push protocol. It's a bit of extra overhead and work to configure the (required) encryption.
It's possible, but I wouldn't do it since it's specific to GCM, while other browsers use other services.
You can either create a unique ID for each user (like we're doing in Mercurius) and store it in IndexedDB, or you can use the entire endpoint URL as an ID.
Here's the snippet to get the registration_id:
self.registration.pushManager.getSubscription()
.then(function(subscription) {
if (subscription) {
var endpoint = subscription.endpoint;
var endpointParts = endpoint.split('/');
var gcmRegistrationID = endpointParts[endpointParts.length - 1];
console.log(gcmRegistrationID);
}
});
P.S.: It returns a promise, so make sure your service worker waits for the promise to be resolved.

Resources