简体   繁体   English

通过剪贴板添加时无法访问 Microsoft Teams Activity 中的图像

[英]Cannot access images from Microsoft Teams Activity when added by clipboard

I am working on a bot which receives messages from Teams via the Botframework and sends them to another application.我正在开发一个机器人,它通过 Botframework 从 Teams 接收消息并将它们发送到另一个应用程序。 I'm using .NET Core.我正在使用 .NET 核心。

So far everything works fine, I can move texts, emojis, files etc. But I have a problem with images in the clipboard.到目前为止一切正常,我可以移动文本、表情符号、文件等。但是剪贴板中的图像有问题。

When sending a normal file, I can access it with the Attachment.Content["downloadUrl"] of the activity which I receive from the Botframework.发送普通文件时,我可以使用从 Botframework 收到的活动的 Attachment.Content["downloadUrl"] 访问它。

But when I insert images from the clipboard, it is stored in another way, with the Activity I get two attachments with different urls (one for layout and one for the image resource, I suppose?), like the image below, but when trying to GET the image, I receive an 401 Unauthorized.但是当我从剪贴板插入图像时,它以另一种方式存储,通过 Activity 我得到两个具有不同 url 的附件(一个用于布局,一个用于图像资源,我想?),如下图所示,但是在尝试时要获取图像,我会收到 401 Unauthorized。

Is there a way to access these images pasted from the clipboard, or are these probably only visible/accessible from inside Microsoft Teams?有没有办法访问从剪贴板粘贴的这些图像,或者这些图像可能只能从 Microsoft Teams 内部看到/访问?

Help me, Obi-Wan Kenobi.帮帮我,欧比旺·克诺比。 You're my only hope.你是我唯一的希望。

Thank you for your time!感谢您的时间!

EDIT: Thank you for your warm welcome!编辑:感谢您的热烈欢迎!

I am using the OnMessageActivityAsync overload from here:我在这里使用 OnMessageActivityAsync 重载:
https://docs.microsoft.com/en-us/microsoftteams/platform/bots/bot-basics?tabs=csharp#bot-logic https://docs.microsoft.com/en-us/microsoftteams/platform/bots/bot-basics?tabs=csharp#bot-logic

    public class BotActivityHandler : Microsoft.Bot.Builder.Teams.TeamsActivityHandler
    {
        [...]

        protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            // it's either this url or the one parsed from the html, but both receive a 401 with a GET request like below or with Postman
            var imageUrl = turnContext.Activity.Attachments.Where(x => !x.ContentUrl.IsNullOrEmpty()).ToList().First().ContentUrl;

            var response = await myHttpClient.GetAsync(imageUrl);
            var img = await response.Content.ReadAsStreamAsync();
        }
[...]

The turnContext includes an Activity with two Attachments: One has Content like turnContext 包括一个带有两个附件的活动:一个具有类似的内容

<div><div>\n<div><span><img
src=\"https://eu-api.asm.skype.com/v1/objects/[...]/views/imgo\"
 width=\"247\" id=\"[...]\" itemscope=\"\" itemtype=\"http://schema.skype.com/AMSImage\"\"></span>\n\n</div>\n\n\n</div>\n</div>

And the other one a ContentUrl like另一个像 ContentUrl

"https://smba.trafficmanager.net/emea/v3/attachments/[...]/views/original"

从 Microsoft Teams 收到的活动

Answered in https://github.com/MicrosoftDocs/msteams-docs/issues/1561https://github.com/MicrosoftDocs/msteams-docs/issues/1561中回答

One can use the MicrosoftAppCredentials to receive a JWT Token to access the images.可以使用 MicrosoftAppCredentials 接收 JWT 令牌来访问图像。

var token = await new MicrosoftAppCredentials("appId", "password").GetTokenAsync();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

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

相关问题 Activity.Text如何编码Microsoft团队? - How is Activity.Text encoded Microsoft Teams? Gif图像无法在Microsoft Teams中播放 - Gif images don't play in Microsoft Teams 如何突出显示从外部源向 Microsoft Teams 活动源发送通知的消息 - How to highlight the message for which a notification is sent to Microsoft Teams activity feed from external source 通过Microsoft团队机器人团队用户配置文件图像访问 - Teams user profile image access via Microsoft teams bot 如何将文字与剪贴板中的图像(如Microsoft Word)一起粘贴到C#中? - How to Paste text with images from clipboard like Microsoft Word do C#? Microsoft Bot在Azure中使用但在团队中无法使用 - Microsoft Bot in Azure but not working in Teams when used 从Microsoft Teams机器人发送HTML附件 - Sending an HTML attachment from a Microsoft Teams bot 从 Controller 向 Microsoft Teams 发送消息 - Send message from Controller to Microsoft Teams 以生成 Microsoft Teams 可以使用的格式的方式写入 C# 中的剪贴板 - Writing to the clipboard in C# in a way that generates formatting that Microsoft Teams can use 如何使用 C# 访问微软团队,使用 C# 执行团队命令并获取结果数据 - How to access microsoft teams with C#, execute teams commands and get result data with C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM