Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Ezequiel Jadib 6b3df2c0b3
Update documentation links to point to new docs (#118)
7 years ago
..
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
764b4f820b
[CSharp] Update screenshots emulator on all samples
7 years ago
1cac51aaa5
Merge pull request #119
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
6b3df2c0b3
Update documentation links to point to new docs (#118)
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
18223aeb4c
[CSharp-GetConversationMembers] Update to Microsoft.Bot.Builder v3.5.0
7 years ago
d3442710e0
[GetConversationMembers] Update path on azuredeploy.json and Deploy button
7 years ago
9220673e8a
Rename GetConversationMembers sample folder
7 years ago
1cac51aaa5
Merge pull request #119
7 years ago

README.md

You have to be logged in to leave a comment. Sign In

Get Conversation Members Bot Sample

A sample bot that retrieves the conversation's members list and detects when it changes.

Deploy to Azure

Prerequisites

The minimum prerequisites to run this sample are:

  • The latest update of Visual Studio 2015. You can download the community version here for free.
  • The Bot Framework Emulator. To install the Bot Framework Emulator, download it from here. Please refer to this documentation article to know more about the Bot Framework Emulator.

Code Highlights

Detecting when members leave or join a group conversation

Your bot often needs to know when the state of the conversation it's in has changed. This may represent the bot being added to the conversation, or a person added or remove from the chat. When these changes happen, your bot will receive a conversationUpdate Activity. In this event, the MembersAdded and MembersRemoved lists will contain the changes to the conversation since the last event. Both properties contain an array of ChannelAccount used to represent an address a user or bot on a communication channel. Check out the GetConversationMembersDialog.cs class handling the ConversationUpdate Activity type.

if (activity.Type == ActivityTypes.ConversationUpdate)
{
    if (activity.MembersAdded != null && activity.MembersAdded.Any())
    {
        string membersAdded = string.Join(
            ", ", 
            activity.MembersAdded.Select(
                newMember => (newMember.Id != activity.Recipient.Id) ? $"{newMember.Name} (Id: {newMember.Id})" 
                                : $"{activity.Recipient.Name} (Id: {activity.Recipient.Id})"));

        await context.PostAsync($"Welcome {membersAdded}");
    }

    if (activity.MembersRemoved != null && activity.MembersRemoved.Any())
    {
        string membersRemoved = string.Join(
            ", ", 
            activity.MembersRemoved.Select(
                removedMember => (removedMember.Id != activity.Recipient.Id) ? $"{removedMember.Name} (Id: {removedMember.Id})" : string.Empty));

        await context.PostAsync($"The following members {membersRemoved} were removed or left the conversation :(");
    }
}

Retrieving the member's list using the Bot Connector's REST API

To enumerate the members of a conversation you can use the GetConversationMembers method from the Bot Connector class. This method returns an array of ChannelAccount objects which are the members of the conversation. Check out the GetConversationMembersDialog.cs class using the GetConversationMembersAsync method to list the Conversation members.

if (activity.Type == ActivityTypes.Message)
{
    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
    {
        var client = scope.Resolve<IConnectorClient>();
        var activityMembers = await client.Conversations.GetConversationMembersAsync(activity.Conversation.Id);

        string members = string.Join(
            "\n ", 
            activityMembers.Select(
                member => (member.Id != activity.Recipient.Id) ? $"* {member.Name} (Id: {member.Id})"
                            : $"* {activity.Recipient.Name} (Id: {activity.Recipient.Id})"));

        await context.PostAsync($"These are the members of this conversation: \n {members}");
    }
}

Outcome

You will see the following in the Bot Framework Emulator when opening and running the sample solution.

Sample Outcome

You will see the following in Slack.

Sample Outcome

On the other hand, you will see the following in Skype.

Sample Outcome

More Information

To get more information about how to get started in Bot Builder for .NET and Activities please review the following resources:

LimitationsThe functionality provided by the Bot Framework Activity can be used across many channels. Moreover, some special channel features can be unleashed using the ChannelData property.

The Bot Framework does its best to support the reuse of your Bot in as many channels as you want. However, due to the very nature of some of these channels, some features are not fully portable.

The features used in this sample are fully supported in the following channels:

  • Skype
  • Slack
  • DirectLine
  • WebChat
  • SMS
  • Kik
  • Email
  • GroupMe

They are also supported, with some limitations, in the following channels:

  • Facebook
  • Microsoft Teams

On the other hand, they are not supported and the sample won't work as expected in the following channel:

  • Telegram
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...