import { persistOpenClawReplyEndState } from "./openclaw-state-file.ts" import { buildTelegramCallbackResolution } from "../runtime/openclaw-telegram-callback-actions.ts" import { normalizeTelegramCallback } from "../core/callback-contract.ts" export type OpenClawTelegramInteractiveContext = { callback: { data: string messageId: string chatId: string } conversationId: string sessionKey: string | null callbackId: string respond: { editButtons: (input: { buttons: { text: string; callback_data: string }[][] }) => Promise | void reply: (input: { text: string }) => Promise | void } } export async function handleOpenClawTelegramReplyEndInteraction(baseDir: string, ctx: OpenClawTelegramInteractiveContext): Promise { const normalized = normalizeTelegramCallback({ callbackData: ctx.callback.data, conversationId: ctx.conversationId, sessionKey: ctx.sessionKey, sourceMessageId: ctx.callback.messageId, sourceCallbackId: ctx.callbackId, timestamp: new Date().toISOString(), }) if (!normalized) { return false } persistOpenClawReplyEndState(baseDir, normalized) const resolution = buildTelegramCallbackResolution(normalized.choice) await ctx.respond.editButtons({ buttons: resolution.buttons }) await ctx.respond.reply({ text: resolution.acknowledgement }) return true }