@relaymessenger/openclaw-plugin 0.4.7-staging.4 → 0.4.7-staging.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/relay-v1.lock.json +5 -5
- package/dist/src/channel.js +1 -0
- package/dist/src/inbound.js +7 -8
- package/dist/src/outbound.js +11 -2
- package/package.json +2 -2
- package/src/channel.ts +4 -0
- package/src/inbound.ts +7 -8
- package/src/outbound.ts +12 -1
- package/src/types.ts +3 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"relayServer": {
|
|
3
3
|
"repository": "RelayMessenger/Relay-Server",
|
|
4
|
-
"commit": "
|
|
4
|
+
"commit": "1d5ccc3ebb1f6cbf5cc7732e9353a4cfb62703e7",
|
|
5
5
|
"openapiPath": "contracts/developer/openapi.yaml",
|
|
6
|
-
"sha256": "
|
|
6
|
+
"sha256": "379ba81f3bd4092bf65c445a730c396620a162a37fec775c0e382bf9edce2640"
|
|
7
7
|
},
|
|
8
8
|
"relaySdk": {
|
|
9
9
|
"package": "@relaymessenger/sdk",
|
|
10
|
-
"version": "0.3.6-staging.
|
|
11
|
-
"integrity": "sha512-
|
|
10
|
+
"version": "0.3.6-staging.5",
|
|
11
|
+
"integrity": "sha512-d3LOJaGz0tmJSuGQCVkAZVmSUkBI3vLspItsMlD7ZVL3FMTnR6EekmkPQZX+G2Mr17u0J5PzkjP2Wx17xDlnvw==",
|
|
12
12
|
"operationsSha256": "5c482165296df7d0634a0f57950936887b118e7159baf3bdabc42fce0d4fe6d8",
|
|
13
|
-
"workspaceOpenapiSha256": "
|
|
13
|
+
"workspaceOpenapiSha256": "379ba81f3bd4092bf65c445a730c396620a162a37fec775c0e382bf9edce2640",
|
|
14
14
|
"usedOperations": [
|
|
15
15
|
{
|
|
16
16
|
"method": "GET",
|
package/dist/src/channel.js
CHANGED
|
@@ -249,6 +249,7 @@ export const relayChannelPlugin = createChatChannelPlugin({
|
|
|
249
249
|
deliveryQueueId: ctx.deliveryQueueId,
|
|
250
250
|
deliveryPartIndex: ctx.deliveryPartIndex,
|
|
251
251
|
}),
|
|
252
|
+
onButtonsError: (error) => ctx.log?.warn?.(`relay: buttons block left as text: ${error}`),
|
|
252
253
|
...(ctx.onPlatformSendDispatch
|
|
253
254
|
? { onPlatformSendDispatch: ctx.onPlatformSendDispatch }
|
|
254
255
|
: {}),
|
package/dist/src/inbound.js
CHANGED
|
@@ -8,11 +8,8 @@ function renderPart(part) {
|
|
|
8
8
|
return `[Attachment: ${part.filename} (${part.mime_type})] ${part.url}`;
|
|
9
9
|
case "system":
|
|
10
10
|
return part.value;
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// nothing, again as the server does; its question is the text beside it.
|
|
14
|
-
case "button_reply":
|
|
15
|
-
return part.label;
|
|
11
|
+
// The agent's own buttons part reads as nothing, as on the server; its
|
|
12
|
+
// question is the text beside it. A tap arrives as ordinary text.
|
|
16
13
|
case "buttons":
|
|
17
14
|
return undefined;
|
|
18
15
|
}
|
|
@@ -70,9 +67,11 @@ export function buildRelayInboundFacts(event) {
|
|
|
70
67
|
...(event.data.reply_to?.message_id
|
|
71
68
|
? {
|
|
72
69
|
replyToId: event.data.reply_to.message_id,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
// The answer quotes the person's message, the one it answers (a bot's
|
|
71
|
+
// reply_to in Telegram and Discord names the person's message). A
|
|
72
|
+
// tap's reply_to names the agent's buttons part, which no reply may
|
|
73
|
+
// target, so this is also what keeps a tap answerable.
|
|
74
|
+
replyAnchorId: event.data.id,
|
|
76
75
|
}
|
|
77
76
|
: {}),
|
|
78
77
|
...(Number.isFinite(timestamp) ? { timestamp } : {}),
|
package/dist/src/outbound.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { Relay, RelayAPIError, } from "@relaymessenger/sdk";
|
|
2
|
+
import { partsWithButtons, Relay, RelayAPIError, splitButtons, } from "@relaymessenger/sdk";
|
|
3
3
|
export const RELAY_TEXT_CHUNK_LIMIT = 10_000;
|
|
4
4
|
const IDEMPOTENCY_KEY_MAX_LENGTH = 255;
|
|
5
5
|
export function createRelaySdkClient(account) {
|
|
@@ -17,11 +17,20 @@ export function deriveRelayIdempotencyKey(params) {
|
|
|
17
17
|
? raw
|
|
18
18
|
: `relay-openclaw:sha256:${createHash("sha256").update(raw).digest("hex")}`;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* OpenClaw hands the agent's words as text, so buttons ride in them as the
|
|
22
|
+
* SDK's fenced block, lifted here into the buttons part. A block that cannot
|
|
23
|
+
* be read stays in the words and is reported through `onButtonsError`.
|
|
24
|
+
*/
|
|
20
25
|
export async function sendRelayText(params) {
|
|
21
26
|
await params.onPlatformSendDispatch?.();
|
|
27
|
+
const { text, buttons, error } = splitButtons(params.text);
|
|
28
|
+
if (error)
|
|
29
|
+
params.onButtonsError?.(error);
|
|
22
30
|
return await params.relay.chats.messages.send(params.chatId, {
|
|
23
31
|
message: {
|
|
24
|
-
|
|
32
|
+
// Without a block the words go exactly as OpenClaw handed them.
|
|
33
|
+
parts: buttons ? partsWithButtons(text, buttons) : [{ type: "text", value: params.text }],
|
|
25
34
|
idempotency_key: params.idempotencyKey,
|
|
26
35
|
...(params.replyToId
|
|
27
36
|
? { reply_to: { message_id: params.replyToId } }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relaymessenger/openclaw-plugin",
|
|
3
|
-
"version": "0.4.7-staging.
|
|
3
|
+
"version": "0.4.7-staging.5",
|
|
4
4
|
"description": "Native Relay channel plugin for OpenClaw",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"prepack": "npm run build"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@relaymessenger/sdk": "0.3.6-staging.
|
|
40
|
+
"@relaymessenger/sdk": "0.3.6-staging.5"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^26.0.0",
|
package/src/channel.ts
CHANGED
|
@@ -329,6 +329,10 @@ export const relayChannelPlugin: ChannelPlugin<ResolvedRelayAccount> =
|
|
|
329
329
|
deliveryQueueId: ctx.deliveryQueueId,
|
|
330
330
|
deliveryPartIndex: ctx.deliveryPartIndex,
|
|
331
331
|
}),
|
|
332
|
+
onButtonsError: (error) =>
|
|
333
|
+
(ctx as { log?: { warn?: (message: string) => void } }).log?.warn?.(
|
|
334
|
+
`relay: buttons block left as text: ${error}`,
|
|
335
|
+
),
|
|
332
336
|
...(ctx.onPlatformSendDispatch
|
|
333
337
|
? { onPlatformSendDispatch: ctx.onPlatformSendDispatch }
|
|
334
338
|
: {}),
|
package/src/inbound.ts
CHANGED
|
@@ -17,11 +17,8 @@ function renderPart(part: MessagePartResponse): string | undefined {
|
|
|
17
17
|
return `[Attachment: ${part.filename} (${part.mime_type})] ${part.url}`;
|
|
18
18
|
case "system":
|
|
19
19
|
return part.value;
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// nothing, again as the server does; its question is the text beside it.
|
|
23
|
-
case "button_reply":
|
|
24
|
-
return part.label;
|
|
20
|
+
// The agent's own buttons part reads as nothing, as on the server; its
|
|
21
|
+
// question is the text beside it. A tap arrives as ordinary text.
|
|
25
22
|
case "buttons":
|
|
26
23
|
return undefined;
|
|
27
24
|
}
|
|
@@ -93,9 +90,11 @@ export function buildRelayInboundFacts(
|
|
|
93
90
|
...(event.data.reply_to?.message_id
|
|
94
91
|
? {
|
|
95
92
|
replyToId: event.data.reply_to.message_id,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
// The answer quotes the person's message, the one it answers (a bot's
|
|
94
|
+
// reply_to in Telegram and Discord names the person's message). A
|
|
95
|
+
// tap's reply_to names the agent's buttons part, which no reply may
|
|
96
|
+
// target, so this is also what keeps a tap answerable.
|
|
97
|
+
replyAnchorId: event.data.id,
|
|
99
98
|
}
|
|
100
99
|
: {}),
|
|
101
100
|
...(Number.isFinite(timestamp) ? { timestamp } : {}),
|
package/src/outbound.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import {
|
|
3
|
+
partsWithButtons,
|
|
3
4
|
Relay,
|
|
4
5
|
RelayAPIError,
|
|
6
|
+
splitButtons,
|
|
5
7
|
type MessageSendResponse,
|
|
6
8
|
} from "@relaymessenger/sdk";
|
|
7
9
|
import type { ResolvedRelayAccount } from "./types.js";
|
|
@@ -32,6 +34,11 @@ export function deriveRelayIdempotencyKey(params: {
|
|
|
32
34
|
: `relay-openclaw:sha256:${createHash("sha256").update(raw).digest("hex")}`;
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
/**
|
|
38
|
+
* OpenClaw hands the agent's words as text, so buttons ride in them as the
|
|
39
|
+
* SDK's fenced block, lifted here into the buttons part. A block that cannot
|
|
40
|
+
* be read stays in the words and is reported through `onButtonsError`.
|
|
41
|
+
*/
|
|
35
42
|
export async function sendRelayText(params: {
|
|
36
43
|
relay: Pick<Relay, "chats">;
|
|
37
44
|
chatId: string;
|
|
@@ -40,13 +47,17 @@ export async function sendRelayText(params: {
|
|
|
40
47
|
idempotencyKey: string;
|
|
41
48
|
signal?: AbortSignal;
|
|
42
49
|
onPlatformSendDispatch?: () => Promise<void>;
|
|
50
|
+
onButtonsError?: (error: string) => void;
|
|
43
51
|
}): Promise<MessageSendResponse> {
|
|
44
52
|
await params.onPlatformSendDispatch?.();
|
|
53
|
+
const { text, buttons, error } = splitButtons(params.text);
|
|
54
|
+
if (error) params.onButtonsError?.(error);
|
|
45
55
|
return await params.relay.chats.messages.send(
|
|
46
56
|
params.chatId,
|
|
47
57
|
{
|
|
48
58
|
message: {
|
|
49
|
-
|
|
59
|
+
// Without a block the words go exactly as OpenClaw handed them.
|
|
60
|
+
parts: buttons ? partsWithButtons(text, buttons) : [{ type: "text", value: params.text }],
|
|
50
61
|
idempotency_key: params.idempotencyKey,
|
|
51
62
|
...(params.replyToId
|
|
52
63
|
? { reply_to: { message_id: params.replyToId } }
|
package/src/types.ts
CHANGED
|
@@ -73,10 +73,9 @@ export type RelayInboundFacts = {
|
|
|
73
73
|
ownerHandle?: ChatHandle;
|
|
74
74
|
replyToId?: string;
|
|
75
75
|
/**
|
|
76
|
-
* The Message an outbound reply should quote
|
|
77
|
-
*
|
|
78
|
-
* agent's
|
|
79
|
-
* the person quoted.
|
|
76
|
+
* The Message an outbound reply should quote when the person's Message
|
|
77
|
+
* was itself a reply: the person's Message. A tap's reply_to names the
|
|
78
|
+
* agent's buttons part, which no reply may target.
|
|
80
79
|
*/
|
|
81
80
|
replyAnchorId?: string;
|
|
82
81
|
timestamp?: number;
|