简体   繁体   English

在 MS Teams 中安装 bot 时获取所有团队成员

[英]Get all team members when bot is installed in MS Teams

I'm trying to implement Proactive Messaging with a MS Teams bot.我正在尝试使用 MS Teams 机器人实施主动消息传递。 According to the docs i have to get a conversationReference before sending any message to the user so I implemented the onMembersAdded event listener as follows:根据文档,我必须在向用户发送任何消息之前获得conversationReference ,因此我实现了onMembersAdded事件监听器,如下所示:

class TeamsBot extends TeamsActivityHandler {

  constructor() {
    super();

    this.onConversationUpdate(async (context, next) => {
      this.addConversationReference(context);
    });

    this.onMembersAdded(async (context, next) => {
      const membersAdded = context.activity.membersAdded;
      for (let cnt = 0; cnt < membersAdded.length; cnt++) {
        if (membersAdded[cnt].id !== context.activity.recipient.id) {
          this.addConversationReference(context);
        }
      }
      await next();
    });
  }

The problem is that I get notified only of the user that is installing the app even tough my Team (and channel) has plenty of members:问题是我只收到安装应用程序的用户的通知,即使我的团队(和频道)有很多成员:

团队成员

How do I get conversation references for every team member once the bot is installed?安装机器人后,如何获取每个团队成员的对话参考?

It's important to note the difference between the users in a Team and the conversation reference between a user and a bot.请务必注意团队中用户之间的区别以及用户与机器人之间的对话引用。 What the docs are -trying- to say is this:文档 - 试图 - 说的是:

  1. When you bot is added to the team, you can get a list of the users in the team .将机器人添加到团队后,您可以获得团队中的用户列表。
  2. You can use that list of users to look up in your own database the conversation references you need to have already for those users in order to messages.您可以使用该用户列表在您自己的数据库中查找您需要已经为这些用户提供消息的对话参考。 This is because those are references to separate conversations - the bot is in the Team/Channel and has that reference, but the 1-1 chats the bot wants to use to message the users personally are each separate individual chats.这是因为这些是对单独对话的引用 - 机器人在团队/频道中并且具有引用,但是机器人想要用来向用户发送个人消息的 1-1 聊天是每个单独的单独聊天。
  3. If you don't yet have a conversation reference for any/all of those users, you need to get them.如果您还没有任何/所有这些用户的对话参考,则需要获取它们。 That means the user needs to either (a) install the bot themselves or you need to (b) install it for them via the Graph .这意味着用户需要 (a) 自己安装机器人,或者您需要 (b) 通过 Graph 为他们安装机器人。

The docs, imo, don't really explain that well - they assume that by enumerating the list of users you'll be getting -actual- conversation references straight away, and/or that you might be able to initiate the conversation using the bot framework itself.文档,imo,并没有真正解释得那么好 - 他们假设通过枚举用户列表你会立即获得 - 实际 - 对话参考,和/或你可能能够使用机器人发起对话框架本身。

To start conversation in channel - I think you are looking for something like this - see 3 point MessageAllMembers .要在频道中开始对话- 我想你正在寻找这样的东西 - 请参阅 3 点MessageAllMembers Try the sample available - Teams Conversation Bot .试用可用的示例 - Teams Conversation Bot (see for code snippet ) (请参阅代码片段

You can use TeamsInfo.getPagedMembers to get members details in the team您可以使用TeamsInfo.getPagedMembers获取团队成员的详细信息

UPDATE - To start 1:1 conversation - We have this implemented with C# in Company Communicator App template .更新 -开始 1:1 对话- 我们在Company Communicator App 模板中使用 C# 实现了这一点。 Company communicator's code snippet for app installation.公司通讯员的应用程序安装代码片段

To install it first, refer the document shared by @Hilton Giesenow, JavaScript snippet and follow create authProvider .要首先安装它,请参考@Hilton Giesenow 共享的文档, JavaScript 片段并按照创建 authProvider 进行操作

Have a look at this method where we are creating a 1:1 conversation in Company Communicator.看看我们在 Company Communicator 中创建 1:1 对话的方法 ( JavaScript method ref ). JavaScript 方法参考)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM