Closed mindncz closed 3 years ago
Are you using sample microsoft/BotBuilder-Samples#15? Because there are some extra steps needed in order to upload files to teams. This is outline in sample microsoft/BotBuilder-Samples#56 (Teams-File-Upload).
Yes, I was using sample microsoft/BotBuilder-Samples#15. Sample microsoft/BotBuilder-Samples#56 used cards to ask user to Accet/Reject the attachment which works in my environment. However, I want to attach a file with message directly like what microsoft/BotBuilder-Samples#15 does.
This is the manifest I used. { "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.5/MicrosoftTeams.schema.json", "manifestVersion": "1.5", "version": "4.0", "id": "*", "packageName": "com.microsoft.teams.fileupload", "developer": { "name": "mindcz", "websiteUrl": "https://**.azurewebsites.net", "privacyUrl": "https://****.azurewebsites.net/privacy", "termsOfUseUrl": "https://****.azurewebsites.net/termsofuse" }, "icons": { "color": "color.png", "outline": "outline.png" }, "name": { "short": "*", "full": "" }, "description": { "short": "Ask bot", "full": "* bot will give you info " }, "accentColor": "#FFFFFF", "bots": [ { "botId": "**", "scopes": [ "personal", "team", "groupchat" ], "supportsFiles": true } ], "permissions": [ "identity", "messageTeamMembers" ], "validDomains": [ "*.azurewebsites.net"] }
The code is exactly the same as example microsoft/BotBuilder-Samples#15.
Alright, let me see if I can repro this for you.
@jwiley84 any update?
I am able to repro this, it's only happening in Teams, attempting to track down the cause.
There's something in the following code it doesn't like (my debugger is acting up, so I'm going line by line):
var response = await attachments.Client.Conversations.UploadAttachmentAsync(
conversationId,
new AttachmentData
{
Name = @"Resources\architecture-resize.png",
OriginalBase64 = File.ReadAllBytes(imagePath),
Type = "image/png",
});
It's kicking back the following stacktrace:
fail: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
[OnTurnError] unhandled error : One or more errors occurred. (Operation returned an invalid status code 'NotFound')
System.AggregateException: One or more errors occurred. (Operation returned an invalid status code 'NotFound') ---> Microsoft.Bot.Schema.ErrorResponseException: Operation returned an invalid status code 'NotFound'
at Microsoft.Bot.Connector.Conversations.UploadAttachmentWithHttpMessagesAsync(String conversationId, AttachmentData attachmentUpload, Dictionary`2 customHeaders, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Connector\Conversations.cs:line 2115
at Microsoft.Bot.Connector.ConversationsExtensions.UploadAttachmentAsync(IConversations operations, String conversationId, AttachmentData attachmentUpload, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Connector\ConversationsExtensions.cs:line 428
at Microsoft.BotBuilderSamples.AttachmentsBot.GetUploadedAttachmentAsync(ITurnContext turnContext, String serviceUrl, String conversationId) in C:\Users\Jessi\botwork\BotBuilder-Samples-122719\samples\csharp_dotnetcore\15.handling-attachments\Bots\AttachmentsBot.cs:line 201
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Microsoft.BotBuilderSamples.AttachmentsBot.HandleOutgoingAttachment(ITurnContext turnContext, IMessageActivity activity) in C:\Users\Jessi\botwork\BotBuilder-Samples-122719\samples\csharp_dotnetcore\15.handling-attachments\Bots\AttachmentsBot.cs:line 118
at Microsoft.BotBuilderSamples.AttachmentsBot.ProcessInput(ITurnContext turnContext) in C:\Users\Jessi\botwork\BotBuilder-Samples-122719\samples\csharp_dotnetcore\15.handling-attachments\Bots\AttachmentsBot.cs:line 92
at Microsoft.BotBuilderSamples.AttachmentsBot.OnMessageActivityAsync(ITurnContext`1 turnContext, CancellationToken cancellationToken) in C:\Users\Jessi\botwork\BotBuilder-Samples-122719\samples\csharp_dotnetcore\15.handling-attachments\Bots\AttachmentsBot.cs:line 32
at Microsoft.Bot.Builder.BotFrameworkAdapter.TenantIdWorkaroundForTeamsMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\BotFrameworkAdapter.cs:line 1218
at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\MiddlewareSet.cs:line 55
at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\BotAdapter.cs:line 200
---> (Inner Exception #0) Microsoft.Bot.Schema.ErrorResponseException: Operation returned an invalid status code 'NotFound'
at Microsoft.Bot.Connector.Conversations.UploadAttachmentWithHttpMessagesAsync(String conversationId, AttachmentData attachmentUpload, Dictionary`2 customHeaders, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Connector\Conversations.cs:line 2115
at Microsoft.Bot.Connector.ConversationsExtensions.UploadAttachmentAsync(IConversations operations, String conversationId, AttachmentData attachmentUpload, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Connector\ConversationsExtensions.cs:line 428
at Microsoft.BotBuilderSamples.AttachmentsBot.GetUploadedAttachmentAsync(ITurnContext turnContext, String serviceUrl, String conversationId) in C:\Users\Jessi\botwork\BotBuilder-Samples-122719\samples\csharp_dotnetcore\15.handling-attachments\Bots\AttachmentsBot.cs:line 201<---
Is this an example issue or SDK issue?
Further debugging has show that this particular error is occurring in every test I run EXCEPT the emulator. This option does not work while ngrok'd into Teams, Facebook or webchat, or in a deployed bot using the 'Test in Webchat' feature. Escalating.
Adding @EricDahlvang to assist.
Hi @mindncz
I don't think Option 3 of Sample 15 is going to work on Teams, since the Teams channel requires consent to upload files. Sample 56 is for Teams files, and demonstrates the FileConsentCard.
However, I did test out Option 3 on WebChat and DirectLine where this should work as expected. We have escalated this issue internally. Thank you for reporting.
Hi @EricDahlvang
Thanks for the reply.
As every member belong to a Team could upload files to Teams channel via Teams desktop client or web without any consent, is the content required to upload files only apply to bots? And what's the design reason behind this, just want to better understand it.
Yes, Bots require users to accept files sent to them. More information can be found here: https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-and-receive-files?tabs=dotnet#using-the-teams-bot-apis
The services team pointed out the maximum message size is 256k, which explains the inline attachment failure. A PR is here https://github.com/microsoft/BotBuilder-Samples/pull/2130 to reduce the image size, which enables Sample 15 on the Direct Line channel.
GetUploadedAttachment is still not working in Teams. I tried to upload 400 bytes png image but it doesn't work working in bot emulator Sample type: BotBuilder-Samples/samples Sample language: NodeJS Sample name: 15. handling attachment
Reopening. Apparently since size is not the issue here. Assigned to @johnataylor
GetUploadedAttachment is not intended to work on Teams. Sample 56 with the FileConsentCard is the sample to use for teams.
From the readme of sample 15:
NOTE: A specific example for Microsoft Teams, demonstrating how to upload files to Teams from a bot and how to receive a file sent to a bot as an attachment, can be found here
Closing this, since sample 15 is not intended for Teams.
Yes, Bots require users to accept files sent to them. More information can be found here: https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-and-receive-files?tabs=dotnet#using-the-teams-bot-apis
@EricDahlvang This link is broken, 404
404 bump
Hi @dgancho, @billreynolds007 Could you please try this document.
Sample information
Describe the bug
GetUploadedAttachmentAsync throws exception: "Operation returned an invalid status code 'NotFound'" in Teams. When tested in Bot emulator, GetUploadedAttachmentAsync works well and the file could be uploaded.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The attached file "architecture-resize.png" will be uploaded successfully.