From cd2df025a7bad00f7d0fb70e6152a676c6dee046 Mon Sep 17 00:00:00 2001 From: "Alice (OpenClaw)" Date: Wed, 13 May 2026 15:07:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20extract=20callback=20resolution=20h?= =?UTF-8?q?elper=20/=20=E6=8A=BD=E5=87=BA=20callback=20resolution=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openclaw-telegram-callback-actions.ts | 17 +++++++++++++++++ tests/runtime-callback-actions.test.mjs | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/runtime/openclaw-telegram-callback-actions.ts create mode 100644 tests/runtime-callback-actions.test.mjs diff --git a/src/runtime/openclaw-telegram-callback-actions.ts b/src/runtime/openclaw-telegram-callback-actions.ts new file mode 100644 index 0000000..25c0d46 --- /dev/null +++ b/src/runtime/openclaw-telegram-callback-actions.ts @@ -0,0 +1,17 @@ +import type { ReplyEndChoice, TelegramInlineButton } from "../types.js" +import { buildReplyEndAcknowledgement } from "./openclaw-telegram-poc.js" +import { buildTelegramReplyEndButtonsForResolvedChoice } from "./openclaw-telegram-bridge.js" + +export type TelegramCallbackResolution = { + choice: ReplyEndChoice + buttons: TelegramInlineButton[][] + acknowledgement: string +} + +export function buildTelegramCallbackResolution(choice: ReplyEndChoice): TelegramCallbackResolution { + return { + choice, + buttons: buildTelegramReplyEndButtonsForResolvedChoice(choice), + acknowledgement: buildReplyEndAcknowledgement(choice), + } +} diff --git a/tests/runtime-callback-actions.test.mjs b/tests/runtime-callback-actions.test.mjs new file mode 100644 index 0000000..4649863 --- /dev/null +++ b/tests/runtime-callback-actions.test.mjs @@ -0,0 +1,18 @@ +import test from "node:test" +import assert from "node:assert/strict" + +import { buildTelegramCallbackResolution } from "../src/runtime/openclaw-telegram-callback-actions.ts" + +test("callback resolution for continue includes resolved buttons and ack", () => { + const result = buildTelegramCallbackResolution("continue") + assert.equal(result.choice, "continue") + assert.equal(result.acknowledgement, "reply-end-controls: continue received") + assert.match(result.buttons[0][0].text, /^✅/) +}) + +test("callback resolution for stop includes resolved buttons and ack", () => { + const result = buildTelegramCallbackResolution("stop") + assert.equal(result.choice, "stop") + assert.equal(result.acknowledgement, "reply-end-controls: stop received") + assert.match(result.buttons[0][1].text, /^⏹/) +})