Teams Bot: attachment file type on mobile

Benoit Dupont 66 Reputation points
2023-07-10T11:57:53.26+00:00

Hello,

When I send a media file from the Teams iOS app, I don't have the file type of the image.
There is no extension to the and no attribute to the HTML. On the desktop app there is the "itemscope" to specify the file type.

Sample iOS Teams payload:

{
    "text": "Envoyer un fax Γ  162626\r\n",
    "textFormat": "plain",
    "attachments": [
        {
            "contentType": "image/*",
            "contentUrl": "https://smba.trafficmanager.net/amer/v3/attachments/0-eus-d20-fd7c8146fbc34613ddb246bed1988c0e/views/original"
        },
        {
            "contentType": "text/html",
            "content": "<div>Envoyer un fax Γ  162626<br>\r\n<img src=\"https://us-api.asm.skype.com/v1/objects/0-eus-d20-fd7c8146fbc34613ddb246bed1988c0e/views/imgo\" itemscope=\"\" itemtype=\"http://schema.skype.com/AMSImage\" style=\"width:2448px; height:3264px\"></div>"
        }
    ],
    "type": "message",
    "timestamp": "2023-06-29T12:26:40.2070891Z",
    "localTimestamp": "2023-06-29T09:26:40.2070891-03:00",
    "id": "1688041600190",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer/",
    "from": {
        "id": "29:1JiEH1nLmzqH5YT7Do_1KRCs7ISDxUmVVKPbIzwM1pc884QpFbzi7GFznE58JZKe5sdjw65yzjAZtxyJt55B3mA",
        "name": "Benoit Dupont",
        "aadObjectId": "af24b8a2-cfe8-453a-a9b4-4a917b1534ae"
    },
    "conversation": {
        "conversationType": "personal",
        "tenantId": "caafef10-9d12-4668-a0d6-268b71695e1a",
        "id": "a:1ktMfOkUqtyhd4ub9GhZwaOdqpjjygWz5IZGvHZLTCnduBU1HmsFGO9vBAMZMQhqJOeiphjhE_k9G3HerhrBgeIf6uuA-FYRX93w_OsJYVTFX1lB36Q5xJgAGJtizZM1o"
    },
    "recipient": {
        "id": "28:45fc30f1-94c5-48aa-b0df-ef0e41b65c6c",
        "name": "XM Fax  US "
    },
    "entities": [
        {
            "locale": "fr-FR",
            "country": "BE",
            "platform": "iOS",
            "timezone": "America/Moncton",
            "type": "clientInfo"
        }
    ],
    "channelData": {
        "tenant": {
            "id": "caafef10-9d12-4668-a0d6-268b71695e1a"
        }
    },
    "locale": "fr-FR",
    "localTimezone": "America/Moncton"
}

This is a sample code from the desktop app where you can see the itemscope attribute containing the file type:

<p>&nbsp;</p>\r\n<p><img itemtype=\"http://schema.skype.com/AMSImage\" alt=\"image\" src=\"https://us-api.asm.skype.com/v1/objects/0-eus-d11-1b47833a8fa4fb8fe906041a1babe0d4/views/imgo\" itemscope=\"png\" width=\"97.26962457337883\" height=\"250\" id=\"x_0-eus-d11-1b47833a8fa4fb8fe906041a1babe0d4\" itemid=\"0-eus-d11-1b47833a8fa4fb8fe906041a1babe0d4\" style=\"vertical-align:bottom\"></p>\r\n<p>&nbsp;</p>

When I try to make a request to get the attachment info, I get the following, without a "type" attribute.

Your documentation says the attribute should be there: https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#attachmentinfo-object

GET https://smba.trafficmanager.net/amer/v3/attachments/0-eus-d7-705ba1541e51724674e42330f55f5cf9

{
    "type": "Image",
    "views": [
        {
            "viewId": "original",
            "size": 1626813
        }
    ]
}
Microsoft Teams | Development
{count} votes

2 answers

