Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contentType for excel attachment #4662

Open
Kalyan492 opened this issue May 9, 2024 · 5 comments
Open

contentType for excel attachment #4662

Kalyan492 opened this issue May 9, 2024 · 5 comments

Comments

@Kalyan492
Copy link

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

@tracyboehrer
Copy link
Member

@Kalyan492 What channel are you using?

@Kalyan492
Copy link
Author

Kalyan492 commented May 9, 2024

@Kalyan492 What channel are you using?

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

@dmvtech
Copy link
Collaborator

dmvtech commented May 9, 2024

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

@Kalyan492
Copy link
Author

@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?

@tracyboehrer
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants