downloading file (pdf/image) from using Microsoft bot framework

对着背影说爱祢 提交于 2019-12-06 09:32:01
Kishore1021

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.

I have modified your code, it’s working and displayed image on Bot Framework Emulator successfully.

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

You are likely getting a null reference exception on the Attachment. Have you checked for exceptions?

Try:

reply.Attachments = new List< Attachment >();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!