0

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 :/

Naktibalda
  • 13,705
  • 5
  • 35
  • 51

1 Answers1

1

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

Naktibalda
  • 13,705
  • 5
  • 35
  • 51
  • Thanks! This worked, but sometimes the Watson didn't recognizes my "mark as done" in my Inbox Facebook page. There is a way to create a custom "welcome" in dialog? – cleobatista Oct 30 '18 at 22:28
  • Sorry, I have no idea what "mark as done" means and how it relates to welcome event. – Naktibalda Oct 31 '18 at 08:26
  • Don't worry, it's just a event in Facebook Page Inbox. Thanks anyways, you helped me. – cleobatista Oct 31 '18 at 15:24