feat: add OpenClaw interactive-handler adapter / 新增 OpenClaw interactive-handler adapter

This commit is contained in:
Alice (OpenClaw)
2026-05-14 08:37:30 +08:00
parent 6282667297
commit 9ce2b09f71
2 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import test from "node:test"
import assert from "node:assert/strict"
import fs from "node:fs"
import os from "node:os"
import path from "node:path"
import { handleOpenClawTelegramReplyEndInteraction } from "../src/adapters/openclaw-interactive-handler.ts"
test("openclaw interactive handler persists state and emits response actions", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "reply-end-interactive-"))
const calls = []
const handled = await handleOpenClawTelegramReplyEndInteraction(tempDir, {
callback: {
data: "rec:continue",
messageId: "77",
chatId: "864811879",
},
conversationId: "864811879",
sessionKey: "agent:main:main",
callbackId: "cb-77",
respond: {
editButtons: async (input) => {
calls.push(["editButtons", input])
},
reply: async (input) => {
calls.push(["reply", input])
},
},
})
assert.equal(handled, true)
const statePath = path.join(tempDir, "reply-end-controls.json")
const stored = JSON.parse(fs.readFileSync(statePath, "utf-8"))
assert.equal(stored["864811879"].lastChoice, "continue")
assert.equal(calls[0][0], "editButtons")
assert.equal(calls[1][0], "reply")
})
test("openclaw interactive handler ignores unrelated callback data", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "reply-end-interactive-"))
const handled = await handleOpenClawTelegramReplyEndInteraction(tempDir, {
callback: {
data: "other:value",
messageId: "78",
chatId: "864811879",
},
conversationId: "864811879",
sessionKey: "agent:main:main",
callbackId: "cb-78",
respond: {
editButtons: async () => {},
reply: async () => {},
},
})
assert.equal(handled, false)
})