使用Microsoft bot框架下载文件(pdf/image) [英] downloading file (pdf/image) from using Microsoft bot framework
问题描述
我想下载文档/图像(文档/图像位于Internet上,我正在提供它的路径).但是它无法正常工作..即使我只评论附件部分,我仍然能够从BOT中获得嗨".
I wanted to download document/image ( Document/image is on internet and I am giving path of it). But it ins not working.. How ever if I just comment the attachment part, I am able to get "Hi" from BOT.
让我们拥有像这样的控制器
Lets have the controller like this
[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
Activity reply = activity.CreateReply("Hi");
activity.Attachments.Add(new Attachment()
{
ContentUrl = "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png",
ContentType = "Image/png",
Name = "Bender_Rodriguez.png"
});
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
推荐答案
在此行代码之后,您确实在代码中犯了错误
You did mistake in your code after this line of code
Activity reply = activity.CreateReply("Hi");
您正在将附件添加到活动对象,而不是回复.因为您没有将附件添加到回复参考中,所以得到了嗨.
You are adding the attachments to the activity object instead of reply. You are getting "Hi" in response because you did not added the attachments to reply reference.
我已经修改了您的代码,它可以正常工作并成功在Bot Framework Emulator上显示图像.
I have modified your code, it’s working and displayed image on Bot Framework Emulator successfully.
代码
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
Activity reply = activity.CreateReply("Hi");
reply.Recipient = activity.From;
reply.Type = "message";
reply.Attachments = new List<Attachment>();
reply.Attachments.Add(new Attachment()
{
ContentUrl = "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png",
ContentType = "image/png",
Name = "Bender_Rodriguez.png"
});
await connector.Conversations.ReplyToActivityAsync(reply);
//var reply = await connector.Conversations.SendToConversationAsync(replyToConversation);
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
}
-Kishore
这篇关于使用Microsoft bot框架下载文件(pdf/image)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!