在 Node-RED 中使用 Watson Assistant V2 时出现类型错误

TypeError using Watson Assistant V2 in Node-RED

我正在尝试为我正在构建的 Telegram 机器人设置 Watson Assistant。我知道我可以使用 watson-assistant-v1(即辅助节点)从 Watson 获得答案,但是,我想使用 watson-assistant-v2 (即助手V2节点)

我不知道我做错了什么。对于 Node-RED 中的 API 键,我使用的是助手的 API 键。但是,当我在调试中向机器人发送消息时,我收到“类型错误:无法读取未定义的 属性 '0'”。

我还漏掉了什么吗?为什么会出现这个错误

在Assistant V1节点中,配置的是Workspace ID。

在Assistant V2节点中,配置的是Assistant ID。

对于这两个输入文本,都应在 msg.payload 中,尽管这可以为空以允许启动对话。所以对于 V2 节点,这是一个应该有效的有效流程

[{"id":"83dbc697.d416c8","type":"inject","z":"f551e981.a6bf78","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":260,"wires":[["d334bd1c.00abb"]]},{"id":"d334bd1c.00abb","type":"watson-assistant-v2","z":"f551e981.a6bf78","name":"","service-endpoint":"https://gateway.watsonplatform.net/assistant/api","assistant_id":"f6f33980-9b6a-4bdf-92dd-e7974a832586","debug":false,"restart":false,"return_context":true,"alternate_intents":false,"multisession":true,"timeout":"","optout-learning":false,"x":410,"y":260,"wires":[["151a548c.d4f44b","6ad0ad7b.b34414"]]},{"id":"151a548c.d4f44b","type":"debug","z":"f551e981.a6bf78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":240,"wires":[]}]

如果要设置对话框,则需要设置上下文。两个节点都可以为您管理上下文,但它们需要上下文的标识符。对于 V2 节点,这是通过将 msg.params.session_id 设置为对您的应用程序有意义的任意值来完成的。例如

[{"id":"b30a8bd4.e5f628","type":"inject","z":"f551e981.a6bf78","name":"","topic":"","payload":"Hello","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":300,"wires":[["4c5c73b5.eef91c"]]},{"id":"4c5c73b5.eef91c","type":"function","z":"f551e981.a6bf78","name":"","func":"msg.params = {\n    \"session_id\" : \"ABC\"\n};\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":360,"wires":[["d334bd1c.00abb"]]},{"id":"d334bd1c.00abb","type":"watson-assistant-v2","z":"f551e981.a6bf78","name":"","service-endpoint":"https://gateway.watsonplatform.net/assistant/api","assistant_id":"f6f33980-9b6a-4bdf-92dd-e7974a832586","debug":false,"restart":false,"return_context":true,"alternate_intents":false,"multisession":true,"timeout":"","optout-learning":false,"x":410,"y":260,"wires":[["151a548c.d4f44b","6ad0ad7b.b34414"]]},{"id":"151a548c.d4f44b","type":"debug","z":"f551e981.a6bf78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":240,"wires":[]}]

然后该节点会为您管理会话和上下文,并在会话到期时更新会话。