【问题标题】:How to make a post using WATSON and Node js?如何使用 WATSON 和 Node js 发帖?
【发布时间】:2021-01-27 10:33:21
【问题描述】:

我想通过与 Watson 聊天发 POST(添加新任务)。

我的 POST 功能非常好用,我在 Postman 上对其进行了测试。我已经创建了 Watson 节点。

这是我在 Node js 中的 POST 的端点:

MainRouter.post('/welcome', (req, res) => {
    TaskPost.postTask(req.body).then(message => {
        return res.json(message);
    }).catch((error) => {
        return res.status(404).json(error);
    });
});

这是我与 Watson 的对话(效果很好):

我也在main.js中包含了这个并更改了密码和url:

const AssistantV2 = require('ibm-watson/assistant/v2');
const { IamAuthenticator } = require('ibm-watson/auth');

const assistant = new AssistantV2({
  authenticator: new IamAuthenticator({ apikey: '<apikey>' }),
  serviceUrl: 'https://api.us-south.assistant.watson.cloud.ibm.com',
  version: '2018-09-19'
});

如何建立这种联系?我必须包括什么?

【问题讨论】:

    标签: node.js post ibm-cloud ibm-watson watson-assistant


    【解决方案1】:

    我会推荐official Node.js SDK for the IBM Watson services。它包括对 Watson Assistant 的支持并且易于使用。

    如果您仍想直接使用 V2 API,请查看how the SDK utilizes the API。作为替代方案,API docs for Watson Assistant have code snippets for Node.js

    基本流程是您进行身份验证,然后建立会话,最后将用户输入 send messages 输入到 Watson Assistant。

    要通过任务到达您的对话节点,用户(或您的代码)需要发送正确的意图和实体,以便从根节点导航到该特定子节点。

    【讨论】:

      猜你喜欢
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 2017-10-30
      • 1970-01-01
      • 2017-02-19
      • 2019-06-20
      • 1970-01-01
      相关资源
      最近更新 更多