MCPcopy Index your code
hub / github.com/CopilotKit/CopilotKit / deriveConversationKey

Function deriveConversationKey

packages/bot-telegram/src/interaction.ts:35–61  ·  view source on GitHub ↗
(
  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,
)

Source from the content-addressed store, hash-verified

33 * clicking user's id so the key matches ingress).
34 */
35export 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.

Callers 5

handleTurnFunction · 0.85
attachTelegramListenerFunction · 0.85
decodeReactionFunction · 0.85
decodeInteractionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…