From 62bbe3bd18cdc82e0eea397f72ba2673d9654d84 Mon Sep 17 00:00:00 2001 From: "Alice (OpenClaw)" Date: Thu, 14 May 2026 09:27:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20OpenClaw=20plugin=20skeleton=20/?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=20OpenClaw=20plugin=20skeleton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/adapters/openclaw-plugin-skeleton.ts | 33 +++++++++++++++++++ tests/openclaw-plugin-skeleton.test.mjs | 40 ++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/adapters/openclaw-plugin-skeleton.ts create mode 100644 tests/openclaw-plugin-skeleton.test.mjs diff --git a/src/adapters/openclaw-plugin-skeleton.ts b/src/adapters/openclaw-plugin-skeleton.ts new file mode 100644 index 0000000..5abc454 --- /dev/null +++ b/src/adapters/openclaw-plugin-skeleton.ts @@ -0,0 +1,33 @@ +import { buildOpenClawTelegramMessageToolPayload } from "./openclaw-message-tool.js" +import { handleOpenClawTelegramReplyEndInteraction } from "./openclaw-interactive-handler.ts" + +export type OpenClawInteractiveRegistration = { + namespace: string + handler: (ctx: { + 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 + } + }) => Promise +} + +export function buildOpenClawReplyEndPresentation(target: string, text: string) { + return buildOpenClawTelegramMessageToolPayload(target, text) +} + +export function createOpenClawReplyEndInteractiveRegistration(baseDir: string): OpenClawInteractiveRegistration { + return { + namespace: "rec", + handler: async (ctx) => { + return await handleOpenClawTelegramReplyEndInteraction(baseDir, ctx) + }, + } +} diff --git a/tests/openclaw-plugin-skeleton.test.mjs b/tests/openclaw-plugin-skeleton.test.mjs new file mode 100644 index 0000000..0f6146c --- /dev/null +++ b/tests/openclaw-plugin-skeleton.test.mjs @@ -0,0 +1,40 @@ +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 { buildOpenClawReplyEndPresentation, createOpenClawReplyEndInteractiveRegistration } from "../src/adapters/openclaw-plugin-skeleton.ts" + +test("plugin skeleton builds OpenClaw message-tool presentation", () => { + const payload = buildOpenClawReplyEndPresentation("864811879", "hello") + assert.equal(payload.channel, "telegram") + assert.equal(payload.target, "864811879") + assert.equal(payload.presentation.blocks[1].type, "buttons") +}) + +test("plugin skeleton interactive registration handles continue callback", async () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "reply-end-plugin-skel-")) + const calls = [] + const registration = createOpenClawReplyEndInteractiveRegistration(tempDir) + assert.equal(registration.namespace, "rec") + + const handled = await registration.handler({ + callback: { + data: "rec:continue", + messageId: "99", + chatId: "864811879", + }, + conversationId: "864811879", + sessionKey: "agent:main:main", + callbackId: "cb-99", + respond: { + editButtons: async (input) => calls.push(["editButtons", input]), + reply: async (input) => calls.push(["reply", input]), + }, + }) + + assert.equal(handled, true) + assert.equal(calls[0][0], "editButtons") + assert.equal(calls[1][0], "reply") +})