feat: add OpenClaw interactive-handler adapter / 新增 OpenClaw interactive-handler adapter
This commit is contained in:
58
tests/openclaw-interactive-handler.test.mjs
Normal file
58
tests/openclaw-interactive-handler.test.mjs
Normal 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)
|
||||
})
|
||||
Reference in New Issue
Block a user