0
votes

I am developing a bot in microsoft teams using node js sdk 4. I have installed the app in a team and i want to know the list of members in that team using my bot. I have tried this code (below) but only getting data of only one member(myself) .

async getAllMembers(context) {
        var continuationToken;
        var members = [];
        do {

            var pagedMembers = await TeamsInfo.getPagedMembers(context,10, continuationToken);   //return my data only
            continuationToken = pagedMembers.continuationToken;
            members.push(...pagedMembers.members);
        } while (continuationToken !== undefined);
        for (var i = 0; i < members.length; i++) {
            console.log(members[i]);
        }
        return members;
    };
2
I'm having the same problem. Did you figure out the solution?da Rocha Pires

2 Answers

0
votes

Could you please try getting roster for the Team. Here is the code sample:

export class MyBot extends TeamsActivityHandler {
    constructor() {
        super();

        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
        this.onMessage(async (turnContext, next) => {
            const teamDetails = await TeamsInfo.getTeamDetails(turnContext);
            if (teamDetails) {
                await turnContext.sendActivity(`The group ID is: ${teamDetails.aadGroupId}`);
            } else {
                await turnContext.sendActivity('This message did not come from a channel in a team.');
            }

            // By calling next() you ensure that the next BotHandler is run.
            await next();
        });
    }
}
0
votes

The same was happening to me. The reason was that I was sending a direct message to the bot. The code is supposed to be used inside a Teams channel context. That way, the bot has access to all the team members that belong to that channel.

    private async Task MessageAllMembersAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        var teamsChannelId = turnContext.Activity.TeamsGetChannelId();
        var serviceUrl = turnContext.Activity.ServiceUrl;
        var credentials = new MicrosoftAppCredentials(_appId, _appPassword);
        ConversationReference conversationReference = null;

        var members = await GetPagedMembers(turnContext, cancellationToken);
        ...