首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与聊天机器人进行Twilio对话

与聊天机器人进行Twilio对话
EN

Stack Overflow用户
提问于 2021-03-17 19:31:58
回答 1查看 503关注 0票数 1

我想知道如何在自动驾驶聊天机器人中使用twilio对话api。因此,用户开始与bot聊天,在回答了bot的一些问题后,用户被移交给真实的agent,并继续与他们聊天。我已经使用twilio对话api和使用自动驾驶的聊天机器人进行了对话。现在我想知道如何集成它们。

EN

回答 1

Stack Overflow用户

发布于 2021-03-19 00:46:33

Twilio开发者的布道者在这里。

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

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

  1. 创建自动驾驶工作室流程一旦自动驾驶会话结束(即,在没有listen的情况下命中任务),您可以handoff到另一个小工具。您可以在自动驾驶的内存中添加一个"sendToAgent“指示器,然后使用"Split Based On”小工具检查此指示器,只在适当的时候关闭。

那么Autopilot告别任务示例可能如下所示

代码语言:javascript
复制
{
    "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

中查找您的工作室flow SID

  1. 要使用对话,请确保您的函数具有更新版本的Twilio!

  1. ,则函数的JS代码可能类似于

代码语言:javascript
复制
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。

  1. 通过making sure that the "Handle Inbound Messages with Conversations" Messaging Feature is enabled for your Account here为短信配置会话。

  1. Create a Messaging Service for your Autopilot Studio Flow here可将自动驾驶机器人的电话号码与此信息服务相关联。

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

  1. 创建一个函数以将Studio从会话中删除。创建一个包含如下代码的函数:

代码语言:javascript
复制
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);
    });
};

和另一个将参与者添加到会话中的函数

代码语言:javascript
复制
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小部件来运行这些函数并完成交接。

第一个小部件是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的帮助下构建自己的聊天机器人。”

如果这有帮助,请让我知道!

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66672232

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档