mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:50:46 +00:00
refactor: migrate bundled plugins to message lifecycle
This commit is contained in:
@@ -23,7 +23,7 @@ export {
|
||||
resolveDefaultGroupPolicy,
|
||||
warnMissingProviderGroupPolicyFallbackOnce,
|
||||
} from "openclaw/plugin-sdk/runtime-group-policy";
|
||||
export { dispatchInboundReplyWithBase } from "openclaw/plugin-sdk/inbound-reply-dispatch";
|
||||
export { dispatchChannelMessageReplyWithBase } from "openclaw/plugin-sdk/channel-message";
|
||||
export type { OutboundReplyPayload } from "openclaw/plugin-sdk/reply-payload";
|
||||
export { deliverFormattedTextWithAttachments } from "openclaw/plugin-sdk/reply-payload";
|
||||
export type { PluginRuntime } from "openclaw/plugin-sdk/runtime-store";
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import { NextcloudTalkConfigSchema } from "./config-schema.js";
|
||||
import { nextcloudTalkDoctor } from "./doctor.js";
|
||||
import { nextcloudTalkGatewayAdapter } from "./gateway.js";
|
||||
import { nextcloudTalkMessageAdapter } from "./message-adapter.js";
|
||||
import {
|
||||
looksLikeNextcloudTalkTargetId,
|
||||
normalizeNextcloudTalkMessagingTarget,
|
||||
@@ -25,7 +26,6 @@ import {
|
||||
import { resolveNextcloudTalkGroupToolPolicy } from "./policy.js";
|
||||
import { getNextcloudTalkRuntime } from "./runtime.js";
|
||||
import { collectRuntimeConfigAssignments, secretTargetRegistryEntries } from "./secret-contract.js";
|
||||
import { sendMessageNextcloudTalk } from "./send.js";
|
||||
import { resolveNextcloudTalkOutboundSessionRoute } from "./session-route.js";
|
||||
import { nextcloudTalkSetupAdapter } from "./setup-core.js";
|
||||
import { nextcloudTalkSetupWizard } from "./setup-surface.js";
|
||||
@@ -151,6 +151,7 @@ export const nextcloudTalkPlugin: ChannelPlugin<ResolvedNextcloudTalkAccount> =
|
||||
}),
|
||||
}),
|
||||
gateway: nextcloudTalkGatewayAdapter,
|
||||
message: nextcloudTalkMessageAdapter,
|
||||
},
|
||||
pairing: {
|
||||
text: {
|
||||
@@ -175,21 +176,22 @@ export const nextcloudTalkPlugin: ChannelPlugin<ResolvedNextcloudTalkAccount> =
|
||||
attachedResults: {
|
||||
channel: "nextcloud-talk",
|
||||
sendText: async ({ cfg, to, text, accountId, replyToId }) =>
|
||||
await sendMessageNextcloudTalk(to, text, {
|
||||
accountId: accountId ?? undefined,
|
||||
replyTo: replyToId ?? undefined,
|
||||
cfg: cfg as CoreConfig,
|
||||
await nextcloudTalkMessageAdapter.send.text({
|
||||
cfg,
|
||||
to,
|
||||
text,
|
||||
accountId,
|
||||
replyToId,
|
||||
}),
|
||||
sendMedia: async ({ cfg, to, text, mediaUrl, accountId, replyToId }) =>
|
||||
await sendMessageNextcloudTalk(
|
||||
await nextcloudTalkMessageAdapter.send.media({
|
||||
cfg,
|
||||
to,
|
||||
mediaUrl ? `${text}\n\nAttachment: ${mediaUrl}` : text,
|
||||
{
|
||||
accountId: accountId ?? undefined,
|
||||
replyTo: replyToId ?? undefined,
|
||||
cfg: cfg as CoreConfig,
|
||||
},
|
||||
),
|
||||
text,
|
||||
mediaUrl: mediaUrl ?? "",
|
||||
accountId,
|
||||
replyToId,
|
||||
}),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { CoreConfig, NextcloudTalkInboundMessage } from "./types.js";
|
||||
|
||||
const {
|
||||
createChannelPairingControllerMock,
|
||||
dispatchInboundReplyWithBaseMock,
|
||||
dispatchChannelMessageReplyWithBaseMock,
|
||||
readStoreAllowFromForDmPolicyMock,
|
||||
resolveDmGroupAccessWithCommandGateMock,
|
||||
resolveAllowlistProviderRuntimeGroupPolicyMock,
|
||||
@@ -16,7 +16,7 @@ const {
|
||||
} = vi.hoisted(() => {
|
||||
return {
|
||||
createChannelPairingControllerMock: vi.fn(),
|
||||
dispatchInboundReplyWithBaseMock: vi.fn(),
|
||||
dispatchChannelMessageReplyWithBaseMock: vi.fn(),
|
||||
readStoreAllowFromForDmPolicyMock: vi.fn(),
|
||||
resolveDmGroupAccessWithCommandGateMock: vi.fn(),
|
||||
resolveAllowlistProviderRuntimeGroupPolicyMock: vi.fn(),
|
||||
@@ -33,7 +33,7 @@ vi.mock("../runtime-api.js", async () => {
|
||||
return {
|
||||
...actual,
|
||||
createChannelPairingController: createChannelPairingControllerMock,
|
||||
dispatchInboundReplyWithBase: dispatchInboundReplyWithBaseMock,
|
||||
dispatchChannelMessageReplyWithBase: dispatchChannelMessageReplyWithBaseMock,
|
||||
readStoreAllowFromForDmPolicy: readStoreAllowFromForDmPolicyMock,
|
||||
resolveDmGroupAccessWithCommandGate: resolveDmGroupAccessWithCommandGateMock,
|
||||
resolveAllowlistProviderRuntimeGroupPolicy: resolveAllowlistProviderRuntimeGroupPolicyMock,
|
||||
@@ -196,7 +196,7 @@ describe("nextcloud-talk inbound behavior", () => {
|
||||
runtime,
|
||||
});
|
||||
|
||||
expect(dispatchInboundReplyWithBaseMock).not.toHaveBeenCalled();
|
||||
expect(dispatchChannelMessageReplyWithBaseMock).not.toHaveBeenCalled();
|
||||
expect(runtime.log).toHaveBeenCalledWith("nextcloud-talk: drop room room-group (no mention)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
GROUP_POLICY_BLOCKED_LABEL,
|
||||
createChannelPairingController,
|
||||
deliverFormattedTextWithAttachments,
|
||||
dispatchInboundReplyWithBase,
|
||||
dispatchChannelMessageReplyWithBase,
|
||||
logInboundDrop,
|
||||
readStoreAllowFromForDmPolicy,
|
||||
resolveAllowlistProviderRuntimeGroupPolicy,
|
||||
@@ -286,7 +286,7 @@ export async function handleNextcloudTalkInbound(params: {
|
||||
CommandAuthorized: commandAuthorized,
|
||||
});
|
||||
|
||||
await dispatchInboundReplyWithBase({
|
||||
await dispatchChannelMessageReplyWithBase({
|
||||
cfg: config as OpenClawConfig,
|
||||
channel: CHANNEL_ID,
|
||||
accountId: account.accountId,
|
||||
|
||||
28
extensions/nextcloud-talk/src/message-adapter.ts
Normal file
28
extensions/nextcloud-talk/src/message-adapter.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { defineChannelMessageAdapter } from "openclaw/plugin-sdk/channel-message";
|
||||
import { sendMessageNextcloudTalk } from "./send.js";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
|
||||
export const nextcloudTalkMessageAdapter = defineChannelMessageAdapter({
|
||||
id: "nextcloud-talk",
|
||||
durableFinal: {
|
||||
capabilities: {
|
||||
text: true,
|
||||
media: true,
|
||||
replyTo: true,
|
||||
},
|
||||
},
|
||||
send: {
|
||||
text: async ({ cfg, to, text, accountId, replyToId }) =>
|
||||
await sendMessageNextcloudTalk(to, text, {
|
||||
accountId: accountId ?? undefined,
|
||||
replyTo: replyToId ?? undefined,
|
||||
cfg: cfg as CoreConfig,
|
||||
}),
|
||||
media: async ({ cfg, to, text, mediaUrl, accountId, replyToId }) =>
|
||||
await sendMessageNextcloudTalk(to, mediaUrl ? `${text}\n\nAttachment: ${mediaUrl}` : text, {
|
||||
accountId: accountId ?? undefined,
|
||||
replyTo: replyToId ?? undefined,
|
||||
cfg: cfg as CoreConfig,
|
||||
}),
|
||||
},
|
||||
});
|
||||
@@ -1,7 +1,9 @@
|
||||
import { verifyChannelMessageAdapterCapabilityProofs } from "openclaw/plugin-sdk/channel-message";
|
||||
import {
|
||||
createSendCfgThreadingRuntime,
|
||||
expectProvidedCfgSkipsRuntimeLoad,
|
||||
} from "openclaw/plugin-sdk/channel-test-helpers";
|
||||
import type { OpenClawConfig as CoreConfig } from "openclaw/plugin-sdk/config-types";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
@@ -36,6 +38,7 @@ vi.mock("./send.runtime.js", () => {
|
||||
};
|
||||
});
|
||||
|
||||
const { nextcloudTalkMessageAdapter } = await import("./message-adapter.js");
|
||||
const { sendMessageNextcloudTalk, sendReactionNextcloudTalk } = await import("./send.js");
|
||||
|
||||
function expectProvidedMessageCfgThreading(cfg: unknown): void {
|
||||
@@ -111,11 +114,26 @@ describe("nextcloud-talk send cfg threading", () => {
|
||||
direction: "outbound",
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual({
|
||||
expect(result).toMatchObject({
|
||||
messageId: "12345",
|
||||
roomToken: "abc123",
|
||||
timestamp: 1_706_000_000,
|
||||
});
|
||||
expect(result.receipt).toMatchObject({
|
||||
primaryPlatformMessageId: "12345",
|
||||
platformMessageIds: ["12345"],
|
||||
parts: [
|
||||
{
|
||||
platformMessageId: "12345",
|
||||
kind: "text",
|
||||
raw: {
|
||||
channel: "nextcloud-talk",
|
||||
conversationId: "abc123",
|
||||
messageId: "12345",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("sends with provided cfg even when the runtime store is not initialized", async () => {
|
||||
@@ -131,13 +149,94 @@ describe("nextcloud-talk send cfg threading", () => {
|
||||
});
|
||||
|
||||
expectProvidedMessageCfgThreading(cfg);
|
||||
expect(result).toEqual({
|
||||
expect(result).toMatchObject({
|
||||
messageId: "12346",
|
||||
roomToken: "abc123",
|
||||
timestamp: 1_706_000_001,
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves reply ids in receipts", async () => {
|
||||
const cfg = { source: "provided" } as const;
|
||||
mockNextcloudMessageResponse(12347, 1_706_000_002);
|
||||
|
||||
const result = await sendMessageNextcloudTalk("room:abc123", "hello", {
|
||||
cfg,
|
||||
accountId: "work",
|
||||
replyTo: "parent-1",
|
||||
});
|
||||
|
||||
expect(result.receipt).toMatchObject({
|
||||
replyToId: "parent-1",
|
||||
parts: [
|
||||
{
|
||||
platformMessageId: "12347",
|
||||
replyToId: "parent-1",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("declares message adapter durable text, media, and reply with receipt proofs", async () => {
|
||||
const cfg = { source: "provided" } as const;
|
||||
mockNextcloudMessageResponse(22345, 1_706_000_003);
|
||||
mockNextcloudMessageResponse(22346, 1_706_000_004);
|
||||
mockNextcloudMessageResponse(22347, 1_706_000_005);
|
||||
|
||||
await expect(
|
||||
verifyChannelMessageAdapterCapabilityProofs({
|
||||
adapterName: "nextcloud-talk",
|
||||
adapter: nextcloudTalkMessageAdapter,
|
||||
proofs: {
|
||||
text: async () => {
|
||||
const result = await nextcloudTalkMessageAdapter.send?.text?.({
|
||||
cfg: cfg as CoreConfig,
|
||||
to: "room:abc123",
|
||||
text: "hello",
|
||||
accountId: "work",
|
||||
});
|
||||
expect(result?.receipt.platformMessageIds).toEqual(["22345"]);
|
||||
},
|
||||
media: async () => {
|
||||
const result = await nextcloudTalkMessageAdapter.send?.media?.({
|
||||
cfg: cfg as CoreConfig,
|
||||
to: "room:abc123",
|
||||
text: "image",
|
||||
mediaUrl: "https://example.com/image.png",
|
||||
accountId: "work",
|
||||
});
|
||||
expect(result?.receipt.platformMessageIds).toEqual(["22346"]);
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"https://nextcloud.example.com/ocs/v2.php/apps/spreed/api/v1/bot/abc123/message",
|
||||
expect.objectContaining({
|
||||
body: JSON.stringify({
|
||||
message: "image\n\nAttachment: https://example.com/image.png",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
},
|
||||
replyTo: async () => {
|
||||
const result = await nextcloudTalkMessageAdapter.send?.text?.({
|
||||
cfg: cfg as CoreConfig,
|
||||
to: "room:abc123",
|
||||
text: "threaded",
|
||||
replyToId: "parent-1",
|
||||
accountId: "work",
|
||||
});
|
||||
expect(result?.receipt.replyToId).toBe("parent-1");
|
||||
},
|
||||
},
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
{ capability: "text", status: "verified" },
|
||||
{ capability: "media", status: "verified" },
|
||||
{ capability: "replyTo", status: "verified" },
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("fails hard for sendReaction when cfg is omitted", async () => {
|
||||
fetchMock.mockResolvedValueOnce(new Response("{}", { status: 200 }));
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { createMessageReceiptFromOutboundResults } from "openclaw/plugin-sdk/channel-message";
|
||||
import { stripNextcloudTalkTargetPrefix } from "./normalize.js";
|
||||
import {
|
||||
convertMarkdownTables,
|
||||
@@ -81,6 +82,28 @@ function recordNextcloudTalkOutboundActivity(accountId: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
function createNextcloudTalkSendReceipt(params: {
|
||||
messageId: string;
|
||||
roomToken: string;
|
||||
replyTo?: string;
|
||||
}) {
|
||||
const messageId = params.messageId.trim();
|
||||
return createMessageReceiptFromOutboundResults({
|
||||
results:
|
||||
messageId && messageId !== "unknown"
|
||||
? [
|
||||
{
|
||||
channel: "nextcloud-talk",
|
||||
messageId,
|
||||
conversationId: params.roomToken,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
kind: "text",
|
||||
...(params.replyTo ? { replyToId: params.replyTo } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendMessageNextcloudTalk(
|
||||
to: string,
|
||||
text: string,
|
||||
@@ -183,7 +206,16 @@ export async function sendMessageNextcloudTalk(
|
||||
|
||||
recordNextcloudTalkOutboundActivity(account.accountId);
|
||||
|
||||
return { messageId, roomToken, timestamp };
|
||||
return {
|
||||
messageId,
|
||||
roomToken,
|
||||
receipt: createNextcloudTalkSendReceipt({
|
||||
messageId,
|
||||
roomToken,
|
||||
...(opts.replyTo ? { replyTo: opts.replyTo } : {}),
|
||||
}),
|
||||
timestamp,
|
||||
};
|
||||
} finally {
|
||||
await release();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { MessageReceipt } from "openclaw/plugin-sdk/channel-message";
|
||||
import type {
|
||||
BlockStreamingCoalesceConfig,
|
||||
DmConfig,
|
||||
@@ -144,6 +145,7 @@ export type NextcloudTalkWebhookPayload = {
|
||||
export type NextcloudTalkSendResult = {
|
||||
messageId: string;
|
||||
roomToken: string;
|
||||
receipt: MessageReceipt;
|
||||
timestamp?: number;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user