From ae096bcbc208a5e8706f8df3bdddcb1b2e6e4b98 Mon Sep 17 00:00:00 2001 From: "Alice (OpenClaw)" Date: Wed, 13 May 2026 12:29:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20OpenClaw=20Telegram=20bridge=20he?= =?UTF-8?q?lper=20/=20=E6=96=B0=E5=A2=9E=20OpenClaw=20Telegram=20bridge=20?= =?UTF-8?q?helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/runtime/openclaw-telegram-bridge.ts | 23 ++++++++++++++++ tests/runtime-bridge.test.mjs | 35 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/runtime/openclaw-telegram-bridge.ts create mode 100644 tests/runtime-bridge.test.mjs diff --git a/src/runtime/openclaw-telegram-bridge.ts b/src/runtime/openclaw-telegram-bridge.ts new file mode 100644 index 0000000..a1e1f1c --- /dev/null +++ b/src/runtime/openclaw-telegram-bridge.ts @@ -0,0 +1,23 @@ +import type { ReplyEndChoice, ReplyEndState } from "../types.js" +import { + applyStopStateToInboundText, + buildDefaultReplyEndButtons, + buildReplyEndAcknowledgement, + buildResolvedReplyEndButtons, +} from "./openclaw-telegram-poc.js" + +export function buildTelegramReplyEndButtonsForReply() { + return buildDefaultReplyEndButtons() +} + +export function buildTelegramReplyEndButtonsForResolvedChoice(choice: ReplyEndChoice) { + return buildResolvedReplyEndButtons(choice) +} + +export function buildTelegramReplyEndAck(choice: ReplyEndChoice) { + return buildReplyEndAcknowledgement(choice) +} + +export function applyTelegramReplyEndStopPolicy(text: string, state: ReplyEndState | null) { + return applyStopStateToInboundText(text, state) +} diff --git a/tests/runtime-bridge.test.mjs b/tests/runtime-bridge.test.mjs new file mode 100644 index 0000000..2bd04a6 --- /dev/null +++ b/tests/runtime-bridge.test.mjs @@ -0,0 +1,35 @@ +import test from "node:test" +import assert from "node:assert/strict" + +import { + applyTelegramReplyEndStopPolicy, + buildTelegramReplyEndAck, + buildTelegramReplyEndButtonsForReply, + buildTelegramReplyEndButtonsForResolvedChoice, +} from "../src/runtime/openclaw-telegram-bridge.ts" + +test("bridge exposes default buttons", () => { + const rows = buildTelegramReplyEndButtonsForReply() + assert.equal(rows[0][0].callback_data, "rec:continue") + assert.equal(rows[0][1].callback_data, "rec:stop") +}) + +test("bridge exposes resolved button state", () => { + const rows = buildTelegramReplyEndButtonsForResolvedChoice("stop") + assert.match(rows[0][1].text, /^⏹/) +}) + +test("bridge exposes ack text", () => { + assert.equal(buildTelegramReplyEndAck("continue"), "reply-end-controls: continue received") +}) + +test("bridge applies stop policy", () => { + const out = applyTelegramReplyEndStopPolicy("hello", { + lastChoice: "stop", + lastChoiceAt: "2026-05-13T00:00:00Z", + sourceMessageId: "1", + sourceCallbackId: "cb-1", + active: true, + }) + assert.match(out, /reply-end-controls Stop/) +})