@relaymessenger/openclaw-plugin 0.4.7-staging.3 → 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.
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "relayServer": {
3
3
  "repository": "RelayMessenger/Relay-Server",
4
- "commit": "78d7991c7b8a615302ab30d727503779755df3ab",
4
+ "commit": "1d5ccc3ebb1f6cbf5cc7732e9353a4cfb62703e7",
5
5
  "openapiPath": "contracts/developer/openapi.yaml",
6
- "sha256": "1d790da998a8dfc26cffc098def76d85b8275af7a343148df8e78c486cd02849"
6
+ "sha256": "379ba81f3bd4092bf65c445a730c396620a162a37fec775c0e382bf9edce2640"
7
7
  },
8
8
  "relaySdk": {
9
9
  "package": "@relaymessenger/sdk",
10
- "version": "0.3.6-staging.3",
11
- "integrity": "sha512-yT5/q4alxyFPPmrOh3MqVk9i+55ZPyiLFPX4K4QGeqQsI8/qNt5GCaNVBGewD/rq6Zlw7sfeDqR9P/9leMfPwg==",
12
- "operationsSha256": "a7c3367841e1f7803ff4a040586e30a6347d80548999015503f18d8e32f47b40",
13
- "workspaceOpenapiSha256": "1d790da998a8dfc26cffc098def76d85b8275af7a343148df8e78c486cd02849",
10
+ "version": "0.3.6-staging.5",
11
+ "integrity": "sha512-d3LOJaGz0tmJSuGQCVkAZVmSUkBI3vLspItsMlD7ZVL3FMTnR6EekmkPQZX+G2Mr17u0J5PzkjP2Wx17xDlnvw==",
12
+ "operationsSha256": "5c482165296df7d0634a0f57950936887b118e7159baf3bdabc42fce0d4fe6d8",
13
+ "workspaceOpenapiSha256": "379ba81f3bd4092bf65c445a730c396620a162a37fec775c0e382bf9edce2640",
14
14
  "usedOperations": [
15
15
  {
16
16
  "method": "GET",
@@ -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
  : {}),
@@ -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
- // A tap reads as the label the person chose: the same text the server
12
- // derives for a button_reply. The agent's own buttons part reads as
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
- replyAnchorId: event.data.parts.some((part) => part.type === "button_reply")
74
- ? event.data.id
75
- : event.data.reply_to.message_id,
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 } : {}),
@@ -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
- parts: [{ type: "text", value: params.text }],
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",
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.3"
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
- // A tap reads as the label the person chose: the same text the server
21
- // derives for a button_reply. The agent's own buttons part reads as
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
- replyAnchorId: event.data.parts.some((part) => part.type === "button_reply")
97
- ? event.data.id
98
- : event.data.reply_to.message_id,
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
- parts: [{ type: "text", value: params.text }],
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. A tap's reply_to names the
77
- * agent's buttons part, which only a button_reply may target, so the
78
- * agent's answer quotes the tap itself; every other Message quotes what
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;