microsoft/botbuilder-js

contentType for excel attachment

Kalyan492 opened this issue · 6 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 What channel are you using?

@Kalyan492 What channel are you using?

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

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 , @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 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.