将图像上传到Skype BOT [英] Upload image to Skype BOT

查看:121
本文介绍了将图像上传到Skype BOT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Microsoft Bot Framework开发的机器人,并且在Debug中可以正常运行

I have a bot develop with Microsoft Bot Framework, and in Debug run correctly

在Skype上安装后,上传图像后,我有一个像这样的链接

After the install on Skype, after the upload the image I have a link like this

https://df-apis.skype.com/v2/attachments/0-eus-d4-7e19a097c62f5fc21dd53eabfa19d85e/views/original

代码非常简单,无需使用Skype即可运行

The code is very simply and run without skype

if ((activity.Attachments != null) && (activity.Attachments.Count > 0))
{

      analysisResult = await AnalyzeUrl(activity.Attachments[0].ContentUrl);

}
........

如何查找发送的图片?

推荐答案

根据此注释,要获取附件,GET请求应包含该机器人的 JwtToken 作为授权标头:

According to this comment, to fetch an attachment, the GET request should contain JwtToken of the bot as authorization header:

var attachment = activity.Attachments?.FirstOrDefault();
if (attachment?.ContentUrl != null)
{
    using (var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl)))
    {
        var token = await (connectorClient.Credentials as MicrosoftAppCredentials).GetTokenAsync();
        var uri = new Uri(attachment.ContentUrl);
        using (var httpClient = new HttpClient())
        {
            if (uri.Host.EndsWith("skype.com") && uri.Scheme == Uri.UriSchemeHttps)
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
            }
            else
            {
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(attachment.ContentType));
            }

            var attachmentData = await httpClient.GetByteArrayAsync(uri);
            analysisResult = await AnalyzeUrl(attachmentData);
        }
    }    
}

这意味着您必须更改AnalyzeUrl以接受图像数据而不是URL.我相信您正在使用的CognitiveServices能够接受图像数据.

That means you have to change the AnalyzeUrl to accept the image data instead of URL. I believe CognitiveServices, you are using, are able to accept the image data.

这篇关于将图像上传到Skype BOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