35 lines
998 B
Python
35 lines
998 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
from yuxi.channels.models import ChatType
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_chat_id(channel: str, event: dict[str, Any]) -> str:
|
||
|
|
channel_type = event.get("channel_type", "")
|
||
|
|
if channel.startswith("D") or channel_type == "im":
|
||
|
|
user = event.get("user", "unknown")
|
||
|
|
return f"dm_{user}"
|
||
|
|
return f"channel_{channel}"
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_chat_type(channel: str, event: dict[str, Any]) -> ChatType:
|
||
|
|
if channel.startswith("D"):
|
||
|
|
return ChatType.DIRECT
|
||
|
|
channel_type = event.get("channel_type", "")
|
||
|
|
if channel_type == "im":
|
||
|
|
return ChatType.DIRECT
|
||
|
|
thread_ts = event.get("thread_ts", "")
|
||
|
|
ts = event.get("ts", "")
|
||
|
|
if thread_ts and thread_ts != ts:
|
||
|
|
return ChatType.THREAD
|
||
|
|
return ChatType.CHANNEL
|
||
|
|
|
||
|
|
|
||
|
|
def extract_thread_ts(event: dict[str, Any]) -> str | None:
|
||
|
|
thread_ts = event.get("thread_ts")
|
||
|
|
ts = event.get("ts")
|
||
|
|
if thread_ts and thread_ts != ts:
|
||
|
|
return thread_ts
|
||
|
|
return None
|