mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-11 03:36:02 +00:00
* 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>
51 lines
1.7 KiB
TypeScript
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);
|
|
}
|