我有一个使用Microsoft Bot Framework开发的bot,并在Debug中正确运行
在Skype上安装后,上传图片后我有这样的链接
https://df-apis.skype.com/v2/attachments/0-eus-d4-7e19a097c62f5fc21dd53eabfa19d85e/views/original
代码很简单,没有skype运行
if ((activity.Attachments != null) && (activity.Attachments.Count > 0))
{
analysisResult = await AnalyzeUrl(activity.Attachments[0].ContentUrl);
}
........
我如何找到我发送的图片?
解决方法:
根据this comment,要获取附件,GET请求应包含bot的JwtToken作为授权标头:
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能够接受图像数据.