feat: add OpenClaw interactive-handler adapter / 新增 OpenClaw interactive-handler adapter
This commit is contained in:
40
src/adapters/openclaw-interactive-handler.ts
Normal file
40
src/adapters/openclaw-interactive-handler.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user