41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
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> | void
|
|
reply: (input: { text: string }) => Promise<void> | void
|
|
}
|
|
}
|
|
|
|
export async function handleOpenClawTelegramReplyEndInteraction(baseDir: string, ctx: OpenClawTelegramInteractiveContext): Promise<boolean> {
|
|
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
|
|
}
|