问题
I'm looking to find a way to add a bot to a team that this bot just created.
- Was able to create a group via MS Graph by the bot JS-SDK
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}
. Found them via /users
search
- 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:
graphClient.api(`/groups/${group-id}/team`).put({});
- and 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?
回答1:
So remember that a Bot is not a regular user, it's an App. 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.
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.
来源:https://stackoverflow.com/questions/59796925/add-bot-ms-botbuilder-to-the-ms-teams-team-channel-programmatically