我想下载文档/图像(文档/图像在互联网上,我正在给它的路径)。但它没有工作..如果我只是评论附件部分,我可以从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);
}
}
答案 0 :(得分:2)
在这行代码
之后,你的代码出错了Activity reply = activity.CreateReply("Hi");
您要将附件添加到活动对象,而不是回复。您收到“嗨”,因为您没有将附件添加到回复引用。
我已经修改了你的代码,它在Bot框架模拟器上成功运行并显示了图像。
<强>代码强>
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
答案 1 :(得分:1)
您可能会在附件上获得空引用异常。你检查过例外吗?
尝试:
reply.Attachments = new List&lt;附件&gt;();