私は、Web APIサービスを持っている:私は、「画像/ PNG」に、サーバーとクライアント上のコンテンツタイプを変更し、サーバからクライアントへのPNG画像を送信する場合Microsoft Bot Frameworkを使用してメッセージにファイルを添付するにはどうすればよいですか?
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);
}
:
[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;
}
ボットのコードをこのサンプルは完璧に動作します - Bot Frameworkエミュレータでは "これはあなたのドキュメントです:"というテキストがあり、イメージを受け取りました。
コンテンツタイプが "application/pdf"または "application/octet-stream"のPDFドキュメントを送信し、コンテンツタイプが "application/pdf"のクライアントで取得しようとすると、ボットフレームワークエミュレータでそのようなメッセージ:これはあなたの文書である
が、これは「本物」のドキュメントの代わりに、ダウンロード用のリンクは(どのようにそれはイメージで動作します)会話の中で取得することはできますか?
PS:This questionは、「画像/ png」などのコンテンツタイプでのみ動作します。