feat: add OpenClaw Telegram bridge helper / 新增 OpenClaw Telegram bridge helper

This commit is contained in:
Alice (OpenClaw)
2026-05-13 12:29:07 +08:00
parent bd1da4c0da
commit ae096bcbc2
2 changed files with 58 additions and 0 deletions

View File

@@ -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)
}

View File

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