簡體   English   中英

如何在Watson Conversation中觸發對話框?

[英]How can I trigger a dialog in Watson Conversation?

我需要在ibm-watson對話中觸發特定的對話框,但無需要求用戶輸入某些內容(例如意圖)。 我需要使用botkit來初始化特定對話框。 有可能嗎 我正在Google中尋找所有可能的文檔和鏈接,但未成功:/

發送初始空消息會觸發對話框中的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
(我也寫了那個,所以有點太相似了)。

對話框示例: 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM