botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Photos taken by camera are not accessible to the bot

Open harunB10 opened this issue 1 year ago • 2 comments

I have created a Bot and I'm using it as App in Teams. Everything works with sending and receiving messages. But, when it comes to attachmenets there is one thing that is not clear why is it happening. If I upload a picture using desktop Teams app then it works. Same with uploading the photo using mobile device (but as attachment). However, if I take a photo via camera directly then I always get:

Invalid status 403 code for 'https://smba.trafficmanager.net/de/0f6e1649-5b36-450e-95e3-ef5439e40b1f/v3/attachments/0-nde-d3-d1777d3ef5231f56fc64d6d9ebaa27e/views/original': {"error":{"code":"BotError","message":"Access Forbidden"}}

In my manifest.json I have included

supportsFiles: true

and added:

devicePremissions: ['media']

But still same scenario is happening.

harunB10 avatar Feb 25 '25 08:02 harunB10

@harunB10 Teams has a couple of way of accessing attachments. One of those requires an auth token. Any of the AppCredential based classes can be used to get a token. MicrosoftAppCredential is quite common, but it depends on your settings for the bot. The MicrosoftAppType, etc...

tracyboehrer avatar Apr 02 '25 18:04 tracyboehrer

@tracyboehrer I have auth token which I am providing but still I get same 403 error. For example:

var url = "https://smba.trafficmanager.net/de/0f6e39-5b36-450e-95e3-e9e40b1f/v3/attachments/0-nde-d3-e5975b71c94997c5612130/views/original";
var token = await new MicrosoftAppCredentials("MY_ID", "MY_SECRET", null, null, "https://api.botframework.com/.default").GetTokenAsync();

using(HttpClient httpClient = new HttpClient())
{

    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

    HttpResponseMessage res = await httpClient.GetAsync(url);

    if (res.IsSuccessStatusCode)
    {
        var imageData = await res.Content.ReadAsByteArrayAsync();
        Console.WriteLine("Image downloaded successfully!");
    }
    else
    {
        Console.WriteLine($"Failed to download image: {res.StatusCode}");
        var errorMessage = await res.Content.ReadAsStringAsync();
        Console.WriteLine($"Error message: {errorMessage}");
    }
}

I really don't understand why do we have difference between uploaded images directly from camera and taking a photo of it and then attach it. These two scenarios have totally different urls.

harunB10 avatar Apr 04 '25 08:04 harunB10