-
Notifications
You must be signed in to change notification settings - Fork 292
MS Teams: Auto-detect Power Automate and disable file attachments #1995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MS Teams: Auto-detect Power Automate and disable file attachments #1995
Conversation
The MS Teams sink was embedding base64-encoded images in the Adaptive Card payload, causing 'payload too large' errors with Power Automate webhooks (which have a strict 28KB limit). Other sinks (Slack, Discord, Jira, Zulip, etc.) already check the send_svg parameter to filter out images, but MS Teams was missing this check. Changes: - Pass send_svg parameter from MsTeamsSink to MsTeamsSender - Filter image FileBlocks when send_svg=False using is_image() helper - Add documentation for the send_svg setting Fixes robusta-dev#1994
WalkthroughAdds an optional Changes
Sequence Diagram(s)sequenceDiagram
participant Config as Sink Config
participant Sink as MsTeamsSink
participant Sender as MsTeamsSender
participant Teams as MS Teams Webhook
Config->>Sink: sink_config (webhook_url, send_files?)
Sink->>Sender: send_finding_to_ms_teams(..., send_files=cfg.send_files)
Sender->>Sender: if send_files is None -> _is_power_automate_url(webhook_url) -> decide send_files
Sender->>Sender: split blocks into files_blocks and other_blocks
alt send_files is false
Sender-->>Sender: drop files_blocks
else send_files is true
Sender->>Sender: upload files_blocks as attachments
end
Sender->>Teams: send Adaptive Card (with/without attachments)
Teams-->>Sender: response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Replace the incorrectly used send_svg parameter with send_files: - send_svg was designed only for SVG files (see commit e354c48) - MS Teams 28KB limit affects all file types, not just SVGs - Follow existing pattern from Telegram, Pushover, YaMessenger sinks Changes: - Add send_files: bool = True to MsTeamsSinkParams - Update sender.py to filter all files when send_files is False - Remove incorrect is_image import from sender.py - Add docstring to write_finding for CodeRabbit coverage - Update documentation with new parameter name
- Change send_files from bool to Optional[bool] with None default - Add _is_power_automate_url() helper to detect Power Automate webhooks - Auto-disable files for Power Automate URLs (*.api.powerplatform.com) - Keep files enabled for legacy webhooks (*.webhook.office.com) - Explicit send_files: true/false always overrides auto-detection - Update documentation with auto-detection behavior
befa7f8 to
ed438ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/robusta/integrations/msteams/sender.py`:
- Around line 22-28: Docstring for _is_power_automate_url is misleading about
legacy domains; update the docstring to remove the incorrect reference to
'*.webhook.office.com' and either omit legacy domain mention or replace it with
the correct retiring domain '*.logic.azure.com' (or state that legacy connectors
are retired) so the description matches the implemented detection (checks for
".api.powerplatform.com" and "/powerautomate/"); keep the function name
_is_power_automate_url and its behavior unchanged.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docs/configuration/sinks/ms-teams.rstsrc/robusta/core/sinks/msteams/msteams_sink_params.pysrc/robusta/integrations/msteams/sender.py
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/configuration/sinks/ms-teams.rst
🧰 Additional context used
🧬 Code graph analysis (1)
src/robusta/integrations/msteams/sender.py (2)
src/robusta/core/sinks/msteams/msteams_webhook_tranformer.py (2)
MsTeamsWebhookUrlTransformer(28-69)template(53-69)src/robusta/integrations/msteams/msteams_msg.py (1)
MsTeamsMsg(28-198)
🔇 Additional comments (4)
src/robusta/integrations/msteams/sender.py (3)
64-89: Excellent documentation for the new parameter.The docstring clearly explains the tri-state behavior of
send_files: auto-detection when None, explicit control when True/False. Adding the parameter at the end with a default value maintains backward compatibility.
93-96: Auto-detection correctly uses the transformed webhook URL.The auto-detection happens after
MsTeamsWebhookUrlTransformer.template()is called, ensuring it evaluates the final URL (which may differ from the original due towebhook_override). This is the correct placement.
101-112: Clean filtering approach with minimal code change.The implementation correctly filters
FileBlockentries by clearingfiles_blockswhensend_filesis False. This preserves the existing code path while preventing file attachments from being included in the Adaptive Card payload.src/robusta/core/sinks/msteams/msteams_sink_params.py (1)
13-13: Correct the claim about established pattern consistency.The
send_files: Optional[bool] = Noneimplementation does NOT follow the established pattern from other sinks. Telegram, Pushover, and YaMessenger all usesend_files: bool = True(simple boolean with default True), while MsTeams introduces a unique tri-state approach with None for auto-detection. This is a departure from the existing pattern, not a consistent implementation.The tri-state behavior itself is sound—None enables auto-detection, True forces file sending, False disables it—but the justification in the original review is incorrect.
Likely an incorrect or invalid review comment.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
arikalon1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @philslab-ninja




Summary
Auto-detect Power Automate webhook URLs and disable file attachments by default to avoid the 28KB payload limit. Legacy webhook URLs keep files enabled. User configuration always overrides auto-detection.
Background
Microsoft Teams webhooks have a 28KB message size limit:
With the retirement of Office 365 connectors, users are migrating from legacy webhooks (
*.webhook.office.com) to Power Automate Workflows (*.api.powerplatform.com). Base64-encoded images in alerts frequently exceed this limit.Changes
send_files: Optional[bool] = Noneparameter to MS Teams sink_is_power_automate_url()helper to detect Power Automate webhooks*.api.powerplatform.com)*.webhook.office.com)send_files: true/falsealways overrides auto-detectionHow it works
send_files*.api.powerplatform.comfalse(auto)*.webhook.office.comtrue(auto)Test plan
send_files: trueoverrides auto-detection for Power Automatesend_files: falsedisables files for legacy webhooksReferences
Fixes #1994