gpt4 book ai didi

c# - 将图像上传到 Skype BOT

转载 作者:太空狗 更新时间:2023-10-30 01:32:00 27 4
gpt4 key购买 nike

我有一个使用 Microsoft Bot Framework 开发的机器人,并且在 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 请求应包含机器人的 JwtToken 作为授权 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 能够接受图像数据。

关于c# - 将图像上传到 Skype BOT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38633676/

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