ibm-watsonwatson-conversationbotkit

How can I trigger a dialog in Watson Conversation?


I need trigger a specific dialog in ibm-watson conversation, but without ask the user to type something (like a intent). I need to use botkit to init a specific dialog. That's is possible? I'm looking for in all possible documentation and links at Google, but not successfully :/


Solution

  • Sending initial empty message triggers welcome event in the dialog.
    To make it do something different, you could set some variable in the context and add condition for that variable to welcome branch in the dialog.

    This is how I implemented it in my bot:

    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 event is specific to webchat/botkit anywhere, you may need to handle different events for different platfoms.
    A similar example of code handling welcome event: https://github.com/watson-developer-cloud/botkit-middleware/#dynamic-workspace
    (I wrote that one too, so it is a bit too similar).

    Dialog example: enter image description here