mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-11 11:56:03 +00:00
* feat(imessage): add native poll action
Wire the imsg CLI 'poll send' bridge command into the iMessage channel
message-tool action surface, mirroring the existing Discord poll action.
Adds the 'poll' action (gate: polls), a sendPoll runtime, selector-gated
capability advertisement (pollPayloadMessage), config type + zod schema,
regenerated channel metadata, docs, and tests.
* feat(imessage): read inbound polls, vote, and suppress vote echo
Builds on the native poll send action:
- Inbound polls now render to the agent as a readable line (question +
numbered options + tallies) instead of the raw 0xFFFD balloon placeholder,
so a received poll no longer reads as an empty message.
- New `poll-vote` action casts a vote via `imsg poll vote`, resolving a
1-based option index / text / UUID to the poll's option identifier.
- message_tool_only echo guard: the model tends to narrate its choice in a
text reply right after voting ("Blue."), which is redundant since the vote
shows on the poll. A new `poll_vote_echo` suppression reason (alongside
inbound_metadata_echo / internal_runtime_context_echo) drops a send/reply
that exactly restates the just-cast vote, using the option label imsg
returns. Extra content passes through untouched.
* fix(imessage): gate poll-vote on imsg poll.vote rpc capability
Released imsg carries the pollPayloadMessage selector (poll create) but
predates the poll.vote CLI/RPC. Gating both poll and poll-vote on that
selector alone would advertise a vote action the released CLI rejects.
Gate poll-vote additionally on the advertised poll.vote rpc method so this
plugin can ship ahead of the imsg release.
* fix(imessage): enforce poll.vote capability at execution, not just discovery
Codex review flagged the discovery gate as bypassable: a caller that already
knows action=poll-vote skips describeMessageTool and reaches handleAction
directly. Add the same imessageRpcSupportsMethod(status, 'poll.vote') check in
the poll-vote execution path (after assertPrivateApiEnabled), so a direct
dispatch on released imsg fails closed with a clear message instead of an
opaque CLI rejection. Adds a negative handleAction test.
* fix(imessage): harden native poll support
* fix(message): validate targets before channel discovery
* fix(message): validate targets before channel discovery
---------
Co-authored-by: Omar Shahine <lobster@users.noreply.github.com>
Co-authored-by: Omar Shahine <10343873+omarshahine@users.noreply.github.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
142 lines
4.0 KiB
TypeScript
142 lines
4.0 KiB
TypeScript
// Imessage tests cover message tool api plugin behavior.
|
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { describeMessageTool } from "../message-tool-api.js";
|
|
import {
|
|
clearCachedIMessagePrivateApiStatus,
|
|
setCachedIMessagePrivateApiStatus,
|
|
} from "./private-api-status.js";
|
|
|
|
describe("iMessage message-tool artifact", () => {
|
|
beforeEach(() => {
|
|
clearCachedIMessagePrivateApiStatus();
|
|
});
|
|
|
|
it("keeps poll actions discoverable until the first lazy bridge probe", () => {
|
|
const discovery = describeMessageTool({
|
|
cfg: { channels: { imessage: { cliPath: "imsg" } } } as never,
|
|
currentChannelId: "chat_id:1",
|
|
});
|
|
|
|
expect(discovery?.actions).toContain("poll");
|
|
expect(discovery?.actions).toContain("poll-vote");
|
|
expect(discovery?.schema).toMatchObject({
|
|
actions: ["poll-vote"],
|
|
visibility: "all-configured",
|
|
properties: { pollOptionText: { type: "string" } },
|
|
});
|
|
});
|
|
|
|
it("exposes lightweight discovery without loading the channel plugin", () => {
|
|
setCachedIMessagePrivateApiStatus("imsg", {
|
|
available: true,
|
|
v2Ready: true,
|
|
selectors: {
|
|
editMessage: true,
|
|
retractMessagePart: true,
|
|
},
|
|
rpcMethods: [],
|
|
});
|
|
|
|
const discovery = describeMessageTool({
|
|
cfg: {
|
|
channels: {
|
|
imessage: {
|
|
cliPath: "imsg",
|
|
actions: {
|
|
edit: false,
|
|
},
|
|
},
|
|
},
|
|
} as never,
|
|
currentChannelId: "chat_id:1",
|
|
});
|
|
|
|
expect(discovery?.actions).toStrictEqual([
|
|
"react",
|
|
"unsend",
|
|
"reply",
|
|
"sendWithEffect",
|
|
"renameGroup",
|
|
"setGroupIcon",
|
|
"addParticipant",
|
|
"removeParticipant",
|
|
"leaveGroup",
|
|
"upload-file",
|
|
]);
|
|
});
|
|
|
|
it("offers poll but hides poll-vote on imsg builds without the poll.vote rpc", () => {
|
|
setCachedIMessagePrivateApiStatus("imsg", {
|
|
available: true,
|
|
v2Ready: true,
|
|
selectors: { pollPayloadMessage: true, pollVoteMessage: true },
|
|
rpcMethods: [],
|
|
});
|
|
|
|
const discovery = describeMessageTool({
|
|
cfg: { channels: { imessage: { cliPath: "imsg" } } } as never,
|
|
currentChannelId: "chat_id:1",
|
|
});
|
|
|
|
expect(discovery?.actions).toContain("poll");
|
|
expect(discovery?.actions).not.toContain("poll-vote");
|
|
expect(discovery?.schema).toBeUndefined();
|
|
});
|
|
|
|
it("hides poll-vote when only the poll creation selector is available", () => {
|
|
setCachedIMessagePrivateApiStatus("imsg", {
|
|
available: true,
|
|
v2Ready: true,
|
|
selectors: { pollPayloadMessage: true },
|
|
rpcMethods: ["send", "poll.send", "poll.vote"],
|
|
});
|
|
|
|
const discovery = describeMessageTool({
|
|
cfg: { channels: { imessage: { cliPath: "imsg" } } } as never,
|
|
currentChannelId: "chat_id:1",
|
|
});
|
|
|
|
expect(discovery?.actions).toContain("poll");
|
|
expect(discovery?.actions).not.toContain("poll-vote");
|
|
});
|
|
|
|
it("offers poll-vote once imsg advertises the poll.vote rpc", () => {
|
|
setCachedIMessagePrivateApiStatus("imsg", {
|
|
available: true,
|
|
v2Ready: true,
|
|
selectors: { pollPayloadMessage: true, pollVoteMessage: true },
|
|
rpcMethods: ["send", "poll.send", "poll.vote", "messages.poll.vote"],
|
|
});
|
|
|
|
const discovery = describeMessageTool({
|
|
cfg: { channels: { imessage: { cliPath: "imsg" } } } as never,
|
|
currentChannelId: "chat_id:1",
|
|
});
|
|
|
|
expect(discovery?.actions).toContain("poll");
|
|
expect(discovery?.actions).toContain("poll-vote");
|
|
});
|
|
|
|
it("hides private actions when cached bridge status is unavailable", () => {
|
|
setCachedIMessagePrivateApiStatus("imsg", {
|
|
available: false,
|
|
v2Ready: false,
|
|
selectors: {},
|
|
rpcMethods: [],
|
|
});
|
|
|
|
const discovery = describeMessageTool({
|
|
cfg: {
|
|
channels: {
|
|
imessage: {
|
|
cliPath: "imsg",
|
|
},
|
|
},
|
|
} as never,
|
|
currentChannelId: "chat_id:1",
|
|
});
|
|
|
|
expect(discovery?.actions).toStrictEqual([]);
|
|
});
|
|
});
|