首页 > 解决方案 > 如何在 Watson Conversation 中触发对话?

问题描述

我需要在 ibm-watson 对话中触发特定对话,但不要求用户输入某些内容(如意图)。我需要使用 botkit 来启动一个特定的对话框。那有可能吗?我正在谷歌寻找所有可能的文档和链接,但没有成功:/

标签: ibm-watsonwatson-conversationbotkit

解决方案


发送初始空消息会触发welcome对话框中的事件。
为了让它做一些不同的事情,你可以在上下文中设置一些变量,并为该变量添加条件到对话框中的欢迎分支。

这就是我在我的机器人中实现它的方式:

function handleHelloEvent(bot, message) {
    message.type = 'welcome';
    const contextDelta: any = {};

    if (message.intent) {
        contextDelta.initialIntent = message.intent;
    }
    //more fields here

    watsonMiddleware.sendToWatsonAsync(bot, message, contextDelta).catch((error) => {
        message.watsonError = error;
    }).then(() => {
        //this is the same function which handles message_received events
        return handleWatsonResponse(bot, message);
    });
}

function handleWatsonResponse(bot, message) {
    bot.reply(message, message.watsonData.output.text.join('\n'));
}

controller.on('hello', handleHelloEvent);
controller.on('message_received', handleWatsonResponse);

hello事件特定于任何地方的 webchat/botkit,您可能需要为不同的平台处理不同的事件。
代码处理欢迎事件的类似示例:https
://github.com/watson-developer-cloud/botkit-middleware/#dynamic-workspace (我也写了一个,所以有点太相似了)。

对话框示例: 在此处输入图像描述


推荐阅读