Asp.net web api 如何使用Microsoft Bot Framework将文件附加到邮件?

Asp.net web api 如何使用Microsoft Bot Framework将文件附加到邮件?,asp.net-web-api,content-type,botframework,Asp.net Web Api,Content Type,Botframework,我有Web API服务: [ActionName("download")] [HttpGet] public HttpResponseMessage Download() { var stream = new FileStream(HostingEnvironment.MapPath("~/tmp/") + "doc.pdf", FileMode.Open); var result = new HttpResponseMessage(HttpStatusCode.OK)

我有Web API服务:

[ActionName("download")]
[HttpGet]
public HttpResponseMessage Download()
{
    var stream = new FileStream(HostingEnvironment.MapPath("~/tmp/") + "doc.pdf", FileMode.Open);
    var result = new HttpResponseMessage(HttpStatusCode.OK)
    {
        Content = new StreamContent(stream)
    };
    result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
    {
        FileName = document.Name + "." + document.AssociatedApplication.Extension
    };

    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
    return result;
}
机器人程序代码:

if (message.Text.StartsWith("/d"))
{
    var contentType = "application/pdf";
    var attachment = new Attachment(contentType, "https://localhost/api/documents.download");
    var response = await client.GetAsync("https://localhost/api/documents.download");

    var data = await response.Content.ReadAsByteArrayAsync();
    System.IO.File.WriteAllBytes(HostingEnvironment.MapPath("~/tmp/") + document.Name + "." + document.Extension, data);

    var stream = System.IO.File.ReadAllBytes(HostingEnvironment.MapPath("~/tmp/") + document.Name + "." + document.Extension);
    attachment.Content = stream;

    var msg = message.CreateReplyMessage("This is your document: ");
    msg.Attachments = new[] { attachment };

    await context.PostAsync(msg);
}
如果我将服务器和客户机上的内容类型更改为“image/png”,并将png图像从服务器发送到客户机,那么这个示例工作得非常完美-在Bot框架模拟器中,我得到了文本“this is your document:”和接收到的图像

但是,如果我尝试发送内容类型为“application/PDF”或“application/octet stream”的PDF文档,并在内容类型为“application/PDF”的客户端上获取它,那么在Bot Framework Emulator上,我会收到这样的消息:

这是您的文档:()

这是否可能在对话“真实”文档中而不是下载链接(如何处理图像)

PS:仅适用于“图像/png”或类似的内容类型。

2件事: 1.看起来您没有设置附件的内容类型(上面的代码使用的是“”) 2.内容不用于推送媒体文件。我们的消息限制为256k序列化json。如果要发送文档或图像,请发送一个带有指向文件的url和文件的内容类型的附件 3.并非所有通道都具有图像以外的文件语义,它们将文件表示为链接。我们使用contenttype来确定是否可以为给定附件执行特定于频道的操作