feat: add OpenClaw message-tool payload adapter / 新增 OpenClaw message-tool payload adapter
This commit is contained in:
42
src/adapters/openclaw-message-tool.ts
Normal file
42
src/adapters/openclaw-message-tool.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { buildTelegramReplyEndPayload } from "../telegram/outbound-payload.js"
|
||||
|
||||
export type OpenClawTelegramMessageToolPayload = {
|
||||
action: "send"
|
||||
channel: "telegram"
|
||||
target: string
|
||||
message: string
|
||||
presentation: {
|
||||
blocks: Array<
|
||||
| { type: "text"; text: string }
|
||||
| {
|
||||
type: "buttons"
|
||||
buttons: Array<{
|
||||
label: string
|
||||
value: string
|
||||
}>
|
||||
}
|
||||
>
|
||||
}
|
||||
}
|
||||
|
||||
export function buildOpenClawTelegramMessageToolPayload(target: string, text: string): OpenClawTelegramMessageToolPayload {
|
||||
const payload = buildTelegramReplyEndPayload(text)
|
||||
return {
|
||||
action: "send",
|
||||
channel: "telegram",
|
||||
target,
|
||||
message: payload.text,
|
||||
presentation: {
|
||||
blocks: [
|
||||
{ type: "text", text: payload.text },
|
||||
{
|
||||
type: "buttons",
|
||||
buttons: payload.buttons[0].map((button) => ({
|
||||
label: button.text,
|
||||
value: button.callback_data,
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
}
|
||||
16
tests/openclaw-message-tool.test.mjs
Normal file
16
tests/openclaw-message-tool.test.mjs
Normal file
@@ -0,0 +1,16 @@
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
|
||||
import { buildOpenClawTelegramMessageToolPayload } from "../src/adapters/openclaw-message-tool.ts"
|
||||
|
||||
test("buildOpenClawTelegramMessageToolPayload creates Telegram send payload with text and button presentation", () => {
|
||||
const payload = buildOpenClawTelegramMessageToolPayload("864811879", "hello")
|
||||
assert.equal(payload.action, "send")
|
||||
assert.equal(payload.channel, "telegram")
|
||||
assert.equal(payload.target, "864811879")
|
||||
assert.equal(payload.message, "hello")
|
||||
assert.equal(payload.presentation.blocks[0].type, "text")
|
||||
assert.equal(payload.presentation.blocks[1].type, "buttons")
|
||||
assert.equal(payload.presentation.blocks[1].buttons[0].value, "rec:continue")
|
||||
assert.equal(payload.presentation.blocks[1].buttons[1].value, "rec:stop")
|
||||
})
|
||||
Reference in New Issue
Block a user