文件附件工作在微软Bot模拟器,但不是在Skype
本文关键字:Skype 模拟器 Bot 工作 微软 文件 | 更新日期: 2023-09-27 18:04:10
我想发送一个附件(.txt)到Skype客户端使用微软Bot框架V3与Bot Builder Nuget包(3.2.0)
我是这样创建附件的:
var replayFile = new Microsoft.Bot.Connector.Attachment();
replayFile.Name = "FileName";
replayFile.Content = "ByteArray";
replayFile.ContentType = "text/plain";
这适用于Bot模拟器(3.0.0.59),但我的skype客户端(7.26.0.101)在Windows 10上只看到消息的文本,而不是附件。
我也试过Skype的Web UI在outlook.com,也没有附件。
本文档:https://docs.botframework.com/en-us/csharp/builder/sdkreference/attachments.html
它说:
如果它是一个文件,那么它将直接显示为一个链接
这是否意味着使用BotFramework发送文件的唯一方法是通过链接?不能直接发送吗?但是它是如何使用模拟器工作的呢?
我不知道为什么它在模拟器中工作,但是不支持通过Content属性发送字节数组。但是,根据这个和这个注释,您可以使用base64编码的数据URI发送附件:
byte[] data = GetAttachmentData();
var contentType = "text/plain";
var replayFile = new Microsoft.Bot.Connector.Attachment
{
Name = "FileName.txt",
ContentUrl = $"data:{contentType};base64,{Convert.ToBase64String(data)}",
ContentType = contentType
};