@relaymessenger/openclaw-plugin 0.4.7-staging.2 → 0.4.7-staging.21

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/README.md CHANGED
@@ -12,6 +12,26 @@ delivers events over its v1 WebSocket, and the plugin sends replies through
12
12
  the Relay v1 REST Message API. The plugin imports `@relaymessenger/sdk`; it
13
13
  does not contain a copied Relay client or protocol implementation.
14
14
 
15
+ ## Selection
16
+
17
+ End the final answer with a `selection` JSON fence after the question.
18
+ `BodyForAgent` carries structured response and rich-message JSON; `RawBody` and
19
+ `CommandBody` retain readable text. Stable values are not executable commands.
20
+
21
+ New human reply text is literal `• ` + each selected source label joined with
22
+ `\n`, followed by `selection_response` metadata in source-option order. Dispatch
23
+ with `selected_values` and the explicit source target, never label parsing.
24
+ Exact legacy comma-joined text remains a server compatibility input. The person
25
+ checks any number of options and submits them once; checking sends nothing, and
26
+ a person answers a given selection once. iOS may draw a checkmark in place of
27
+ each bullet and repeat the prompt's title, as presentation only.
28
+
29
+ ## Invoice
30
+
31
+ A verified agent ends the final answer with an `invoice` JSON fence holding a
32
+ Stripe checkout link; the words go first and the invoice follows as its own
33
+ Message.
34
+
15
35
  ## Install
16
36
 
17
37
  ```bash
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "relayServer": {
3
3
  "repository": "RelayMessenger/Relay-Server",
4
- "commit": "74b7603fff3025b6d591a35f9b6f8ed9e2383173",
4
+ "commit": "3b7425e5bafcf25cdc8ceff009715e4f06877d18",
5
5
  "openapiPath": "contracts/developer/openapi.yaml",
6
- "sha256": "9e92c51df654d6896e13a56e95b6a32ce0fbb4c77ed9c754603482890e84dfde"
6
+ "sha256": "3fb4873a3c09b7dade09012ecfc57acfef8cfb983b6b35fff9d320cf62bb3b00"
7
7
  },
8
8
  "relaySdk": {
9
9
  "package": "@relaymessenger/sdk",
10
- "version": "0.3.6-staging.2",
11
- "integrity": "sha512-v430wR76ud6ZyUCVqVW7RK0be2iT83NS1lQQAGKpbA4XINs0kC0zPI7SBEVFrQgq1HVmZF+zcqbjgAdeF+z9Ig==",
12
- "operationsSha256": "a7c3367841e1f7803ff4a040586e30a6347d80548999015503f18d8e32f47b40",
13
- "workspaceOpenapiSha256": "9e92c51df654d6896e13a56e95b6a32ce0fbb4c77ed9c754603482890e84dfde",
10
+ "version": "0.3.6-staging.22",
11
+ "integrity": "sha512-PnMaOgFgLcYD8xTspki0mGpySfVnkxC/EjnyTiNYioWuy+hJjtYzE3xwjJEnDYyJ6HlucDzZqmFCE07PgILCGw==",
12
+ "operationsSha256": "5d9cc3d0eed738d85deb3842b6efc0db5fe720299aa53e959f87e83c8585be36",
13
+ "workspaceOpenapiSha256": "3fb4873a3c09b7dade09012ecfc57acfef8cfb983b6b35fff9d320cf62bb3b00",
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: component block left as text: ${error}`),
252
253
  ...(ctx.onPlatformSendDispatch
253
254
  ? { onPlatformSendDispatch: ctx.onPlatformSendDispatch }
254
255
  : {}),
@@ -1,3 +1,4 @@
1
+ import { BUTTONS_GUIDANCE, BUTTONS_BLOCK_INSTRUCTION, INVOICE_BLOCK_INSTRUCTION, INVOICE_GUIDANCE, LINK_LINE_INSTRUCTION, SELECTION_GUIDANCE, SELECTION_BLOCK_INSTRUCTION, selectionReplyContext } from "@relaymessenger/sdk";
1
2
  import { buildChannelInboundEventContext, resolveChannelInboundRouteEnvelope, } from "openclaw/plugin-sdk/channel-inbound";
