1

How to implement a welcome activity when the bot first starts - NLP is from Google Dialogflow.

I have designed the chatbot -intent, entities and NLP from Google Dialogflow and I have integrated successfully with the botframework webchat in a html file on referring this url.

The bot design and also the bot response is good to go. My most expected is am not getting the Bot response first here.

The welcome intent from Google Dialogflow has to get trigger from the following code as per the link given above.

But I am unable to get the bot trigger first here.

How to trigger the event of Google Dialogflow from the code.

I am expecting same like this

Note: Also referred this url

James Z
  • 12,209
  • 10
  • 24
  • 44
IMRANKHAN K
  • 99
  • 1
  • 3
  • Looks like you received a good answer. DialogFlow documentation for how to add an event from the webhook is here: https://cloud.google.com/dialogflow/docs/events-custom . – KateYoak Aug 27 '19 at 18:27

1 Answers1

1

When a user joins WebChat, a conversation update activity will be sent to the bot. Once the activity is received, you can check if a member was added and send the welcome message accordingly.

If you are using the Activity Handler that was released in v4.3, you can simply add an onMembersAdded handler and send the welcome message from there.

class Bot extends ActivityHandler{

    constructor() {
        super();

        this.onMembersAdded(async (context, next) => {
            const { membersAdded } = context.activity;

            for (let member of membersAdded) {
                if (member.id !== context.activity.recipient.id) {
                   await context.sendActivity("Welcome Message!");
                }
            }
            await next();
        });

        ...
    }
}

If you are not using the activity handler, in the bot's onTurn method, you can check if the incoming activity handler is a conversation update and if a member has been added.

async onTurn(turnContext) {
    if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
        if (turnContext.activity.membersAdded && turnContext.activity.membersAdded.length > 0) {
            for (let member of turnContext.activity.membersAdded) {
                if (member.id !== turnContext.activity.recipient.id) {
                     await turnContext.sendActivity("Welcome Message!");
                }
            }
        }
    } ...
}

For more details on sending welcome messages, please take a look at this sample.

Hope this helps!

tdurnford
  • 3,632
  • 2
  • 6
  • 15
  • Hey, you mention ActivityHandler. I googled and did find any references. Can you provide a link? – KateYoak Aug 19 '19 at 21:19
  • 1
    Documentation is a bit sparse https://github.com/microsoft/botbuilder-js/blob/master/libraries/botbuilder-core/src/activityHandler.ts – tdurnford Aug 19 '19 at 21:38
  • Ah! You are calling dialogflow out of MS Botkit just for NLP? – KateYoak Aug 27 '19 at 18:20
  • 1
    I believe that is what @MRANKHAN K is doing, yes. – tdurnford Aug 27 '19 at 18:33
  • Yes @tdurnford.. Correct, But however I have handled everything in the html page for trigger event from dialogflow. That is instead calling to event I have called intent training phrase text of dialogflow from Botframework.. Also I have hidden the text message which we trigger to bot in UI.. Finally itseems like we have trigger event from botframework to Dialogflow NLP. – IMRANKHAN K Aug 29 '19 at 03:18