Forum Discussion

Lakshmi_145's avatar
Lakshmi_145
Brass Contributor
Dec 14, 2022

How to fetch the lists the members of the current conversation using Cloud adapter in Chatbot

Recently we have upgraded the .net version from 3 to 6 and updated bot builder. As 'BotFrameworkAdapter' is obselete , we have used CloudAdapter instead.

In BotFrameworkAdapter, method 'GetConversationMembersAsync' gets the list of members of the current conversation. We need the same replacement of this method in Cloud adapter to return the channel account of the current conversation members .

GetConversationMembersAsync in BotFrameworkAdapter,

  • Lakshmi_145 -You can try with the below code snippets.
    Sample link-Microsoft-Teams-Samples/TeamsConversationBot.cs at 6d681dbf8133921172adf3d6aa03843ab09715ce · OfficeDev/Microsoft-Teams-Samples (github.com)

    var members = await GetPagedMembers(turnContext, cancellationToken);
    
                foreach (var teamMember in members)
                {
                    var proactiveMessage = MessageFactory.Text($"Hello {teamMember.GivenName} {teamMember.Surname}. I'm a Teams conversation bot.");
    
                    var conversationParameters = new ConversationParameters
                    {
                        IsGroup = false,
                        Bot = turnContext.Activity.Recipient,
                        Members = new ChannelAccount[] { teamMember },
                        TenantId = turnContext.Activity.Conversation.TenantId,
                    };
    
                    await ((CloudAdapter)turnContext.Adapter).CreateConversationAsync(
                        credentials.MicrosoftAppId,
                        teamsChannelId,
                        serviceUrl,
                        credentials.OAuthScope,
                        conversationParameters,
                        async (t1, c1) =>
                        {
                            conversationReference = t1.Activity.GetConversationReference();
                            await ((CloudAdapter)turnContext.Adapter).ContinueConversationAsync(
                                _appId,
                                conversationReference,
                                async (t2, c2) =>
                                {
                                    await t2.SendActivityAsync(proactiveMessage, c2);
                                },
                                cancellationToken);
                        },
                        cancellationToken);
                }
    
                await turnContext.SendActivityAsync(MessageFactory.Text("All messages have been sent."), cancellationToken);

     

Resources