refactor: extract callback resolution helper / 抽出 callback resolution helper
This commit is contained in:
17
src/runtime/openclaw-telegram-callback-actions.ts
Normal file
17
src/runtime/openclaw-telegram-callback-actions.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import type { ReplyEndChoice, TelegramInlineButton } from "../types.js"
|
||||||
|
import { buildReplyEndAcknowledgement } from "./openclaw-telegram-poc.js"
|
||||||
|
import { buildTelegramReplyEndButtonsForResolvedChoice } from "./openclaw-telegram-bridge.js"
|
||||||
|
|
||||||
|
export type TelegramCallbackResolution = {
|
||||||
|
choice: ReplyEndChoice
|
||||||
|
buttons: TelegramInlineButton[][]
|
||||||
|
acknowledgement: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildTelegramCallbackResolution(choice: ReplyEndChoice): TelegramCallbackResolution {
|
||||||
|
return {
|
||||||
|
choice,
|
||||||
|
buttons: buildTelegramReplyEndButtonsForResolvedChoice(choice),
|
||||||
|
acknowledgement: buildReplyEndAcknowledgement(choice),
|
||||||
|
}
|
||||||
|
}
|
||||||
18
tests/runtime-callback-actions.test.mjs
Normal file
18
tests/runtime-callback-actions.test.mjs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import test from "node:test"
|
||||||
|
import assert from "node:assert/strict"
|
||||||
|
|
||||||
|
import { buildTelegramCallbackResolution } from "../src/runtime/openclaw-telegram-callback-actions.ts"
|
||||||
|
|
||||||
|
test("callback resolution for continue includes resolved buttons and ack", () => {
|
||||||
|
const result = buildTelegramCallbackResolution("continue")
|
||||||
|
assert.equal(result.choice, "continue")
|
||||||
|
assert.equal(result.acknowledgement, "reply-end-controls: continue received")
|
||||||
|
assert.match(result.buttons[0][0].text, /^✅/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("callback resolution for stop includes resolved buttons and ack", () => {
|
||||||
|
const result = buildTelegramCallbackResolution("stop")
|
||||||
|
assert.equal(result.choice, "stop")
|
||||||
|
assert.equal(result.acknowledgement, "reply-end-controls: stop received")
|
||||||
|
assert.match(result.buttons[0][1].text, /^⏹/)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user