【问题标题】:create context variable from node red to watson conversation创建从节点 red 到 watson 对话的上下文变量
【发布时间】:2018-10-18 12:55:00
【问题描述】:

是否可以向 watson 对话发送变量?

这正是我想要做的。获取 Slack 用户名 将用户名保存为上下文变量 当用户与聊天机器人交谈时,它会说,Hello username,无需用户输入。

我已经阅读了有关 additional_context 的信息,但我似乎无法在任何地方找到如何使用它。这是我在进入 Watson 对话之前处理松弛文本的函数

msg._payload = msg.payload;
msg.payload = msg._payload.event.text; 
msg.additional_context = msg._payload.event.user
node.send(msg); // Send the message long to the next node

如果我查看调试节点,additional_context 键会正确返回用户 ID,但我不知道如何从对话节点内部“获取”它。

提前致谢

【问题讨论】:

  • 您通常不应该在函数节点中使用node.send(msg)return msg 是通常将消息发送到下一个节点的方式。

标签: node-red watson-conversation


【解决方案1】:

添加附加变量意味着在消息请求的"context" 部分中添加变量。向 Watson Assistant (Conversation) API 发送 POST 消息时,添加如下变量:

{ "input": { "text" : "Text the user typed." } "context" : { "username" : "user name", ...+all of the attributes of the context sent in the the last response from WA } }

请记住 - 在对话开始时,可​​以发送一个空的 context 或一个仅包含用户名变量的 context。然而,随着对话的开始,系统在context 字段中发送它的状态,因此在下一个 POST 消息请求中将此上下文发送回很重要(因为系统是无状态的,并且状态保存在上下文中目的)。不过,可以将 node.js 中的其他变量添加到此上下文中。

更多关于 POST 消息的信息在这里:API documentation (23.10.2018)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多