【问题标题】:File attachment works in Microsoft Bot Emulator but not in Skype文件附件在 Microsoft Bot Emulator 中有效,但在 Skype 中无效
【发布时间】:2017-11-09 05:50:11
【问题描述】:

我想使用带有 Bot Builder Nuget 包 (3.2.0) 的 Microsoft Bot Framework V3 向 Skype 客户端发送附件 (.txt)

这就是我创建附件的方式:

var replayFile = new Microsoft.Bot.Connector.Attachment();
replayFile.Name = "FileName";
replayFile.Content = "ByteArray";
replayFile.ContentType = "text/plain";

这适用于 Bot Emulator (3.0.0.59),但我在 Windows 10 上的 Skype 客户端 (7.26.0.101) 只能看到消息的文本,而不是附件。

我也在outlook.com 中尝试了Skype 的Web UI,也没有附件。

在本文档中:https://docs.botframework.com/en-us/csharp/builder/sdkreference/attachments.html

上面写着:

如果它是一个文件,那么它只会作为一个链接出现

这是否意味着使用 BotFramework 发送文件的唯一方法是通过链接?不能直接寄吗?但是它是如何使用模拟器工作的呢?

【问题讨论】:

标签: c# botframework skype-bots


【解决方案1】:

我不知道为什么它可以在模拟器中工作,但不支持通过 Content 属性发送字节数组。 但是,根据thisthis cmets,您可以使用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
};

【讨论】:

  • 附带说明,您不必指定上传的图像类型。 "data:image;base64,..." 就像一个魅力。
  • @srichakradhar 如果同样的方法不起作用,我认为你必须在 Stack Overflow 上提出一个单独的问题
猜你喜欢
  • 2023-01-26
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
  • 2019-09-19
  • 2018-10-18
  • 2021-12-23
  • 2013-01-31
  • 1970-01-01
相关资源
最近更新 更多