Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bot.on('conversationUpdate') repeats itself in webchat #2093

Closed
ajayp opened this issue Jan 23, 2017 · 8 comments
Closed

bot.on('conversationUpdate') repeats itself in webchat #2093

ajayp opened this issue Jan 23, 2017 · 8 comments

Comments

@ajayp
Copy link

ajayp commented Jan 23, 2017

This issue only started occurring in the past few days.

I am using bot.on('conversationUpdate') as a greeting when the webchat iframe first appears. I see my greeting, but if I then type something into webchat and hit enter, the greeting is output again, this only happens when the first conversation is initiated in web chat.

bot.on('conversationUpdate', function (message) {
    var instructions = "Hi there?";
    var reply = new builder.Message()
        .address(message.address)
        .text(instructions);
    bot.send(reply);
});
@ajayp ajayp closed this as completed Jan 23, 2017
@ajayp ajayp reopened this Jan 23, 2017
@ajayp ajayp changed the title bot.on('conversationUpdate' bot.on('conversationUpdate' is now repeating itself in webchat Jan 23, 2017
@ajayp ajayp changed the title bot.on('conversationUpdate' is now repeating itself in webchat bot.on('conversationUpdate' repeats itself in webchat Jan 23, 2017
@ajayp ajayp changed the title bot.on('conversationUpdate' repeats itself in webchat bot.on('conversationUpdate') repeats itself in webchat Jan 23, 2017
@fingejo
Copy link

fingejo commented Jan 23, 2017

I also ran into this problem. The webchat is sending the ConversationUpdate twice. I think the WebChat got updated some days ago (buttons were not working before) and this bug slipped into it with the update... I hope it gets fixed soon.

@dandriscoll
Copy link
Member

dandriscoll commented Jan 24, 2017

Hi @ajayp and @fingejo, the Direct Line channel sends multiple ConversationUpdate messages.

The first ConversationUpdate is sent when the bot is added to the conversation.
After that, each additional ConversationUpdate is sent when a new user joins the conversation.

You can read more about this here: #2065

(You can tell if the member added was a bot by comparing each conversation.MembersAdded[i].Id to activity.Recipient.Id.)

@ajayp
Copy link
Author

ajayp commented Jan 24, 2017

@dandriscoll - Thanks, I was using bot.on('conversationUpdate') to send a custom greeting to the user when the bot is initiated, is there another way to present a custom greeting?

@m-hou
Copy link

m-hou commented Jan 24, 2017

@ajayp, @dandriscoll Would you be able to check if the your bot is one of the members added? If so, do you have any idea on how to do this? Thanks!

@dandriscoll
Copy link
Member

@ajayp and @mushroomcakes, you can tell the difference between your bot and a user by checking the ID field of each element of activity.membersAdded.

{
    "activity": "conversationUpdate",
    "recipient": {
        "id": "MYBOTID" // bot ID here
    },
    "membersAdded": [
        { "id": "MYBOTID" } // this means your bot was added to the conversation, compare with Recipient.Id
        { "id": "user1" } // any other IDs are users
    ]
}

@pcostantini
Copy link
Contributor

If you need to send a message when the bot joins a conversation, you may use the following snippet:

bot.on('conversationUpdate', function (activity) {
    if (activity.membersAdded) {
        activity.membersAdded.forEach((identity) => {
            if (identity.id === activity.address.bot.id) {
                var reply = new builder.activity()
                    .address(activity.address)
                    .text('Hi there!');
                bot.send(reply);
            }
        });
    }
});

@ajayp
Copy link
Author

ajayp commented Jan 25, 2017

@dandriscoll @pcostantini - Thanks for the information, that works.

@Nordes
Copy link

Nordes commented Dec 5, 2017

In node I had a small issue, I had to write builder.Message() instead of builder.activity() (Code from @pcostantini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants