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”指示器,然后使用“Split Based On”小部件来检查该指示器,仅在适当时移交。Studio flow 那么一个示例 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 console 中找到您的 Studio 流程 SID Studio Console
  2. 要使用 Conversations,请确保您拥有适用于您的 Functions 的更新版本的 Twilio! Twilio version in Functions
  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 here to configure Conversations Webhook 粘贴为对话的事件后 URL。选择“onConversationAdded”作为此 url 将接收的 Post-Webhook。 Conversations with Function URL

  2. 通过 making sure that the "Handle Inbound Messages with Conversations" Messaging Feature is enabled for your Account here 配置 SMS 对话。 Configure Conversations

  3. Create a Messaging Service for your Autopilot Studio Flow here 将您的 Autopilot 机器人的电话号码与此消息服务相关联。 Associate phone number for your Autopilot bot to this messaging service.

  4. 更新集成设置,以便在消息到达此电话号码时创建新对话 Integration settings so a new conversation is created when a message arrives at this phone number

  5. 创建一个函数以从对话中删除 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。 widgets together 第一个小部件是 RunFunction - removeStudioWebhook Widget 1 - RunFunction - removeStudioWebhook

函数参数包括ConversationSid: {{trigger.message.ConversationSid}}WebhookSid: {{trigger.message.WebhookSid}} 第二个小部件是 RunFunction - addToConversation

Widget 2 - RunFunction - addToConversation

函数参数包括ConversationSid:{{trigger.message.ConversationSid}}WebhookSid: +15555551212 (the number you want to handoff to) 第三个发送消息

send message widget

小部件配置: 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 的帮助下构建自己的聊天机器人。

让我知道这是否有帮助!

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...