Twilio与聊天机器人的对话

我想知道如何将 twilio 对话 api 与自动驾驶仪聊天机器人一起使用。所以用户开始和bot聊天,在回答了bot的一些问题后,用户就交给真正的agent继续和他们聊天。我已经使用 twilio 对话 api 和使用自动驾驶仪的聊天机器人进行了对话。现在我想知道如何整合它们。

回答

Twilio 开发人员布道者在这里。

Twilio Autopilot 没有对话作为支持的频道,只有可编程的聊天。对于大多数这些用例,我建议使用 Autopilot + Studio + Flex——然后你可以构建任何东西!

以下解决方法来自 Twilio 支持工程师 Adam Taylor:

  1. 要在 Autopilot 会话结束后创建 Autopilot Studio Flow(即在没有 的情况下命中任务listen),您可以handoff转到另一个小部件。您可以在 Autopilot 的内存中添加“sendToAgent”指示器,然后使用“基于拆分”小部件来检查该指示器,仅在适当时进行移交。
    那么一个示例 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
            }
        }
    ]
}
  1. 在Studio 控制台中查找您的 Studio 流程 SID
  2. 要使用对话,请确保您拥有适用于您的函数的更新版本的 Twilio!
  3. 那么你的函数的 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);
    });
};
  1. 将该函数 URL 粘贴到此处以将 Conversations Webhook 配置为 Conversations的 Post-Event URL。选择“onConversationAdded”作为此 url 将接收的 Post-Webhook。

  2. 通过确保在此处为您的帐户启用“使用对话处理入站消息”消息传递功能来配置 SMS对话。

  3. 在此处为您的 Autopilot Studio Flow 创建消息服务,以将您的 Autopilot 机器人的电话号码与此消息服务相关联。

  4. 更新集成设置,以便在消息到达此电话号码时创建新对话

  5. 创建一个函数以从对话中删除 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 的帮助下构建自己的聊天机器人。

让我知道这是否有帮助!


以上是Twilio与聊天机器人的对话的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>