Bot unable to see attachments in groupchat and channel conversation context
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:
- 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}
- 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:
- 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> Can you check this code?</p>', 'name': None, 'thumbnail_url': None}
- 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> 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,
- I have correctly set manifest to support files:
"supportsFiles": true
- The following permissions are added to the Microsoft Graph API permissions:
- I'm using Microsoft Graph APIs to ensure the bot can work in groupchat and channel conversations
- I'm asking for file consent as well
- 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
- 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! :)