node.js - 从后端设置 Watson Conversation 的上下文变量。

标签 node.js ibm-watson chatbot watson watson-conversation

我在从 Node 应用程序向 Watson Conversation 发送上下文变量时遇到问题。

我正在尝试实现以下内容,

  1. 用户输入电话号码。
  2. 提取与该电话号码对应的数据并将其显示在下一个 Node 中。

例如:

When the user enters his phone number, the next node should greet the user with their name; which is obtained from the database.

Node 1: Enter your phone number?
Node 2: <user enters the phone number>
fetches the data corresponding to the phone number from the database and passes it to Watson as context variable
Node 3: Hey, $user_name. How are you?
Node 4: <waits for user input>

我面临的问题是,

Node 应用程序仅在需要用户输入时才发回上下文变量,因此,在此之前,Watson Conversation 不会获取新的上下文变量集。因此,这里它仅通过 Node 3 发送新的上下文变量集,但我想要的是,我希望 Watson Conversation 在我输入电话号码后就拥有新的上下文变量集。

也就是说,当用户在 Node 2 中输入他的 phone_number 后,Node 应用程序会立即获取与其对应的 user_name 并将该值设置为 Node 应用程序中的上下文变量,并将其发送回 Watson Conversation。因此,在 Node 3 打印 Watson Conversation 之前,有一组新的上下文变量。 但实际发生的情况是,当用户输入电话号码时,我在 Node 应用程序上获取与其相对应的user_name,但 Watson Conversation 上的上下文变量NOT,因此现在当 Watson 响应时,$user_name 的值仍然是未定义,因此它以空字符串形式返回。

谁能帮我解决这个问题吗?提前致谢。

最佳答案

Node app only sends the context variable back only when it wants user input, so, until that point, the Watson Conversation doesn't get the new set of the context variable.

这是预期的行为。 Watson Assistant 是无状态的。在您将上下文对象发送回它之前,它不知道上下文变量或您在对话中的位置。

所以你必须将值发送给它。如果是,那么您需要发布示例 JSON 请求/响应,以便更好地了解正在发生的情况。

<小时/>

另一种方法是云函数。您可以在 Watson Assistant 中创建一个云函数来执行查找,将其传回对话中,然后您的 Node 应用程序获取上下文响应对象中的值。

云函数对时间敏感。因此,如果有任何可能的延迟,那么 Node 应用程序中的代码就会发生延迟。

关于node.js - 从后端设置 Watson Conversation 的上下文变量。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49754857/

相关文章:

python - Watson Discovery "Access is denied due to invalid credentials"- Python

python - 安装line-in包时出错: NodeJS

google-cloud-platform - Dialogflow webhook 设置参数值

azure - 在 Microsoft Virtual Assistant 和 Skills 之间传递数据

javascript - 如何使用异步等待作为模块方法

javascript - 使用 Mongoose 模式导入 CSV

node.js - 了解 redis-store pub-sub 中的 "dispatch" channel

node.js - 一个迁移文件中的多个迁移语句

node.js - 无法使用 CF 定位组织

amazon-web-services - AWS Lex - 默认插槽类型没有限制