Microsoft Bot Framework: showing a welcome message at the start of a new conversation

Recently I’ve worked on some projects related to Bot Framework and enjoyed the functionalities which permit to automate actions in response to user interactions.

It is important to provide the user with a great experience: one “nice touch” can be achieved by providing a welcome message at the beginning of a new conversation.

The first solution I tried was triggering the welcome message in the ConversationUpdate activity:

When I ran this, the message was presented twice in the Bot Framework Emulator:

After some investigation, I discovered that the ConversationUpdate activity is triggered both when the connection to the Bot is established and when a new user joins the conversation.

As explained on GitHub, the correct way to handle this case is by showing the welcome message only when a new user is added:

Using this approach the welcome message is displayed properly:

Happy coding!

6 thoughts on “Microsoft Bot Framework: showing a welcome message at the start of a new conversation”

  1. Thanks, this solved a problem I’ve been working on for 2 days! I am new to Bot programming but have an idea for a bot I am trying to build.

  2. i try to use this sample in my bot :

    else if (message.Type == ActivityTypes.ConversationUpdate)
    {
    // Handle conversation state changes, like members being added and removed
    // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
    // Not available in all channels

    // Note: Add introduction here:
    IConversationUpdateActivity update = message;
    var client = new ConnectorClient(new Uri(message.ServiceUrl), new MicrosoftAppCredentials());
    if (update.MembersAdded != null && update.MembersAdded.Any())
    {
    foreach (var newMember in update.MembersAdded)
    {
    if (newMember.Id != message.Recipient.Id)
    {
    var reply = message.CreateReply();
    reply.Text = $”Welcome {newMember.Name}!”;
    client.Conversations.ReplyToActivityAsync(reply);
    }
    }
    }
    }

    when a new user start the conversation the bot can’t catch the username of the bot

  3. Thanks for this information!
    I am facing a problem regarding state management. How to remove/delete users conversion from state.
    Please help in this regard.

Leave a Reply

Your email address will not be published. Required fields are marked *