C P Verma
C P Verma

Reputation: 330

welcome message repeated with every message in node js bot

I am using ADFS authentication for my node js bot, which will be integrated with microsoft teams.

my problem is that, when i signed in bot i got a welcome message-

 (session, results, next) => {
      if (session.userData.userName && session.userData.accessToken && session.userData.refreshToken ) {

              builder.Prompts.text(session, "Welcome " + session.userData.userName + "! You are currently logged in into Hotel Bot. Type 'Help' for Bot Help ");

              }

        else {
          session.endConversation("Goodbye.");
        }
      },

it is a part of root dialog.

now after this when i am trying to ask any thing to bot this welcome message repeated with every message. if i comment this prompt then bot stopped responding.

Help me how can i get rid of this repeated message

Thanks

Upvotes: 1

Views: 423

Answers (1)

Gary Liu
Gary Liu

Reputation: 13918

You can try to add a first-run dialog as introduced at https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-handle-conversation-events#add-a-first-run-dialog.

The sample following:

// Add first run dialog
bot.dialog('firstRun', function (session) {    
    session.userData.firstRun = true;
    session.send("Hello...").endDialog();
}).triggerAction({
    onFindAction: function (context, callback) {
        // Only trigger if we've never seen user before
        if (!context.userData.firstRun) {
            // Return a score of 1.1 to ensure the first run dialog wins
            callback(null, 1.1);
        } else {
            callback(null, 0.0);
        }
    }
});

Which leverage a customer variable firstRun to check whether the user has come before. Also you can build your own logic in onFindAction event.

Upvotes: 1

Related Questions