(
message: {
message_id: number;
message_thread_id?: number;
chat: { id: number | string; type: string; is_forum?: boolean };
reply_to_message?: { message_id: number };
from?: { id: number };
},
userId?: number,
)
| 33 | * clicking user's id so the key matches ingress). |
| 34 | */ |
| 35 | export function deriveConversationKey( |
| 36 | message: { |
| 37 | message_id: number; |
| 38 | message_thread_id?: number; |
| 39 | chat: { id: number | string; type: string; is_forum?: boolean }; |
| 40 | reply_to_message?: { message_id: number }; |
| 41 | from?: { id: number }; |
| 42 | }, |
| 43 | userId?: number, |
| 44 | ): ConversationKey { |
| 45 | const { chat } = message; |
| 46 | const chatId = String(chat.id); |
| 47 | |
| 48 | if (chat.type === "private") { |
| 49 | return { chatId, scope: DM_SCOPE }; |
| 50 | } |
| 51 | |
| 52 | // Treat message_thread_id as a forum topic ONLY in forum supergroups. In a |
| 53 | // regular (non-forum) supergroup Telegram also sets message_thread_id on any |
| 54 | // REPLY message (it doubles as the reply-thread id), so keying off it there |
| 55 | // would defeat per-user keying (each reply would spawn a new conversation). |
| 56 | if (message.message_thread_id !== undefined && message.chat?.is_forum) { |
| 57 | return { chatId, scope: `topic:${message.message_thread_id}` }; |
| 58 | } |
| 59 | |
| 60 | return { chatId, scope: `user:${userId ?? message.from?.id ?? "unknown"}` }; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Map a Telegram `from` user to a PlatformUser. |
no outgoing calls
no test coverage detected
searching dependent graphs…