Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/robusta/core/sinks/discord/discord_sink.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import logging
from typing import Dict, Any
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove unused Dict import.

Dict is not used (Line 2), and this is already flagged by Flake8 (F401).

✂️ Proposed fix
-from typing import Dict, Any
+from typing import Any
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from typing import Dict, Any
from typing import Any
🧰 Tools
🪛 Flake8 (7.3.0)

[error] 2-2: 'typing.Dict' imported but unused

(F401)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/robusta/core/sinks/discord/discord_sink.py` at line 2, Remove the unused
typing import by deleting "Dict" from the import statement in discord_sink.py
(leave "Any" if still needed); check the module for any usages of "Dict" (none
expected) and run linters to confirm the F401 warning is resolved.


from robusta.core.reporting.base import Finding
from robusta.core.reporting.blocks import ButtonEvent
from robusta.core.sinks.discord.discord_sink_params import DiscordSinkConfigWrapper
from robusta.core.sinks.sink_base import SinkBase
from robusta.integrations.discord.sender import DiscordSender
Expand All @@ -9,7 +13,29 @@ def __init__(self, sink_config: DiscordSinkConfigWrapper, registry):
super().__init__(sink_config.discord_sink, registry)

self.url = sink_config.discord_sink.url
self.sender = DiscordSender(self.url, self.account_id, self.cluster_name, self.params)
self.bot_token = sink_config.discord_sink.bot_token
self.application_id = sink_config.discord_sink.application_id
self.sender = DiscordSender(
self.url,
self.account_id,
self.cluster_name,
self.params,
bot_token=self.bot_token,
application_id=self.application_id
)

def write_finding(self, finding: Finding, platform_enabled: bool):
self.sender.send_finding_to_discord(finding, platform_enabled)

def handle_button_event(self, event: ButtonEvent) -> bool:
"""Handle interactive button events from Discord."""
try:
return self.sender.handle_interaction(event)
except Exception as e:
logging.error(f"Failed to handle Discord button event: {e}", exc_info=True)
return False

def register_interaction_handler(self, interaction_id: str, handler: Any):
"""Register a handler for Discord interactions."""
if hasattr(self.sender, 'register_interaction_handler'):
self.sender.register_interaction_handler(interaction_id, handler)
Comment on lines +30 to +41
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Interactive buttons are effectively broken due to missing sender contract.

On Line 33, self.sender.handle_interaction(...) is called unconditionally, but DiscordSender currently does not expose this method (src/robusta/integrations/discord/sender.py, Lines 91-313). This will raise AttributeError, be caught, and always return False.
Additionally, Lines 40-41 silently skip registration when register_interaction_handler is missing, so callbacks may never be wired.

🛠️ Proposed defensive fix in this file (while implementing sender methods separately)
     def handle_button_event(self, event: ButtonEvent) -> bool:
         """Handle interactive button events from Discord."""
+        interaction_handler = getattr(self.sender, "handle_interaction", None)
+        if interaction_handler is None:
+            logging.error("DiscordSender.handle_interaction is not implemented")
+            return False
         try:
-            return self.sender.handle_interaction(event)
+            return interaction_handler(event)
         except Exception as e:
             logging.error(f"Failed to handle Discord button event: {e}", exc_info=True)
             return False

     def register_interaction_handler(self, interaction_id: str, handler: Any):
         """Register a handler for Discord interactions."""
-        if hasattr(self.sender, 'register_interaction_handler'):
-            self.sender.register_interaction_handler(interaction_id, handler)
+        registrar = getattr(self.sender, "register_interaction_handler", None)
+        if registrar is None:
+            logging.error(
+                "DiscordSender.register_interaction_handler is not implemented; "
+                "interaction '%s' was not registered",
+                interaction_id,
+            )
+            return
+        registrar(interaction_id, handler)

You’ll still need to add handle_interaction and register_interaction_handler implementations in src/robusta/integrations/discord/sender.py for the feature to actually work end-to-end.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/robusta/core/sinks/discord/discord_sink.py` around lines 30 - 41,
handle_button_event currently calls self.sender.handle_interaction
unconditionally and register_interaction_handler silently no-ops if the sender
lacks methods; update handle_button_event to first check hasattr(self.sender,
"handle_interaction") and if missing log a clear error and return False (or a
suitable default) instead of letting AttributeError be raised/caught, and update
register_interaction_handler to check for "register_interaction_handler" on
self.sender and log a warning if absent so missed wiring is visible; reference
the methods handle_button_event and register_interaction_handler in this file
and the DiscordSender implementation (DiscordSender) so maintainers know where
to add the concrete handle_interaction and register_interaction_handler
implementations.