botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Reply Message to the user with an attachement of docx file from GoogleDrive

Open Vkrish-Nimmagadda opened this issue 9 years ago • 8 comments

Bot Info

*Bot Name : "Sample"

  • SDK Platform: .NET
  • SDK Version: 3.9.1
  • Active Channels: Skype
  • Deployment Environment: Azure App Service

Issue Description

I have a few files in my Google Drive - docx and pdf files. Upon request by the user, I want the Bot to send either a docx file or pdf file as an attachment. When I just provide the Google Drive link, it opens up a Browser to download the file. But I don't want that to happen. I want the user to be able to download the attachment right from the skype window itself. I am able to send images and have them downloaded. But it is not working for pdf and docx files - I am setting the right content-type and content-url in the Attachment object.
Is there an elegant way to get this done ?

Expected Behavior

The Bot should be able to send me an attachment which I should be able to right click and save the file or I go to the folder where the attachment would have already got downloaded and pick the file from my local file system.

Actual Results

The bot just says quite and does not do anything when I send docx or pdf files.

Vkrish-Nimmagadda avatar Sep 14 '17 10:09 Vkrish-Nimmagadda

Could you please add your bot name, and minimum reproducible code so we can check your bot and confirm if this is a bug or not?

JasonSowers avatar Sep 14 '17 18:09 JasonSowers

Hi Jason, thank you for the response. Name of the Bot is : "Sample" If the Uri in the attachment is a image with appropriate Content-type it works else it gives the attachment as if we gave a link and when clicked on the thumbnail, it opens up the Browser to download. I don't want the user to switch between Apps (Skype and Browser and back) to download the file. Here is the (quick messy)Code - tested with various content-types :

 if (possibleContentTypes.Count == 0)
            {
                possibleContentTypes.Add("image/jpeg");
                possibleContentTypes.Add("application/vnd.google-apps.document");
                possibleContentTypes.Add("application/octet-stream");
                possibleContentTypes.Add("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
                possibleContentTypes.Add("application/msword");
                possibleContentTypes.Add("application/ms-word");
                possibleContentTypes.Add("image/jpg");             
                //possibleContentTypes.Add("");
            }
.....
private async static Task<Attachment> GetInternetAttachment(IDialogContext context, string contentType)
        {

             //await context.PostAsync("cooking the attachment...");

            
            Attachment tempAttachment = new Attachment();
            tempAttachment.ContentType = contentType;
             tempAttachment.ContentUrl = "https://drive.google.com/file/u/1/d/xxxxxx/view?usp=drivesdk";
                        tempAttachment.Name = "test.docx";
            //await context.PostAsync("Inside the GetInternetAttachment and made the attachement object...about to return !!");
            return tempAttachment;

        }

private async Task<bool> SendAttachment2(IDialogContext context, string contentType)
        {
            bool isSuccess = true;
            try
            {
                var mesgToUser = context.MakeMessage();
             
                Attachment attachmentToBeSent = await GetInternetAttachment(context, contentType);
                mesgToUser.Attachments.Add(attachmentToBeSent);
                await context.PostAsync(mesgToUser);
                context.Wait(MessageReceivedAsync);
            }
            catch (Exception e)
            {
                isSuccess = false;
            }
            return isSuccess;
        }
` ``

Vkrish-Nimmagadda avatar Sep 15 '17 14:09 Vkrish-Nimmagadda

@JasonSowers any help on this is appreciated. Thank you in advance for your time.

Vkrish-Nimmagadda avatar Sep 18 '17 17:09 Vkrish-Nimmagadda

Have a same issue with Attachments. Hope this gets solved soon.

varunreddycs avatar Sep 19 '17 05:09 varunreddycs

@JasonSowers Same Issue here. are we able to send file attachments Yes Or no .If yes how.

XyzFreak avatar Sep 19 '17 14:09 XyzFreak

Looking into this now, I'll get back to you for my findings.

I did find this specifying the correct MIME type, I learned something today 👍

The correct MIME type for DOCX is not application/msword but application/vnd.openxmlformats-officedocument.wordprocessingml.document.

JasonSowers avatar Sep 19 '17 15:09 JasonSowers

After attempting to accomplish this in many different ways I was unable to produce the behavior you are looking for. To download a file it does so through the browser. That being said you may be able to implement a workaround using something like this or this by implementing another (mvc not api) controller and calling it from where you need to send your file from.

After having a few conversations around the office, this is not a bug but is the intended way to send files to download. We can log this as a feature request but cannot promise any timelines right now.

In my personal opinion the best way to implement this (from a UX perspective) with out of the box functionality was using a herocard with a download button

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            
            HeroCard h = new HeroCard();
            h.Buttons = new List<CardAction>
            {
                new CardAction(ActionTypes.DownloadFile, "Compliace Doc", value: "http://SomeURL/Compliance%20Doc.docx")
            };
            var activity = await result as Activity;
            var reply = activity.CreateReply();

            var aList = new List<Attachment>();
            aList.Add(h.ToAttachment());
            reply.Attachments = aList;
            await context.PostAsync(reply);

            context.Wait(MessageReceivedAsync);
        }

JasonSowers avatar Sep 19 '17 18:09 JasonSowers

Reopen if any further questions.

fanidamj-zz avatar Oct 19 '17 18:10 fanidamj-zz