如何解决Twilio 与聊天机器人的对话
我想知道如何将 twilio 对话 api 与自动驾驶聊天机器人一起使用。 所以用户开始和bot聊天,在回答了bot的一些问题后,用户就交给真正的agent继续和他们聊天。 我已经使用 twilio 对话 api 和使用自动驾驶仪的聊天机器人进行了对话。 现在我想知道如何整合它们。
解决方法
这里是 Twilio 开发者布道者。
Twilio Autopilot 没有对话作为支持的频道,只有可编程的聊天。对于大多数这些用例,我建议使用 Autopilot + Studio + Flex——然后你就可以构建任何东西!
以下解决方法来自 Twilio 支持工程师 Adam Taylor:
- 要在 Autopilot 会话结束后创建 Autopilot Studio Flow(即在没有
listen
的情况下命中任务),您可以handoff
到另一个小部件。您可以在 Autopilot 的内存中添加“sendToAgent”指示器,然后使用“Split Based On”小部件来检查该指示器,仅在适当时移交。 那么一个示例 Autopilot Goodbye Task 可能看起来像
{
"actions": [
{
"say": "Great. Please reach out again if you have any questions. I'm sending you to an agent to finish up."
},{
"remember": {
"sendToAgent": true
}
}
]
}
- 在 Studio console 中找到您的 Studio 流程 SID
- 要使用 Conversations,请确保您拥有适用于您的 Functions 的更新版本的 Twilio!
- 那么你的函数的 JS 代码可能看起来像
exports.handler = function(context,event,callback) {
const client = context.getTwilioClient();
const conversationSid = event.ConversationSid;
client.conversations
.conversations(conversationSid)
.webhooks.create({
"configuration.flowSid": "FWxxxxxxxxxxxxxxxx",//update your flow sid here
"configuration.replayAfter": 0,target: "studio"
})
.then(webhook => {
let responseObject = { "conversationSid": conversationSid,"webhookSid": webhook.sid };
callback(null,responseObject);
})
.catch(err => {
callback(error);
});
};
-
将该函数 URL here to configure Conversations Webhook 粘贴为对话的事件后 URL。选择“onConversationAdded”作为此 url 将接收的 Post-Webhook。
-
通过 making sure that the "Handle Inbound Messages with Conversations" Messaging Feature is enabled for your Account here 配置 SMS 对话。
-
Create a Messaging Service for your Autopilot Studio Flow here 将您的 Autopilot 机器人的电话号码与此消息服务相关联。
-
创建一个函数以从对话中删除 Studio。制作一个包含如下代码的函数:
exports.handler = function(context,callback) {
const client = context.getTwilioClient();
const conversationSid = event.ConversationSid;
const webhookSid = event.WebhookSid;
client.conversations
.conversations(conversationSid)
.webhooks(webhookSid)
.remove()
.then(()=> {
let responseObject = { "conversationSid": conversationSid,"webhookSid": webhookSid };
callback(null,responseObject);
})
.catch(err => {
callback(error);
});
};
和另一个功能将参与者添加到对话中
exports.handler = function(context,callback) {
const client = context.getTwilioClient();
const conversationSid = event.ConversationSid;
const handoffTo = event.HandoffTo;
client.conversations
.conversations(conversationSid)
.participants
.create({
'messagingBinding.address': handoffTo,// the phone number or whatsapp address you want to handoff messaging conversation to
'messagingBinding.proxyAddress': '+14156632326' // the phone number attached to your messaging service
})
.then(participant => {
let responseObject = { "participantSid": participant.sid,"conversationSid": conversationSid };
callback(null,responseObject);
})
.catch(err => {
callback(error);
});
};
最后,添加 Studio Widgets 来运行这些函数并完成 Handoff。 第一个小部件是 RunFunction - removeStudioWebhook
函数参数包括ConversationSid: {{trigger.message.ConversationSid}}
和WebhookSid: {{trigger.message.WebhookSid}}
第二个小部件是 RunFunction - addToConversation
函数参数包括ConversationSid:{{trigger.message.ConversationSid}}
和WebhookSid: +15555551212 (the number you want to handoff to)
第三个发送消息
小部件配置:
MessageBody: Customer {{contact.channel.address}} is connected with Agent Adam. (replace with your Agent Name)
和
Send Message To: +15555551213 (replace with the number you want to handoff to)
。
Conversations API 描述说“基本自动回复和聊天机器人功能”作为一些自动化功能“这意味着您可以在 Conversations API 的帮助下构建自己的聊天机器人。
让我知道这是否有帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。