feat: add OpenClaw Telegram bridge helper / 新增 OpenClaw Telegram bridge helper
This commit is contained in:
23
src/runtime/openclaw-telegram-bridge.ts
Normal file
23
src/runtime/openclaw-telegram-bridge.ts
Normal 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)
|
||||||
|
}
|
||||||
35
tests/runtime-bridge.test.mjs
Normal file
35
tests/runtime-bridge.test.mjs
Normal 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/)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user