0

我创建了一个带有嵌入式 Watson Virtual Agent 聊天机器人的 html 文件,代码类似如下,WVA 严格使用构建核心功能:

IBMChat.init({ el: 'ibm_chat_root', baseURL: 'https://api.ibm.com/virtualagent/run/api/v1', botID: '', XIBMClientID: '', XIBMClientSecret: '' });

我注意到如果我在预览模式下运行 WVA,并输入“支付账单”,WVA 可以返回两部分响应,首先:

正在访问您的帐户信息...

其次是付款:

您的账户余额为 42.01 美元,到期日为 2017 年 5 月 17 日。你想干什么?(更多选项即将推出!)

但是,如果我在我的 HTML 聊天机器人中输入相同的内容,则响应只会与第一部分一起返回:

正在访问您的帐户信息...

第二部分永远不会出来。

有没有其他人遇到同样的问题?

4

2 回答 2

0

“预览”模式下的版本有一些模拟“动作”处理程序设置。显然,不是每个用户都会欠 42 美元!在 github 上的示例代码中,未设置模拟操作处理程序。这里有关于如何使用处理程序订阅这些操作事件的示例:https ://github.com/watson-virtual-agents/chat-widget/tree/master/examples/basic-actions-example

截至 2017 年 5 月 31 日,您可以使用下面的代码片段涵盖所有内置操作...

const config = { instance: null };

const getUserProfileVariablesMap = {
    'bill_amount': '42.01',
    'payment_due_date': (() => {
        const currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
        return `${currentDate.getMonth() + 1}/${currentDate.getDate()}/${currentDate.getFullYear()}`;
})(),
    'authorized_users': 'Bob Everyman and Jane Doe'
};

const getUserProfileVariables = (data) => {
    const variables = data.message.action.args.variables;
    variables.forEach(v => {
        const value = getUserProfileVariablesMap[v];
        (value) ? config.instance.profile.set(v, value) : config.instance.profile.set(v, '[sample data]');
    });
    config.instance.sendSilently('success');
};

const success = () => config.instance.sendSilently('success');
const agent = () => config.instance.receive('On your own site you would run code to connect to an agent now.');
const accountSettings = () => config.instance.receive('On your own site you would run code to open the Account Settings page now.');

function registerActions(instance) {
    config.instance = instance;
    instance.subscribe('action:getUserProfileVariables', getUserProfileVariables);
    instance.subscribe('action:updateAddress', success);
    instance.subscribe('action:updateUserName', success);
    instance.subscribe('action:updatePhoneNumber', success);
    instance.subscribe('action:updateEmail', success);
    instance.subscribe('action:payBill', success);
    instance.subscribe('action:sendPaymentReceipt', success);
    instance.subscribe('action:agent', agent);
    instance.subscribe('action:openAccountSettingsPage', accountSettings);
};

window.IBMChatActions = {
    registerActions: registerActions
};

// window.IBMChatActions.registerActions(window.IBMChat);
于 2017-05-31T19:09:51.647 回答
0

在管理预览中,您将获得处理来自代理的操作请求的假代码存根。

当调用其中一个操作时,小部件将打印“处理中...”消息,然后调用该操作的所有注册订阅者。"success"由这些注册的订阅者通过静默发送、"failure""cancel"返回服务器来继续对话流。

例如,代理可能会传递"payBill"操作。您可能想调用您的支付网关,确定它是否成功,然后将结果通知代理:

IBMChat.init(/* Settings */);

IBMChat.subscribe('action:payBill', function() {
  var data = {
    amount: IBMChat.profile.get('amount'),
    card: {
      number: IBMChat.profile.get('cc_number'),
      // ... other private card data
    }
  };
  $.post('https://www.myserver.com/payment-gateway', data)
   .done( function() {
     IBMChat.sendSilently('success');
   })
   .fail( function() {
     IBMChat.sendSilently('failure');
   });
});

操作文档 https://github.com/watson-virtual-agents/chat-widget/blob/master/docs/DOCS.md#actions

于 2017-05-31T19:42:46.807 回答