feat: add reusable Telegram PoC helper module / 新增可重用 Telegram PoC helper 模組

This commit is contained in:
Alice (OpenClaw)
2026-05-13 12:02:48 +08:00
parent 900ea7b93f
commit bd1da4c0da
2 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import test from "node:test"
import assert from "node:assert/strict"
import {
applyStopStateToInboundText,
buildDefaultReplyEndButtons,
buildReplyEndAcknowledgement,
buildResolvedReplyEndButtons,
} from "../src/runtime/openclaw-telegram-poc.ts"
test("default reply-end buttons contain continue and stop", () => {
const buttons = buildDefaultReplyEndButtons()
assert.equal(buttons[0][0].callback_data, "rec:continue")
assert.equal(buttons[0][1].callback_data, "rec:stop")
})
test("resolved buttons mark continue selection", () => {
const buttons = buildResolvedReplyEndButtons("continue")
assert.match(buttons[0][0].text, /^✅/)
assert.doesNotMatch(buttons[0][1].text, /^⏹/)
})
test("resolved buttons mark stop selection", () => {
const buttons = buildResolvedReplyEndButtons("stop")
assert.match(buttons[0][1].text, /^⏹/)
assert.doesNotMatch(buttons[0][0].text, /^✅/)
})
test("acknowledgement text matches choice", () => {
assert.equal(buildReplyEndAcknowledgement("continue"), "reply-end-controls: continue received")
assert.equal(buildReplyEndAcknowledgement("stop"), "reply-end-controls: stop received")
})
test("stop state injects control text into inbound message", () => {
const result = applyStopStateToInboundText("我先這樣", {
lastChoice: "stop",
lastChoiceAt: "2026-05-13T00:00:00Z",
sourceMessageId: "1",
sourceCallbackId: "cb-1",
active: true,
})
assert.match(result, /reply-end-controls Stop/)
})
test("continue or null state leaves inbound text unchanged", () => {
const base = "我先這樣"
assert.equal(applyStopStateToInboundText(base, null), base)
assert.equal(
applyStopStateToInboundText(base, {
lastChoice: "continue",
lastChoiceAt: "2026-05-13T00:00:00Z",
sourceMessageId: "1",
sourceCallbackId: "cb-1",
active: true,
}),
base
)
})