我正致力于创建一个包含IBM Watson Conversation Chat Bot实例的简单网页。我有以下Node.js代码,它们与IBM云交互并接收Chat Bot的对话框作为控制台输出,并允许用户响应。
var ConversationV1 = require('watson-developer-cloud/conversation/v1');
// Set up Conversation service wrapper.
var conversation = new ConversationV1({
username: 'Security Credentials', // replace with service username
password: 'Security Credentials', // replace with service password
version_date: '2018-02-05'
});
var workspace_id = 'Security Credentials'; // replace with workspace ID
// Start conversation with empty message.
conversation.message({
workspace_id: workspace_id
}, processResponse);
// Process the conversation response.
function processResponse(err, response) {
if (err) {
console.error(err); // something went wrong
return;
}
// If an intent was detected, log it out to the console.
if (response.intents.length > 0) {
console.log('Detected intent: #' + response.intents[0].intent);
}
// Display the output from dialog, if any.
if (response.output.text.length != 0) {
console.log(response.output.text[0]);
}
// Prompt for the next round of input.
var newMessageFromUser = prompt('>> ');
// Send back the context to maintain state.
conversation.message({
workspace_id: workspace_id,
input: { text: newMessageFromUser },
context : response.context,
}, processResponse)
}
我对网络开发不是很熟悉,我也不确定如何创建一个与Node.js交互的html页面。理想情况下,我希望页面能够显示聊天机器人的窗口,并在页面上显示一些图像。
我尝试过使用像Browserify这样的东西, 但我不确定下一步该去哪里。