我想下载文档/图像(文档/图像位于互联网上,我给出了它的路径)。但它不起作用……但是,如果我只是评论附件部分,我就能从 BOT 那里得到“嗨”。
让控制器像这样
[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);
}
}
在这行代码之后你的代码出错了
Activity reply = activity.CreateReply("Hi");
您正在将附件添加到activity对象而不是reply。你正在得到“Hi” 回复,因为您没有将附件添加到reply参考。
我已经修改了您的代码,它可以正常工作并在 Bot Framework Emulator 上成功显示图像。
Code
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)