microsoft / botbuilder-js

Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
https://github.com/Microsoft/botframework
MIT License
680 stars 276 forks source link

Attachment's DownloadURL is missing when attaching cloud files #4723

Closed mutt0-ds closed 1 month ago

mutt0-ds commented 2 months ago

Versions

Describe the bug

TurnContext.activity.attachments doesn't show the files attached using "Attach Cloud Files". It only works with "Upload from this device"

To Reproduce

Steps to reproduce the behavior:

  1. Run the EchoBot demo
  2. Click on '+' -> Attach File -> Attach Cloud Files image
  3. Log context.activity.attachments
    private test(context: TurnContext): Message {
        const { attachments } = context.activity;
        console.log('attachments', attachments);

    image

Expected behavior

To see the downloadUrl in context.activity.attachments just like it happens when uploading the file from the device image

stevkan commented 1 month ago

@mutt0-ds - Thank you for your patience. Are you still having an issue with this?

Unfortunately, I have been unable to repro the issue. Every attachment I have sent using 'Attach cloud files' shows the file details in the activity.attachments property array. For example:

attachments: [
    {
      contentType: 'application/vnd.microsoft.teams.file.download.info',
      content: [Object],
      contentUrl: 'https://XXXXXXXXXXX/personal/XXXXXXXXXXX/Documents/DahliaList.xlsx',
      name: 'DahliaList.xlsx'
    },
    {
      contentType: 'text/html',
      content: '<p>Sending a file</p>'
    }
  ]

Can you try capturing the attachment in the activity handler's "on message" handler and see if the result is the same?

mutt0-ds commented 1 month ago

Thank you for the assistance! I have used the handler as the following

import { TeamsActivityHandler, TeamsInfo, TurnContext } from 'botbuilder';

export class TeamsBot extends TeamsActivityHandler {
    constructor() {
        super();
        this.onMessage(async (context: TurnContext, next: () => Promise<void>) => {
            console.log(`Received message: ${context.activity.text}`);

            const attachments = context.activity.attachments;
            if (attachments) {
                for (const attachment of attachments) {
                    console.log(`Received attachment: ${JSON.stringify(attachment)}`);
                }
            }
            const response = `Received message: ${context.activity.text}`;
            await context.sendActivity(response);
            await next();
        });

And the issue persists.

image

image

Do I need to change something in my code?

stevkan commented 1 month ago

@mutt0-ds - I'll test your code tomorrow and let you know what I find. In the meantime, can you tell me the size of the file you are trying to send?

mutt0-ds commented 1 month ago

Much appreciated! In the example, the .png is 80kb and the .pdf is 1MB, I also tried with other files of various sizes during my tests.

stevkan commented 1 month ago

@mutt0-ds - I tested your code and it is working without issue for me.

image

image

It's possible this is an issue related to your tenant and/or OneDrive. The notes listed in this portion of the Teams docs regarding storage may point to a cause. Namely,

If you don't have SharePoint Online enabled in your tenant, Microsoft Teams users can't always share files in teams. Users in private chat also can't share files because OneDrive for Business (which is tied to the SharePoint license) is required for that functionality.

and

all compliance rules configured at the tenant level are followed.

I don't know that any of the above is the cause. Only that any of it could be. I would expect an error or warning to appear or the option to send be disabled vs. the attachment just being ignored, but I don't know what the expected functionality should be.

Regardless, at the moment, this is looking less like a BotFramework issue and more like a configuration issue. But let me know what you discover.

I would also recommend posting this issue on Microsoft's Q&A docs forum, tagged with microsoft-teams, and see what response you get. If you do so, include details such as it's not reproducible and your code worked fine when tested.

mutt0-ds commented 1 month ago

Will do! Thank you so much for your help! I will keep you posted

sameretto commented 2 weeks ago

This needs to be reopened when attaching files that are shared to you so not in your personal it doesn't appear as anything but can be sent.

sameretto commented 2 weeks ago

Will do! Thank you so much for your help! I will keep you posted

any update on this?