在网站内导入沃森对话聊天

Importing inside a website a watson conversation chat

我正在实施一个 watson 对话聊天,现在我想知道如何将这个聊天导入现有网站?

有什么帮助吗?

您可以在 Java 中查看一个示例 conversation-simple in Nodejs and Conversation-with-discovery

此存储库来自 IBM Developers

此示例展示了一个如何调用 API 的示例,并且有一些 前端 用于展示 对话流程 Watson 明白,所有你需要知道如何使用 Watson,context variables, intents, entities

在这种情况下,您使用 Service Credentials 和 Workspace_id 从您在 IBM Bluemix 中创建的对话中调用对话 API:

用Java脚本语言(nodejs)调用调用结果的例子:

var conversation = new Conversation({
  // If unspecified here, the CONVERSATION_USERNAME and CONVERSATION_PASSWORD env properties will be checked
  // username: '<username>', paste the Service Credentials here or paste in env archive
  // password: '<password>',
  url: 'https://gateway.watsonplatform.net/conversation/api',
  version_date: '2016-10-21',
  version: 'v1'
});

// Endpoint to be call from the client side
app.post('/api/message', function(req, res) {
  var workspace = process.env.WORKSPACE_ID || '<workspace-id>'; //workspace id can be check inside Conversation Service, click View details
  if (!workspace || workspace === '<workspace-id>') {
    return res.json({
      'output': {
        'text': 'The app has not been configured with a <b>WORKSPACE_ID</b> environment variable.' //error if workspace_id is not set
      }
    });
  }
  var payload = {
    workspace_id: workspace,
    context: req.body.context || {},
    input: req.body.input || {}
  };

  // Send the input to the conversation service
  conversation.message(payload, function(err, data) {
    if (err) {
      return res.status(err.code || 500).json(err);
    }
    return res.json(updateMessage(payload, data));
  });
});

您可以使用其他语言(Python、curl、Java),请参阅 this 文档。

检查示例 here 运行。