Skip to content

[Bug]: TeamsAttachmentDownloader doesn't work in Bot Framework Emulator #1154

@qinezh

Description

@qinezh

Language

Javascript/Typescript

Version

latest

Description

I created a Teams bot app to handle inline image sent from users with teams-ai SDK. It works as expected in Teams client, however it doesn't work in Bot Framework Emulator and unhandled error is thrown:

[onTurnError] unhandled error: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

Looks it's related to the implementation to check if content url starts with 'https://': https://github.com/microsoft/teams-ai/blob/8258ca0e2396c3f5bb376cdc62374b5cd11b5603/js/packages/teams-ai/src/TeamsAttachmentDownloader.ts#L76

In Bot Framework Emulator, the image is hosted from localhost with http endpoint:
image

In addition, I found TeamsAttachmentDownloader will try to get access token before downloading the attachment. When I test the bot app in Bot Framework Emulator with empty string of BOT_ID and BOT_PASSWORD, the step to get access token would be failed:

https://github.com/microsoft/teams-ai/blob/8258ca0e2396c3f5bb376cdc62374b5cd11b5603/js/packages/teams-ai/src/TeamsAttachmentDownloader.ts#L113-L128

We may consider skipping to get access token if the BOT_ID is empty, similar to the implementation of botbuilder SDK.

Reproduction Steps

1. Create a Teams bot app with below code snippet.


const downloader = new TeamsAttachmentDownloader({
  botAppId: process.env.BOT_ID,
  botAppPassword: process.env.BOT_PASSWORD,
});

app.activity(ActivityTypes.Message, async (context: TurnContext, state: ApplicationTurnState) => {
    const attachments = await downloader.downloadFiles(context, state);
    await context.sendActivity(`you have uploaded ${attachments?.length ?? 0} attachments`);
});


2. Run the Teams bot app locally.
3. Test the bot app by uploading an image in Bot Framework Emulator.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions