Bot unable to see attachments in groupchat and channel conversation context

Varad L 0 Reputation points
2024-12-05T15:27:17.38+00:00

Hello!

I am creating a bot which interacts with the user, gets their questions, and answer them using an API in the background. I want it to work with attachments (mainly images) as well. As far as I understand, images can be directly pasted, or sent as file attachments, which makes it different in how the bot receives them. In my current workflow, I'm handling direct image pastes with Teams bot token, and handling file attachments by retrieving them using a Microsoft Graph API token.

This is how I'm handling attachments:

async def on_message_activity(self, turn_context: TurnContext):
        logger.debug("Received message: %s", turn_context.activity.text)

        # If attachments are present, handle them and return early
        if turn_context.activity.attachments:
            for attachment in turn_context.activity.attachments:
                logger.info(f"Processing attachment: {attachment.__dict__}")
            all_text_html = all(
                attachment.content_type == 'text/html'
                for attachment in turn_context.activity.attachments
            )
            logger.debug(f"All attachments are text/html: {all_text_html}")
            if not all_text_html:
                await self.handle_attachments(turn_context.activity.attachments, turn_context)
                return

In personal chat with the bot, both direct image pastes and image file attachment approaches are working fine. I'm attaching the logs for reference:

  1. Direct image pastes:
       INFO:bot:Processing attachment: {'additional_properties': {}, 'content_type': 'image/*', 'content_url': 'https://smba.trafficmanager.net/xxxxx', 'content': None, 'name': None, 'thumbnail_url': None}
       INFO:bot:Processing attachment: {'additional_properties': {}, 'content_type': 'text/html', 'content_url': None, 'content': '<p><img itemscope="png" itemtype="http://schema.skype.com/AMSImage" src="xxxx" width="272.52906976744185" height="250" alt="image" id="xxxxx" itemid="xxxxx"></p>\r\n<p>Can you check this code?</p>', 'name': None, 'thumbnail_url': None}
    
  2. Image as file attachment:
       INFO:bot:Processing attachment: {'additional_properties': {}, 'content_type': 'application/vnd.microsoft.teams.file.download.info', 'content_url': 'xxxxx', 'content': {'downloadUrl': 'xxxxx', 'uniqueId': 'xxxx', 'fileType': 'png'}, 'name': 'xxxx', 'thumbnail_url': None}
       INFO:bot:Processing attachment: {'additional_properties': {}, 'content_type': 'text/html', 'content_url': None, 'content': '<p>Can you check this code?</p>', 'name': None, 'thumbnail_url': None}
    

I can use either content_url or downloadUrl to retrieve the content, and send it to the API, no issues here.

But, for groupchat and channel conversation contexts, only direct image pastes are working. Reference logs:

  1. Direct image pastes:
       INFO:bot:Processing attachment: {'additional_properties': {}, 'content_type': 'image/*', 'content_url': 'https://smba.trafficmanager.net/xxxx', 'content': None, 'name': None, 'thumbnail_url': None}
       INFO:bot:Processing attachment: {'additional_properties': {}, 'content_type': 'text/html', 'content_url': None, 'content': '<p><img itemscope="png" itemtype="http://schema.skype.com/AMSImage" src="xxxx" width="272.52906976744185" height="250" alt="image" id="xxxxx" itemid="xxxx"></p>\r\n<p><span itemtype="http://schema.skype.com/Mention" itemscope="" itemid="0">Bot</span>&nbsp;Can you check this code?</p>', 'name': None, 'thumbnail_url': None}
    
  2. Image as file attachment:
       INFO:bot:Processing attachment: {'additional_properties': {}, 'content_type': 'text/html', 'content_url': None, 'content': '<p><span itemtype="http://schema.skype.com/Mention" itemscope="" itemid="0">Bot</span>&nbsp;Can you check this code?</p>', 'name': None, 'thumbnail_url': None}
    

Notice how the attachment is not even recognized when sent as a file?

For reference,

  1. I have correctly set manifest to support files: "supportsFiles": true
  2. The following permissions are added to the Microsoft Graph API permissions: Screenshot 2024-12-05 at 9.40.01 AM
  3. I'm using Microsoft Graph APIs to ensure the bot can work in groupchat and channel conversations
  4. I'm asking for file consent as well
  5. I have went through related documentation, including Send and receive files using bots, Working with files in Microsoft Graph, Send chatMessage in a channel or a chat etc., still unsure what should be done here
  6. I have also ensured for the files I'm sending, they are already present in my SharePoint. But if they are not even getting recognized as an attachment, I cannot retrieve them using Microsoft Graph API. This is important when any external user will use the bot to send file attachments - if the bot does not recognize the income file attachment / has no visibility into the details, it won't be able to retrieve the file using Microsoft Graph API.

Your help in this matter will be greatly appreciated. Thanks! :)

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,554 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,652 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,442 questions
{count} votes

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.