| 208 | if (value.channelId !== undefined) return `channel:${idToString(value.channelId)}`; |
| 209 | try { |
| 210 | return JSON.stringify(value, (_key, item) => |
| 211 | typeof item === "bigint" ? item.toString() : item |
| 212 | ); |
| 213 | } catch { |
| 214 | return String(value); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | function getSessionKey(msg: Api.Message): string { |
| 219 | const peerKey = idToString((msg as any).chatId ?? msg.peerId) || "unknown-peer"; |
| 220 | const userKey = |
| 221 | idToString((msg as any).senderId ?? (msg as any).fromId) || "unknown-user"; |
| 222 | return `${peerKey}:${userKey}`; |
| 223 | } |
| 224 | |
| 225 | function parseIndex(text?: string): number | null { |
| 226 | if (!text || !/^\d+$/.test(text)) return null; |
| 227 | const index = Number.parseInt(text, 10); |