我正在使用node js sdk 4在Microsoft团队中开发一个机器人。我已经在团队中安装了该应用程序,我想使用我的机器人来了解该团队中的成员列表。我已经尝试过此代码(如下),但仅获取一个成员(我自己)的数据。
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;
};
答案 0 :(得分:0)
请您为团队争取名册。这是代码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(); }); } }
答案 1 :(得分:0)
我也发生了同样的事情。原因是我正在向机器人发送直接消息。 该代码应在Teams通道上下文中使用。这样,该漫游器就可以访问属于该渠道的所有团队成员。
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);
...