更新频道
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
更新指定频道 的属性。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
ChannelSettings.ReadWrite.All、Group.ReadWrite.All 、Directory.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
ChannelSettings.ReadWrite.Group 、ChannelSettings.ReadWrite.All、Group.ReadWrite.All*、Directory.ReadWrite.All** |
注意:
- 标记为 * 的权限使用 特定于资源的许可。
- 只有向后兼容性才支持使用 ** 标记的权限。 建议更新解决方案,以使用上表中列出的替代权限,并避免今后使用这些权限。
注意:此 API 支持管理员权限。全局管理员和 Microsoft Teams 服务管理员可以访问自己不是其中成员的团队。
HTTP 请求
PATCH /teams/{team-id}/channels/{channel-id}
| 标头 |
值 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,提供 channel 对象的 JSON 表示形式。
注意: 无法更新 membershipType 现有通道的值。
响应
如果成功,此方法返回 204 No Content 响应代码。
示例
示例 1:更新频道
请求
下面是一个请求示例。
PATCH https://graph.microsoft.com/beta/teams/893075dd-2487-4122-925f-022c42e20265/channels/19:561fbdbbfca848a484f0a6f00ce9dbbd@thread.tacv2
响应
下面是一个响应示例。
HTTP/1.1 204 No Content
示例 2:使用审核设置更新频道
请求
以下示例显示更新频道 的审核设置 的请求。 此操作只能由团队所有者执行。
PATCH https://graph.microsoft.com/beta/teams/893075dd-2487-4122-925f-022c42e20265/channels/19:561fbdbbfca848a484f0a6f00ce9dbbd@thread.tacv2
Content-type: application/json
{
"displayName": "UpdateChannelModeration",
"description": "Update channel moderation.",
"moderationSettings": {
"userNewMessageRestriction": "moderators",
"replyRestriction": "everyone",
"allowNewMessageFromBots": true,
"allowNewMessageFromConnectors": true
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var channel = new Channel
{
DisplayName = "UpdateChannelModeration",
Description = "Update channel moderation.",
ModerationSettings = new ChannelModerationSettings
{
UserNewMessageRestriction = UserNewMessageRestriction.Moderators,
ReplyRestriction = ReplyRestriction.Everyone,
AllowNewMessageFromBots = true,
AllowNewMessageFromConnectors = true
}
};
await graphClient.Teams["{team-id}"].Channels["{channel-id}"]
.Request()
.UpdateAsync(channel);
const options = {
authProvider,
};
const client = Client.init(options);
const channel = {
displayName: 'UpdateChannelModeration',
description: 'Update channel moderation.',
moderationSettings: {
userNewMessageRestriction: 'moderators',
replyRestriction: 'everyone',
allowNewMessageFromBots: true,
allowNewMessageFromConnectors: true
}
};
await client.api('/teams/893075dd-2487-4122-925f-022c42e20265/channels/19:561fbdbbfca848a484f0a6f00ce9dbbd@thread.tacv2')
.version('beta')
.update(channel);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/teams/893075dd-2487-4122-925f-022c42e20265/channels/19:561fbdbbfca848a484f0a6f00ce9dbbd@thread.tacv2"]]];
[urlRequest setHTTPMethod:@"PATCH"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphChannel *channel = [[MSGraphChannel alloc] init];
[channel setDisplayName:@"UpdateChannelModeration"];
[channel setDescription:@"Update channel moderation."];
MSGraphChannelModerationSettings *moderationSettings = [[MSGraphChannelModerationSettings alloc] init];
[moderationSettings setUserNewMessageRestriction: [MSGraphUserNewMessageRestriction moderators]];
[moderationSettings setReplyRestriction: [MSGraphReplyRestriction everyone]];
[moderationSettings setAllowNewMessageFromBots: true];
[moderationSettings setAllowNewMessageFromConnectors: true];
[channel setModerationSettings:moderationSettings];
NSError *error;
NSData *channelData = [channel getSerializedDataWithError:&error];
[urlRequest setHTTPBody:channelData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Channel channel = new Channel();
channel.displayName = "UpdateChannelModeration";
channel.description = "Update channel moderation.";
ChannelModerationSettings moderationSettings = new ChannelModerationSettings();
moderationSettings.userNewMessageRestriction = UserNewMessageRestriction.MODERATORS;
moderationSettings.replyRestriction = ReplyRestriction.EVERYONE;
moderationSettings.allowNewMessageFromBots = true;
moderationSettings.allowNewMessageFromConnectors = true;
channel.moderationSettings = moderationSettings;
graphClient.teams("893075dd-2487-4122-925f-022c42e20265").channels("19:561fbdbbfca848a484f0a6f00ce9dbbd@thread.tacv2")
.buildRequest()
.patch(channel);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewChannel()
displayName := "UpdateChannelModeration"
requestBody.SetDisplayName(&displayName)
description := "Update channel moderation."
requestBody.SetDescription(&description)
moderationSettings := msgraphsdk.NewChannelModerationSettings()
requestBody.SetModerationSettings(moderationSettings)
userNewMessageRestriction := "moderators"
moderationSettings.SetUserNewMessageRestriction(&userNewMessageRestriction)
replyRestriction := "everyone"
moderationSettings.SetReplyRestriction(&replyRestriction)
allowNewMessageFromBots := true
moderationSettings.SetAllowNewMessageFromBots(&allowNewMessageFromBots)
allowNewMessageFromConnectors := true
moderationSettings.SetAllowNewMessageFromConnectors(&allowNewMessageFromConnectors)
teamId := "team-id"
channelId := "channel-id"
graphClient.TeamsById(&teamId).ChannelsById(&channelId).Patch(requestBody)
Import-Module Microsoft.Graph.Teams
$params = @{
DisplayName = "UpdateChannelModeration"
Description = "Update channel moderation."
ModerationSettings = @{
UserNewMessageRestriction = "moderators"
ReplyRestriction = "everyone"
AllowNewMessageFromBots = $true
AllowNewMessageFromConnectors = $true
}
}
Update-MgTeamChannel -TeamId $teamId -ChannelId $channelId -BodyParameter $params
响应
下面是一个响应示例。
HTTP/1.1 204 No Content