52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from dataclasses import dataclass
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class ActionThreadBehavior:
|
||
|
|
reply_in_thread: bool = True
|
||
|
|
broadcast_to_channel: bool = False
|
||
|
|
use_thread_ts: str = ""
|
||
|
|
|
||
|
|
@property
|
||
|
|
def should_broadcast(self) -> bool:
|
||
|
|
return self.broadcast_to_channel
|
||
|
|
|
||
|
|
def resolve_ts(self, parent_ts: str = "", fallback_ts: str = "") -> str:
|
||
|
|
return self.use_thread_ts or parent_ts or fallback_ts
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_action_thread_behavior(
|
||
|
|
event: dict[str, Any],
|
||
|
|
*,
|
||
|
|
channel: str = "",
|
||
|
|
thread_ts: str = "",
|
||
|
|
) -> ActionThreadBehavior:
|
||
|
|
is_in_thread = bool(thread_ts)
|
||
|
|
|
||
|
|
broadcast = False
|
||
|
|
if event.get("broadcast_reply"):
|
||
|
|
broadcast = True
|
||
|
|
|
||
|
|
return ActionThreadBehavior(
|
||
|
|
reply_in_thread=is_in_thread,
|
||
|
|
broadcast_to_channel=broadcast,
|
||
|
|
use_thread_ts=thread_ts if is_in_thread else "",
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_button_action_threading(
|
||
|
|
action_payload: dict[str, Any],
|
||
|
|
channel: str,
|
||
|
|
message: dict[str, Any],
|
||
|
|
) -> ActionThreadBehavior:
|
||
|
|
thread_ts = message.get("thread_ts", "")
|
||
|
|
|
||
|
|
return ActionThreadBehavior(
|
||
|
|
reply_in_thread=bool(thread_ts),
|
||
|
|
broadcast_to_channel=action_payload.get("broadcast_reply", False),
|
||
|
|
use_thread_ts=thread_ts,
|
||
|
|
)
|