From c1eeda36185c6f649fa9b25c02889cc55a5c7676 Mon Sep 17 00:00:00 2001 From: "Alice (OpenClaw)" Date: Wed, 13 May 2026 16:48:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20add=20patch=20contract=20helper=20/?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=20patch=20contract=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openclaw-telegram-patch-contract.ts | 26 +++++++++++++++++++ tests/runtime-patch-contract.test.mjs | 14 ++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/runtime/openclaw-telegram-patch-contract.ts create mode 100644 tests/runtime-patch-contract.test.mjs diff --git a/src/runtime/openclaw-telegram-patch-contract.ts b/src/runtime/openclaw-telegram-patch-contract.ts new file mode 100644 index 0000000..d5f7180 --- /dev/null +++ b/src/runtime/openclaw-telegram-patch-contract.ts @@ -0,0 +1,26 @@ +import type { ReplyEndChoice, TelegramInlineButton } from "../types.js" +import { buildTelegramReplyEndAck, buildTelegramReplyEndButtonsForReply, buildTelegramReplyEndButtonsForResolvedChoice } from "./openclaw-telegram-bridge.js" + +export type OpenClawTelegramPatchContract = { + defaultButtons: TelegramInlineButton[][] + resolved: Record +} + +export function buildOpenClawTelegramPatchContract(): OpenClawTelegramPatchContract { + return { + defaultButtons: buildTelegramReplyEndButtonsForReply(), + resolved: { + continue: { + buttons: buildTelegramReplyEndButtonsForResolvedChoice("continue"), + acknowledgement: buildTelegramReplyEndAck("continue"), + }, + stop: { + buttons: buildTelegramReplyEndButtonsForResolvedChoice("stop"), + acknowledgement: buildTelegramReplyEndAck("stop"), + }, + }, + } +} diff --git a/tests/runtime-patch-contract.test.mjs b/tests/runtime-patch-contract.test.mjs new file mode 100644 index 0000000..c2518b4 --- /dev/null +++ b/tests/runtime-patch-contract.test.mjs @@ -0,0 +1,14 @@ +import test from "node:test" +import assert from "node:assert/strict" + +import { buildOpenClawTelegramPatchContract } from "../src/runtime/openclaw-telegram-patch-contract.ts" + +test("patch contract exposes default and resolved callback behavior from shared repo-side logic", () => { + const contract = buildOpenClawTelegramPatchContract() + assert.equal(contract.defaultButtons[0][0].callback_data, "rec:continue") + assert.equal(contract.defaultButtons[0][1].callback_data, "rec:stop") + assert.match(contract.resolved.continue.buttons[0][0].text, /^✅/) + assert.match(contract.resolved.stop.buttons[0][1].text, /^⏹/) + assert.equal(contract.resolved.continue.acknowledgement, "reply-end-controls: continue received") + assert.equal(contract.resolved.stop.acknowledgement, "reply-end-controls: stop received") +})