2
3
  import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
3
4
  import { bindIngressLifecycleToReplyOptions } from "openclaw/plugin-sdk/channel-outbound";
@@ -170,12 +171,16 @@ export async function dispatchRelayEvent(params) {
170
171
  reply: {
171
172
  to: facts.chatId,
172
173
  originatingTo: facts.chatId,
173
- ...(facts.replyToId ? { replyToId: facts.replyToId } : {}),
174
+ ...((facts.replyAnchorId ?? facts.replyToId)
175
+ ? { replyToId: facts.replyAnchorId ?? facts.replyToId }
176
+ : {}),
174
177
  },
175
178
  message: {
176
179
  inboundEventKind: "user_request",
177
180
  body,
178
- bodyForAgent: facts.text,
181
+ bodyForAgent: [facts.text, selectionReplyContext(facts.selection, facts.richMessage),
182
+ `${BUTTONS_BLOCK_INSTRUCTION} ${LINK_LINE_INSTRUCTION} ${BUTTONS_GUIDANCE} ${SELECTION_BLOCK_INSTRUCTION} ${SELECTION_GUIDANCE} ${INVOICE_BLOCK_INSTRUCTION} ${INVOICE_GUIDANCE}`,
183
+ ].filter(Boolean).join("\n\n"),
179
184
  rawBody: facts.text,
180
185
  commandBody: facts.text,
181
186
  },
@@ -1,3 +1,4 @@
1
+ import { selectionReply, selectionReplyContext } from "@relaymessenger/sdk";
1
2
  function renderPart(part) {
2
3
  switch (part.type) {
3
4
  case "text":
@@ -8,6 +9,12 @@ function renderPart(part) {
8
9
  return `[Attachment: ${part.filename} (${part.mime_type})] ${part.url}`;
9
10
  case "system":
10
11
  return part.value;
12
+ // The agent's own buttons part reads as nothing, as on the server; its
13
+ // question is the text beside it. A tap arrives as ordinary text.
14
+ case "buttons":
15
+ case "selection":
16
+ case "selection_response":
17
+ return undefined;
11
18
  }
12
19
  }
13
20
  export function renderRelayMessageParts(parts) {
@@ -37,7 +44,9 @@ export function buildRelayInboundFacts(event) {
37
44
  event.data.sender_handle.kind !== "agent")
38
45
  return null;
39
46
  const text = renderRelayMessageParts(event.data.parts);
40
- if (!text.trim())
47
+ const message = { parts: event.data.parts, ...(event.data.reply_to ? { reply_to: event.data.reply_to } : {}) };
48
+ const richMessage = selectionReplyContext(undefined, message) ? message : undefined;
49
+ if (!text.trim() && !richMessage)
41
50
  return null;
42
51
  const mentionHandles = event.data.parts.flatMap((part) => part.type === "text" &&
43
52
  typeof part.mention === "string" &&
@@ -46,7 +55,10 @@ export function buildRelayInboundFacts(event) {
46
55
  : []);
47
56
  const timestampValue = event.data.sent_at ?? event.created_at;
48
57
  const timestamp = Date.parse(timestampValue);
58
+ const selection = selectionReply(event.data.parts, event.data.reply_to);
49
59
  return {
60
+ ...(selection ? { selection } : {}),
61
+ ...(richMessage ? { richMessage } : {}),
50
62
  eventId: event.event_id,
51
63
  messageId: event.data.id,
52
64
  chatId: event.data.chat.id,
@@ -61,7 +73,14 @@ export function buildRelayInboundFacts(event) {
61
73
  ? { ownerHandle: event.data.chat.owner_handle }
62
74
  : {}),
63
75
  ...(event.data.reply_to?.message_id
64
- ? { replyToId: event.data.reply_to.message_id }
76
+ ? {
77
+ replyToId: event.data.reply_to.message_id,
78
+ // The answer quotes the person's message, the one it answers (a bot's
79
+ // reply_to in Telegram and Discord names the person's message). A
80
+ // tap's reply_to names the agent's buttons part, which no reply may
81
+ // target, so this is also what keeps a tap answerable.
82
+ replyAnchorId: event.data.id,
83
+ }
65
84
  : {}),
66
85
  ...(Number.isFinite(timestamp) ? { timestamp } : {}),
67
86
  };
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import { Relay, RelayAPIError, } from "@relaymessenger/sdk";
2
+ import { answerMessages, indexedIdempotencyKey, Relay, RelayAPIError, } 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,17 +17,35 @@ 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, and a link written
23
+ * alone on a line goes out as its own link Message. A block that cannot be
24
+ * read stays in the words and is reported through `onButtonsError`. Without
25
+ * a block or a link line the words go exactly as OpenClaw handed them, in one
26
+ * Message; the response is the first Message's, the one the reply anchors to.
27
+ */
20
28
  export async function sendRelayText(params) {
21
29
  await params.onPlatformSendDispatch?.();
22
- return await params.relay.chats.messages.send(params.chatId, {
23
- message: {
24
- parts: [{ type: "text", value: params.text }],
25
- idempotency_key: params.idempotencyKey,
26
- ...(params.replyToId
27
- ? { reply_to: { message_id: params.replyToId } }
28
- : {}),
29
- },
30
- }, params.signal ? { signal: params.signal } : undefined);
30
+ const { messages, error } = answerMessages(params.text);
31
+ if (error)
32
+ params.onButtonsError?.(error);
33
+ if (messages.length === 0)
34
+ messages.push([{ type: "text", value: params.text }]);
35
+ let first;
36
+ for (const [index, parts] of messages.entries()) {
37
+ const response = await params.relay.chats.messages.send(params.chatId, {
38
+ message: {
39
+ parts,
40
+ idempotency_key: indexedIdempotencyKey(params.idempotencyKey, index),
41
+ ...(index === 0 && params.replyToId
42
+ ? { reply_to: { message_id: params.replyToId } }
43
+ : {}),
44
+ },
45
+ }, params.signal ? { signal: params.signal } : undefined);
46
+ first ??= response;
47
+ }
48
+ return first;
31
49
  }
32
50
  export function classifyUnknownRelaySend(error) {
33
51
  if (!(error instanceof RelayAPIError)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relaymessenger/openclaw-plugin",
3
- "version": "0.4.7-staging.2",
3
+ "version": "0.4.7-staging.21",
4
4
  "description": "Native Relay channel plugin for OpenClaw",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -37,11 +37,11 @@
37
37
  "prepack": "npm run build"
38
38
  },
39
39
  "dependencies": {
40
- "@relaymessenger/sdk": "0.3.6-staging.2"
40
+ "@relaymessenger/sdk": "0.3.6-staging.22"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^26.0.0",
44
- "openclaw": "2026.8.1",
43
+ "@types/node": "^26.6.2",
44
+ "openclaw": "2026.9.5",
45
45
  "typescript": "^7.0.2",
46
46
  "vitest": "^4.1.10"
47
47
  },
@@ -164,7 +164,7 @@
164
164
  "pluginApi": ">=2026.8.1 <2026.10.0"
165
165
  },
166
166
  "build": {
167
- "openclawVersion": "2026.8.1"
167
+ "openclawVersion": "2026.9.5"
168
168
  }
169
169
  }
170
170
  }
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: component block left as text: ${error}`,
335
+ ),
332
336
  ...(ctx.onPlatformSendDispatch
333
337
  ? { onPlatformSendDispatch: ctx.onPlatformSendDispatch }
334
338
  : {}),
package/src/dispatch.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { BUTTONS_GUIDANCE, BUTTONS_BLOCK_INSTRUCTION, INVOICE_BLOCK_INSTRUCTION, INVOICE_GUIDANCE, LINK_LINE_INSTRUCTION, SELECTION_GUIDANCE, SELECTION_BLOCK_INSTRUCTION, selectionReplyContext } from "@relaymessenger/sdk";
1
2
  import type {
2
3
  Message,
3
4
  Relay,
@@ -236,12 +237,16 @@ export async function dispatchRelayEvent(params: {
236
237
  reply: {
237
238
  to: facts.chatId,
238
239
  originatingTo: facts.chatId,
239
- ...(facts.replyToId ? { replyToId: facts.replyToId } : {}),
240
+ ...((facts.replyAnchorId ?? facts.replyToId)
241
+ ? { replyToId: facts.replyAnchorId ?? facts.replyToId }
242
+ : {}),
240
243
  },
241
244
  message: {
242
245
  inboundEventKind: "user_request",
243
246
  body,
244
- bodyForAgent: facts.text,
247
+ bodyForAgent: [facts.text, selectionReplyContext(facts.selection, facts.richMessage),
248
+ `${BUTTONS_BLOCK_INSTRUCTION} ${LINK_LINE_INSTRUCTION} ${BUTTONS_GUIDANCE} ${SELECTION_BLOCK_INSTRUCTION} ${SELECTION_GUIDANCE} ${INVOICE_BLOCK_INSTRUCTION} ${INVOICE_GUIDANCE}`,
249
+ ].filter(Boolean).join("\n\n"),
245
250
  rawBody: facts.text,
246
251
  commandBody: facts.text,
247
252
  },
package/src/inbound.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { selectionReply, selectionReplyContext } from "@relaymessenger/sdk";
1
2
  import type {
2
3
  MessagePartResponse,
3
4
  RelayWebhookEvent,
@@ -17,6 +18,12 @@ function renderPart(part: MessagePartResponse): string | undefined {
17
18
  return `[Attachment: ${part.filename} (${part.mime_type})] ${part.url}`;
18
19
  case "system":
19
20
  return part.value;
21
+ // The agent's own buttons part reads as nothing, as on the server; its
22
+ // question is the text beside it. A tap arrives as ordinary text.
23
+ case "buttons":
24
+ case "selection":
25
+ case "selection_response":
26
+ return undefined;
20
27
  }
21
28
  }
22
29
 
@@ -57,7 +64,9 @@ export function buildRelayInboundFacts(
57
64
  ) return null;
58
65
 
59
66
  const text = renderRelayMessageParts(event.data.parts);
60
- if (!text.trim()) return null;
67
+ const message = { parts: event.data.parts, ...(event.data.reply_to ? { reply_to: event.data.reply_to } : {}) };
68
+ const richMessage = selectionReplyContext(undefined, message) ? message : undefined;
69
+ if (!text.trim() && !richMessage) return null;
61
70
 
62
71
  const mentionHandles = event.data.parts.flatMap((part) =>
63
72
  part.type === "text" &&
@@ -68,7 +77,10 @@ export function buildRelayInboundFacts(
68
77
  );
69
78
  const timestampValue = event.data.sent_at ?? event.created_at;
70
79
  const timestamp = Date.parse(timestampValue);
80
+ const selection = selectionReply(event.data.parts, event.data.reply_to);
71
81
  return {
82
+ ...(selection ? { selection } : {}),
83
+ ...(richMessage ? { richMessage } : {}),
72
84
  eventId: event.event_id,
73
85
  messageId: event.data.id,
74
86
  chatId: event.data.chat.id,
@@ -84,7 +96,14 @@ export function buildRelayInboundFacts(
84
96
  ? { ownerHandle: event.data.chat.owner_handle }
85
97
  : {}),
86
98
  ...(event.data.reply_to?.message_id
87
- ? { replyToId: event.data.reply_to.message_id }
99
+ ? {
100
+ replyToId: event.data.reply_to.message_id,
101
+ // The answer quotes the person's message, the one it answers (a bot's
102
+ // reply_to in Telegram and Discord names the person's message). A
103
+ // tap's reply_to names the agent's buttons part, which no reply may
104
+ // target, so this is also what keeps a tap answerable.
105
+ replyAnchorId: event.data.id,
106
+ }
88
107
  : {}),
89
108
  ...(Number.isFinite(timestamp) ? { timestamp } : {}),
90
109
  };
package/src/outbound.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import {
3
+ answerMessages,
4
+ indexedIdempotencyKey,
3
5
  Relay,
4
6
  RelayAPIError,
5
7
  type MessageSendResponse,
@@ -32,6 +34,14 @@ 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, and a link written
40
+ * alone on a line goes out as its own link Message. A block that cannot be
41
+ * read stays in the words and is reported through `onButtonsError`. Without
42
+ * a block or a link line the words go exactly as OpenClaw handed them, in one
43
+ * Message; the response is the first Message's, the one the reply anchors to.
44
+ */
35
45
  export async function sendRelayText(params: {
36
46
  relay: Pick<Relay, "chats">;
37
47
  chatId: string;
@@ -40,21 +50,30 @@ export async function sendRelayText(params: {
40
50
  idempotencyKey: string;
41
51
  signal?: AbortSignal;
42
52
  onPlatformSendDispatch?: () => Promise<void>;
53
+ onButtonsError?: (error: string) => void;
43
54
  }): Promise<MessageSendResponse> {
44
55
  await params.onPlatformSendDispatch?.();
45
- return await params.relay.chats.messages.send(
46
- params.chatId,
47
- {
48
- message: {
49
- parts: [{ type: "text", value: params.text }],
50
- idempotency_key: params.idempotencyKey,
51
- ...(params.replyToId
52
- ? { reply_to: { message_id: params.replyToId } }
53
- : {}),
56
+ const { messages, error } = answerMessages(params.text);
57
+ if (error) params.onButtonsError?.(error);
58
+ if (messages.length === 0) messages.push([{ type: "text", value: params.text }]);
59
+ let first: MessageSendResponse | undefined;
60
+ for (const [index, parts] of messages.entries()) {
61
+ const response = await params.relay.chats.messages.send(
62
+ params.chatId,
63
+ {
64
+ message: {
65
+ parts,
66
+ idempotency_key: indexedIdempotencyKey(params.idempotencyKey, index),
67
+ ...(index === 0 && params.replyToId
68
+ ? { reply_to: { message_id: params.replyToId } }
69
+ : {}),
70
+ },
54
71
  },
55
- },
56
- params.signal ? { signal: params.signal } : undefined,
57
- );
72
+ params.signal ? { signal: params.signal } : undefined,
73
+ );
74
+ first ??= response;
75
+ }
76
+ return first!;
58
77
  }
59
78
 
60
79
  export function classifyUnknownRelaySend(error: unknown): {
package/src/types.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import type {
2
2
  Chat,
3
+ SelectionReply,
4
+ MessagePartResponse,
5
+ ReplyTo,
3
6
  ChatHandle,
4
7
  MessageWebhookData,
5
8
  Message,
@@ -61,6 +64,8 @@ export type RelayMessageReceivedEvent = RelayWebhookEnvelope<
61
64
  >;
62
65
 
63
66
  export type RelayInboundFacts = {
67
+ selection?: SelectionReply;
68
+ richMessage?: { parts: MessagePartResponse[]; reply_to?: ReplyTo | null };
64
69
  eventId: string;
65
70
  messageId: string;
66
71
  chatId: string;
@@ -72,5 +77,11 @@ export type RelayInboundFacts = {
72
77
  mentionHandles: string[];
73
78
  ownerHandle?: ChatHandle;
74
79
  replyToId?: string;
80
+ /**
81
+ * The Message an outbound reply should quote when the person's Message
82
+ * was itself a reply: the person's Message. A tap's reply_to names the
83
+ * agent's buttons part, which no reply may target.
84
+ */
85
+ replyAnchorId?: string;
75
86
  timestamp?: number;
76
87
  };