简体   繁体   English

以编程方式将机器人 (ms-botbuilder) 添加到 MS Teams 团队/频道

[英]Add bot (ms-botbuilder) to the MS Teams Team/Channel programmatically

I'm looking to find a way to add a bot to a team that this bot just created.我正在寻找一种方法将机器人添加到该机器人刚刚创建的团队中。

  1. Was able to create a group via MS Graph by the bot JS-SDK能够通过机器人 JS-SDK 通过 MS Graph 创建一个组
graphClient.api("/groups").post({
            displayName: "Some Name",
            mailNickname: "Name without Spaces",
            description: "Some Description",
            visibility: "Private",
            groupTypes: ["Unified"],
            mailEnabled: true,
            securityEnabled: false,
            "members@odata.bind": members, // array of url strings of members
            "owners@odata.bind": owners,
        });

members and owners arrays of strings representing users: https://graph.microsoft.com/v1.0/users/{user-id} .代表用户的membersowners字符串数组: https://graph.microsoft.com/v1.0/users/{user-id} Found them via /users search通过/users搜索找到它们

  1. then added a team to this group (source: https://docs.microsoft.com/en-us/graph/api/team-put-teams?view=graph-rest-beta&tabs=javascript ) like that:然后向该组添加了一个团队(来源: https : //docs.microsoft.com/en-us/graph/api/team-put-teams?view=graph-rest-beta&tabs=javascript ),如下所示:
    graphClient.api(`/groups/${group-id}/team`).put({});
  2. and channel - graphClient.api(`/teams/${group-id}/channels`).post(channel);和频道 - graphClient.api(`/teams/${group-id}/channels`).post(channel);

Couldn't find a way to add the bot to the team or channel that was just created.找不到将机器人添加到刚刚创建的团队或频道的方法。 Maybe there is a way to locate it guid or some kind of app-id and add it to the group?也许有一种方法可以找到它的 guid 或某种 app-id 并将其添加到组中?

So remember that a Bot is not a regular user, it's an App.所以请记住,Bot 不是普通用户,它是一个应用程序。 As a result, to add it to a Team, you would use the Add app to team operation against the Graph.因此,要将其添加到团队,您将使用“ 添加应用程序到团队”操作对图表进行操作。 To do so, you need to use the app Id from List the published apps from the Microsoft Teams app catalog .为此,您需要使用列出 Microsoft Teams 应用程序目录中已发布的应用程序中的应用程序 ID。

Once you do this, your bot is part of the entire Team, and can be accessed from any Channel.一旦你这样做了,你的机器人就是整个团队的一部分,可以从任何渠道访问。 As a result, you don't need to also add your bot to a Channel per se after installing it to the Team (you can see this because the only way to remove the bot from a "channel" is by removing it from the App tab for the entire Team).因此,在将机器人安装到团队后,您不需要将其本身也添加到频道(您可以看到这一点,因为从“频道”中删除机器人的唯一方法是将其从应用程序中删除整个团队的选项卡)。 It's kind of like a user in this regard - adding the user to the Team gives them access to all channels.这有点像在这方面的用户 - 将用户添加到团队可以让他们访问所有频道。 However, if your app includes a tab as well, the tab can be added automatically to an individual channel - see add tab to channel .但是,如果您的应用程序也包含一个选项卡,则该选项卡可以自动添加到单个频道 - 请参阅将选项卡添加到频道

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

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