-
Notifications
You must be signed in to change notification settings - Fork 299
🚀 Feature: Create Discord sink with interactive button support #2039
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| import logging | ||
| from typing import Dict, Any | ||
|
|
||
| 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 | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interactive buttons are effectively broken due to missing sender contract. On Line 33, 🛠️ 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 🤖 Prompt for AI Agents |
||
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.
Remove unused
Dictimport.Dictis not used (Line 2), and this is already flagged by Flake8 (F401).✂️ Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Flake8 (7.3.0)
[error] 2-2: 'typing.Dict' imported but unused
(F401)
🤖 Prompt for AI Agents