gpt4 book ai didi

microsoft-graph-api - 使用 Microsoft Graph API C# 将聊天消息发送到 Microsoft Teams channel

转载 作者:行者123 更新时间:2023-12-04 04:16:57 28 4
gpt4 key购买 nike

我的目标很简单。我想使用图形 API 将自动聊天消息发送到 MS Teams channel 。

这似乎是图形 API 的测试版功能,仅在 Microsoft.Graph.Beta 中可用。

我已经阅读了文档并且一直在尝试遵循这个例子:

https://learn.microsoft.com/en-us/graph/api/channel-post-messages ,我在我的 Azure 门户中正确设置了所有权限。我一直收到“未知错误”我已经尝试过:

var graphServiceClient = MicrosoftGraphService.GetGraphServiceClient();

var chatMessage = new ChatMessage
{
Subject = null,

Body = new ItemBody
{
ContentType = BodyType.Text,
Content = messageText
}

};

var response = await graphServiceClient.Teams["77f9c17f-54ca-4275-82d4-fff7esdacda1"].Channels["2007765c-8185-4cc7-8064-fb1b10f27e6b"].Messages.Request()
.AddAsync(chatMessage);

我也试过看看我能不能从团队那里得到什么:

var teams = await graphServiceClient.Teams["77f9c17f-54ca-4275-2sed4-ffsde59acda1"].Request().GetAsync();

再次,我得到的是未知错误,我之前使用过 GRAPH API 来做一些事情,比如在组织中获取用户,所以我知道类型设置是正确的。

世界上某个地方的互联网上有没有人让这个工作?!因为它让我发疯

最佳答案

同样的问题:

用户或组一切正常,但我无法从 Teams 获得任何信息(未知错误)

所有ID都正确并经过检查

这是我为应用程序设置的授权:

  • 阅读所有用户的团队合作事件提要
  • 阅读所有群组
  • 向任何用户发送团队合作事件
  • 获取所有团队的列表

这是我的代码(基于 microsoft daemon app scenario )

访问 token 没问题

var graphClient = new GraphServiceClient(
"https://graph.microsoft.com/beta",
new DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
}));

var chatMessage = new ChatMessage
{
Subject = "Message de test",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Contenu de test"
}
};

await graphClient.Teams["218a4b1d-84d5-48a2-97a0-023e4e4c3e85"].Channels["19:adbf8ddf37a049aa9f63a0f8ee0e8054@thread.tacv2"].Messages
.Request()
.AddAsync(chatMessage);

结果:

Token acquired
Code: UnknownError
Inner error:
AdditionalData:
request-id: e2e433d8-cedd-4401-b5b2-6f34cf5611cf
date: 2020-03-30T12:14:15
ClientRequestId: e2e433d8-cedd-4401-b5b2-6f34cf5611cf

编辑(2020-04-01):

暂无解决办法:页底评论有答案"Create chatMessage in a channel" in ms doc (反馈部分)

目前应用程序似乎无法获得发送chatMessages的权限。

RamjotSingh commented on Jun 11, 2019 Contributor

@pythonpsycho1337 - As the permission table above notes, Application only context is not supported on this API at the moment.


RamjotSingh commented on Dec 16, 2019 Contributor

Supporting application permissions is something we plan to do but we do not have a date yet.


RamjotSingh commented a day ago Contributor

We will share on Microsoft Graph Blog once we have application permissions for this API. Since the original question for this issue was answered. Closing it.

关于microsoft-graph-api - 使用 Microsoft Graph API C# 将聊天消息发送到 Microsoft Teams channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60561348/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com