Sort by: Most helpful
  1. Sayali-MSFT 3,991 Reputation points Microsoft External Staff Moderator
    2023-07-19T09:58:17.4566667+00:00

    We have tried the above scenarios, as you mention did not get the type attribute.
    As per document, type=Content type of the attachment.
    which is already return in the above payload.

    also, could you please elaborate more on itemscope and share the steps so that we can try it from our end?

    {
      "attachments": [
        {
          "contentType": "application/vnd.microsoft.teams.file.download.info",
          "content": {
            "downloadUrl": "https://m365x9462XXXX-my.sharepoint.com/personal/admin_m365x9462XXXX_onmicrosoft_com/_layouts/15/download.aspx?UniqueId=2392290d-ff20-4520-9862-f5bf588688e0&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9lNA&ApiVersion=2.0",
            "uniqueId": "2392290d-ff20-4520-9862-f5bf588XXXXX",
            "fileType": "png"
          },
          "contentUrl": "https://m365x9462XXXX-my.sharepoint.com/personal/admin_m365x9462XXXX_onmicrosoft_com/Documents/Microsoft Teams Chat Files/outline.png",
          "name": "outline.png"
        },
        {
          "contentType": "text/html",
          "content": ""
        }
      ],
      "type": "message",
      "timestamp": "2023-07-19T09:40:22.0157834Z",
      "localTimestamp": "2023-07-19T15:10:22.0157834+05:30",
      "id": "1689759621995",
      "channelId": "msteams",
      "serviceUrl": "https://smba.trafficmanager.net/amer/",
      "from": {
        "id": "29:1ikDJNiDL-7-Sb-LPAB7WTVaDlbPAzCyOUw6pSCQP_Pm",
        "name": "MOD Administrator",
        "aadObjectId": "e652dd92-dd63-4fcc-b5b2-2005681e8e9f"
      },
      "conversation": {
        "conversationType": "personal",
        "tenantId": "aa923623-ae61-49ee-b401-81f414b6ad5a",
        "id": "a:1BKK_CYD1vE1bJWpV6B23n3pxd5xL6GhuXMCRbQkx5i59RwKgC"
      },
      "recipient": {
        "id": "28:734601fc-bbcd-4a30-9092-3c89f8dXXXXX",
        "name": "SBot"
      },
      "entities": [
        {
          "locale": "en-US",
          "country": "US",
          "platform": "Windows",
          "timezone": "Asia/Calcutta",
          "type": "clientInfo"
        }
      ],
      "channelData": {
        "tenant": {
          "id": "aa923623-ae61-49ee-b401-81f414bXXXXX"
        }
      },
      "locale": "en-US",
      "localTimezone": "Asia/Calcutta"
    }
    

  2. VenuGopal Malladi 0 Reputation points
    2023-12-19T06:44:38.6833333+00:00

    Is there any update on this ? I am facing the same issue and actually the URL inside contentUrl is not retrievable as I keep getting 401 error. I tried accessing both urls

    1. attachments[0].contentUrl - https://smba.trafficmanager.net/amer/v3/attachments/0-cus-d17-c53459922d66463fb94af32a61057191/views/original
    2. parsing html content and using img url inside it - https://us-api.asm.skype.com/v1/objects/0-cus-d17-c53459922d66463fb94af32a61057191/views/imgo

    @Benoit Dupont were you able to retrieve the attachments ? I have tried adding authentication headers using AppId and password but it doesn't seem to be working either. Below is the snippet i've been using:

    const axios = require("axios");
    const { MicrosoftAppCredentials } = require("botframework-connector");
    
    async function getAttachment() {
      try {
        // const serviceUrl = 'https://smba.trafficmanager.net/amer/';
        // MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
        const contentUrl = "https://smba.trafficmanager.net/amer/v3/attachments/0-cus-d17-c53459922d66463fb94af32a61057191";
        // const contentUrl = "https://us-api.asm.skype.com/v1/objects/0-cus-d17-c53459922d66463fb94af32a61057191/views/imgo";
        var credentials = new MicrosoftAppCredentials("<appId>", "<appPassword>");
        const botToken = await credentials.getToken();
        const config = {
          headers: { Authorization: `Bearer ${botToken}` },
          responseType: "stream",
        };
        const response = await axios({ method: "GET", url: contentUrl, ...config });
        console.log("πŸš€πŸš€ ~ file: testAPI.js:16 ~ getToken ~ response:", response.data);
      } catch (error) {
        console.log("πŸš€πŸš€ ~ file: tets.js:24 ~ getToken ~ error:", error);
      }
    }
    
    getAttachment();
    
    {
        "text": " \r\n\r\n ",
        "textFormat": "plain",
        "attachments": [
            {
                "contentType": "image/*",
                "contentUrl": "https://smba.trafficmanager.net/amer/v3/attachments/0-cus-d17-c53459922d66463fb94af32a61057191/views/original"
            },
            {
                "contentType": "text/html",
                "content": "<p>&nbsp;</p>\r\n<p><img itemtype=\"http://schema.skype.com/AMSImage\" alt=\"image\" src=\"https://us-api.asm.skype.com/v1/objects/0-cus-d17-c53459922d66463fb94af32a61057191/views/imgo\" itemscope=\"jpeg\" width=\"444.44444444444446\" height=\"250\" aria-label=\"has context menu\" id=\"x_0-cus-d17-c53459922d66463fb94af32a61057191\" itemid=\"0-cus-d17-c53459922d66463fb94af32a61057191\" style=\"vertical-align:bottom\"></p>\r\n<p>&nbsp;</p>"
            }
        ],
        "type": "message",
        "timestamp": "2023-12-17T09:58:08.0629932Z",
        "localTimestamp": "2023-12-17T15:28:08.0629932+05:30",
        "id": "1702807088043",
        "channelId": "msteams",
        "serviceUrl": "https://smba.trafficmanager.net/amer/",
        "from": {
            "id": "29:18spOrxkvI_78J0qBmTjCWlqbCm3EGNuI6pKQFMFkZKqkiUWdvHc4b3VRbVWEItXL_80_H8owExaXxb9KlhPnMA",
            "name": "Praveen Pasam",
            "aadObjectId": "42038d1b-4021-47ab-a494-26d722d8348e"
        },
        "conversation": {
            "conversationType": "personal",
            "tenantId": "f8250d44-a7af-4d49-85bc-589e0e15d852",
            "id": "a:1M23gbESVfdmapfvZtRSod9paD5QRWsJ8L0JOeefNUGpuCymrvAdMBLXOrdYBCSmlMoBkxWf14p-__GEvsnr0LRKk8A2gpVqkwy-UEbSMx5R5SbN-4ioJuiNsUQVuCbya"
        },
        "recipient": {
            "id": "28:2241ccbc-44a8-4267-8898-5affc2159e97",
            "name": "SmartAssistLatestUAT"
        },
        "entities": [
            {
                "locale": "en-GB",
                "country": "GB",
                "platform": "Web",
                "timezone": "Asia/Calcutta",
                "type": "clientInfo"
            }
        ],
        "channelData": {
            "tenant": {
                "id": "f8250d44-a7af-4d49-85bc-589e0e15d852"
            }
        },
        "locale": "en-GB",
        "localTimezone": "Asia/Calcutta"
    }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.