我想知道如何将 twilio 对话 api 与自动驾驶聊天机器人一起使用。 所以用户开始和bot聊天,在回答了bot的一些问题后,用户就交给真正的agent继续和他们聊天。 我已经使用 twilio 对话 api 和使用自动驾驶仪的聊天机器人进行了对话。 现在我想知道如何整合它们。
答案 0 :(得分:6)
这里是 Twilio 开发者布道者。
Twilio Autopilot 没有对话作为支持的频道,只有可编程的聊天。对于大多数这些用例,我建议使用 Autopilot + Studio + Flex——然后你就可以构建任何东西!
以下解决方法来自 Twilio 支持工程师 Adam Taylor:
listen
的情况下命中任务),您可以 handoff
到另一个小部件。您可以在 Autopilot 的内存中添加“sendToAgent”指示器,然后使用“Split Based On”小部件来检查该指示器,仅在适当时移交。{
"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
}
}
]
}
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, event, 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, event, 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 的帮助下构建自己的聊天机器人。
让我知道这是否有帮助!