Files
openclaw/extensions/telegram/src/session-transcript-context.ts
mikasa ec7a548062 fix #95378: https://github.com/openclaw/openclaw/issues/95378 (#95390)
* fix(telegram): use session transcript for direct context

* fix(telegram): account for proof and SDK checks

* fix(telegram): address review findings

* fix(telegram): tighten session transcript context

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-06-22 04:29:44 +05:30

51 lines
1.7 KiB
TypeScript

import {
readRecentUserAssistantTextForSession,
type SessionRecentConversationText,
} from "openclaw/plugin-sdk/session-store-runtime";
export type TelegramSessionTranscriptPromptMessage = {
message_id?: string;
sender: string;
timestamp_ms?: number;
body: string;
source_channel?: string;
};
export type BuildTelegramSessionTranscriptPromptMessagesParams = {
agentId: string;
beforeTimestampMs?: number;
limit: number;
minTimestampMs?: number;
sessionKey: string;
storePath?: string;
};
function toSessionTranscriptPromptMessage(
entry: SessionRecentConversationText,
): TelegramSessionTranscriptPromptMessage {
const sender = entry.role === "assistant" ? "OpenClaw" : "User";
return {
...(entry.id ? { message_id: `session:${entry.id}` } : {}),
sender: entry.sourceChannel ? `${sender} (${entry.sourceChannel})` : sender,
...(entry.timestamp !== undefined ? { timestamp_ms: entry.timestamp } : {}),
body: entry.text,
...(entry.sourceChannel ? { source_channel: entry.sourceChannel } : {}),
};
}
export async function buildTelegramSessionTranscriptPromptMessages(
params: BuildTelegramSessionTranscriptPromptMessagesParams,
): Promise<TelegramSessionTranscriptPromptMessage[]> {
const entries = await readRecentUserAssistantTextForSession({
agentId: params.agentId,
sessionKey: params.sessionKey,
limit: params.limit,
...(params.storePath !== undefined ? { storePath: params.storePath } : {}),
...(params.beforeTimestampMs !== undefined
? { beforeTimestampMs: params.beforeTimestampMs }
: {}),
...(params.minTimestampMs !== undefined ? { minTimestampMs: params.minTimestampMs } : {}),
});
return entries.map(toSessionTranscriptPromptMessage);
}