refactor: add patch contract helper / 新增 patch contract helper
This commit is contained in:
26
src/runtime/openclaw-telegram-patch-contract.ts
Normal file
26
src/runtime/openclaw-telegram-patch-contract.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import type { ReplyEndChoice, TelegramInlineButton } from "../types.js"
|
||||||
|
import { buildTelegramReplyEndAck, buildTelegramReplyEndButtonsForReply, buildTelegramReplyEndButtonsForResolvedChoice } from "./openclaw-telegram-bridge.js"
|
||||||
|
|
||||||
|
export type OpenClawTelegramPatchContract = {
|
||||||
|
defaultButtons: TelegramInlineButton[][]
|
||||||
|
resolved: Record<ReplyEndChoice, {
|
||||||
|
buttons: TelegramInlineButton[][]
|
||||||
|
acknowledgement: string
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildOpenClawTelegramPatchContract(): OpenClawTelegramPatchContract {
|
||||||
|
return {
|
||||||
|
defaultButtons: buildTelegramReplyEndButtonsForReply(),
|
||||||
|
resolved: {
|
||||||
|
continue: {
|
||||||
|
buttons: buildTelegramReplyEndButtonsForResolvedChoice("continue"),
|
||||||
|
acknowledgement: buildTelegramReplyEndAck("continue"),
|
||||||
|
},
|
||||||
|
stop: {
|
||||||
|
buttons: buildTelegramReplyEndButtonsForResolvedChoice("stop"),
|
||||||
|
acknowledgement: buildTelegramReplyEndAck("stop"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
14
tests/runtime-patch-contract.test.mjs
Normal file
14
tests/runtime-patch-contract.test.mjs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import test from "node:test"
|
||||||
|
import assert from "node:assert/strict"
|
||||||
|
|
||||||
|
import { buildOpenClawTelegramPatchContract } from "../src/runtime/openclaw-telegram-patch-contract.ts"
|
||||||
|
|
||||||
|
test("patch contract exposes default and resolved callback behavior from shared repo-side logic", () => {
|
||||||
|
const contract = buildOpenClawTelegramPatchContract()
|
||||||
|
assert.equal(contract.defaultButtons[0][0].callback_data, "rec:continue")
|
||||||
|
assert.equal(contract.defaultButtons[0][1].callback_data, "rec:stop")
|
||||||
|
assert.match(contract.resolved.continue.buttons[0][0].text, /^✅/)
|
||||||
|
assert.match(contract.resolved.stop.buttons[0][1].text, /^⏹/)
|
||||||
|
assert.equal(contract.resolved.continue.acknowledgement, "reply-end-controls: continue received")
|
||||||
|
assert.equal(contract.resolved.stop.acknowledgement, "reply-end-controls: stop received")
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user