botbuilder-js icon indicating copy to clipboard operation
botbuilder-js copied to clipboard

contentType for excel attachment

Open Kalyan492 opened this issue 1 year ago • 5 comments

Hi,

I am working on a bot where it will post an excel attachment to a Channel. I have the following piece of code for the same: const attachment = { contentUrl: {public access enabled blob url}, contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", name: "new_excel_blob.xlsx" }; const reply: any = {type: ActivityTypes.Message} reply.text = Please find your excel; reply.attachments = [attachment]; await context.sendActivity(reply);

Above code throws "Unknown attachment type" error. I have also tried contentType: "reference". Getting the same error.

If I use the same code for image (contentType: "image/png") then I am able to post image with message to the channel. What sshoudl be the correct contentType for excel / .xslx files?

Thanks & Regards, Kalyan

Kalyan492 avatar May 09 '24 14:05 Kalyan492

@Kalyan492 What channel are you using?

tracyboehrer avatar May 09 '24 18:05 tracyboehrer

@Kalyan492 What channel are you using?

@tracyboehrer , Its Teams channel (Private team -> Standard channel)

Kalyan492 avatar May 09 '24 18:05 Kalyan492

You might have to use application/vnd.microsoft.teams.file.download.info. Please see here for more info: https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bots-filesv4

Also; here is a sample that you can test to see if that works for you as well: https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-file-upload/nodejs

dmvtech avatar May 09 '24 18:05 dmvtech

@dmvtech , @tracyboehrer I followed the steps mentioned in "https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=javascript#example-4-file-attachments&preserve-view=true".

I used ClientSecretCredentials to generate a graph client and made the following call:

const chatMessage = { body: { contentType: "html", content: 'Here's the latest report. ', }, attachments: [ { id: {driveItem-id}, contentType: "reference", contentUrl: "https://{example}.sharepoint.com/sites/SiteName/Shared%20Documents/FileName.xlsx", name: "Filename.xlsx", }, ], }; await client .api( "/teams/{teamId/channels/channelId/messages" ) .post(chatMessage);

Getting "Message POST is allowed in application-only context only for import purposes. Refer to https://docs.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details." as response. What does this mean? Can't we use ClientSecretCredentials for token? If so, what kind of flow should I use for token?

Kalyan492 avatar May 10 '24 07:05 Kalyan492

@Kalyan492 That particular error is not a BF SDK related error. Do a search for that error message and see if any of those solutions apply.

tracyboehrer avatar May 10 '24 13:05 tracyboehrer

Closing as is a Teams and/or Graph issue.

dmvtech avatar Jul 12 '24 21:07 dmvtech