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/) +})