Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
686 lines
20 KiB
TypeScript
686 lines
20 KiB
TypeScript
// Line tests cover channel.sendPayload plugin behavior.
|
|
import {
|
|
verifyChannelMessageAdapterCapabilityProofs,
|
|
verifyChannelMessageReceiveAckPolicyAdapterProofs,
|
|
} from "openclaw/plugin-sdk/channel-outbound";
|
|
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { OpenClawConfig, PluginRuntime } from "../api.js";
|
|
import { linePlugin } from "./channel.js";
|
|
import { lineConfigAdapter } from "./config-adapter.js";
|
|
import { resolveLineGroupRequireMention } from "./group-policy.js";
|
|
import { lineOutboundAdapter } from "./outbound.js";
|
|
import { setLineRuntime } from "./runtime.js";
|
|
import { createLineSendReceipt } from "./send-receipt.js";
|
|
|
|
const ssrfMocks = vi.hoisted(() => ({
|
|
resolvePinnedHostnameWithPolicy: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
|
|
resolvePinnedHostnameWithPolicy: ssrfMocks.resolvePinnedHostnameWithPolicy,
|
|
}));
|
|
|
|
afterAll(() => {
|
|
vi.doUnmock("openclaw/plugin-sdk/ssrf-runtime");
|
|
vi.resetModules();
|
|
});
|
|
|
|
type LineRuntimeMocks = {
|
|
pushMessageLine: ReturnType<typeof vi.fn>;
|
|
pushMessagesLine: ReturnType<typeof vi.fn>;
|
|
pushFlexMessage: ReturnType<typeof vi.fn>;
|
|
pushTemplateMessage: ReturnType<typeof vi.fn>;
|
|
pushLocationMessage: ReturnType<typeof vi.fn>;
|
|
pushTextMessageWithQuickReplies: ReturnType<typeof vi.fn>;
|
|
createQuickReplyItems: ReturnType<typeof vi.fn>;
|
|
buildTemplateMessageFromPayload: ReturnType<typeof vi.fn>;
|
|
sendMessageLine: ReturnType<typeof vi.fn>;
|
|
chunkMarkdownText: ReturnType<typeof vi.fn>;
|
|
resolveLineAccount: ReturnType<typeof vi.fn>;
|
|
resolveTextChunkLimit: ReturnType<typeof vi.fn>;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
vi.setSystemTime(1_800_000_000_000);
|
|
ssrfMocks.resolvePinnedHostnameWithPolicy.mockReset();
|
|
ssrfMocks.resolvePinnedHostnameWithPolicy.mockResolvedValue({
|
|
hostname: "example.com",
|
|
addresses: ["93.184.216.34"],
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
function lineResult(messageId: string, chatId = "c1") {
|
|
return {
|
|
messageId,
|
|
chatId,
|
|
receipt: createLineSendReceipt({ messageId, chatId, kind: "text" }),
|
|
};
|
|
}
|
|
|
|
function createRuntime(): { runtime: PluginRuntime; mocks: LineRuntimeMocks } {
|
|
const pushMessageLine = vi.fn(async () => lineResult("m-text"));
|
|
const pushMessagesLine = vi.fn(async () => lineResult("m-batch"));
|
|
const pushFlexMessage = vi.fn(async () => lineResult("m-flex"));
|
|
const pushTemplateMessage = vi.fn(async () => lineResult("m-template"));
|
|
const pushLocationMessage = vi.fn(async () => lineResult("m-loc"));
|
|
const pushTextMessageWithQuickReplies = vi.fn(async () => lineResult("m-quick"));
|
|
const createQuickReplyItems = vi.fn((labels: string[]) => ({ items: labels }));
|
|
const buildTemplateMessageFromPayload = vi.fn(() => ({ type: "buttons" }));
|
|
const sendMessageLine = vi.fn(async () => lineResult("m-media"));
|
|
const chunkMarkdownText = vi.fn((text: string) => [text]);
|
|
const resolveTextChunkLimit = vi.fn(() => 123);
|
|
const resolveLineAccount = vi.fn(
|
|
({ cfg, accountId }: { cfg: OpenClawConfig; accountId?: string }) => {
|
|
const resolved = accountId ?? "default";
|
|
const lineConfig = (cfg.channels?.line ?? {}) as {
|
|
accounts?: Record<string, Record<string, unknown>>;
|
|
};
|
|
const accountConfig = resolved !== "default" ? (lineConfig.accounts?.[resolved] ?? {}) : {};
|
|
return {
|
|
accountId: resolved,
|
|
config: { ...lineConfig, ...accountConfig },
|
|
};
|
|
},
|
|
);
|
|
|
|
const runtime = {
|
|
channel: {
|
|
line: {
|
|
pushMessageLine,
|
|
pushMessagesLine,
|
|
pushFlexMessage,
|
|
pushTemplateMessage,
|
|
pushLocationMessage,
|
|
pushTextMessageWithQuickReplies,
|
|
createQuickReplyItems,
|
|
buildTemplateMessageFromPayload,
|
|
sendMessageLine,
|
|
resolveLineAccount,
|
|
},
|
|
text: {
|
|
chunkMarkdownText,
|
|
resolveTextChunkLimit,
|
|
},
|
|
},
|
|
} as unknown as PluginRuntime;
|
|
|
|
return {
|
|
runtime,
|
|
mocks: {
|
|
pushMessageLine,
|
|
pushMessagesLine,
|
|
pushFlexMessage,
|
|
pushTemplateMessage,
|
|
pushLocationMessage,
|
|
pushTextMessageWithQuickReplies,
|
|
createQuickReplyItems,
|
|
buildTemplateMessageFromPayload,
|
|
sendMessageLine,
|
|
chunkMarkdownText,
|
|
resolveLineAccount,
|
|
resolveTextChunkLimit,
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("line outbound sendPayload", () => {
|
|
it("sends flex message without dropping text", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
text: "Now playing:",
|
|
channelData: {
|
|
line: {
|
|
flexMessage: {
|
|
altText: "Now playing",
|
|
contents: { type: "bubble" },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:group:1",
|
|
text: payload.text,
|
|
payload,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.pushFlexMessage).toHaveBeenCalledTimes(1);
|
|
expect(mocks.pushMessageLine).toHaveBeenCalledWith("line:group:1", "Now playing:", {
|
|
verbose: false,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
});
|
|
|
|
it("reports each platform result for text and media payloads", async () => {
|
|
const { runtime } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
const onDeliveryResult = vi.fn();
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:progress",
|
|
text: "Hello",
|
|
payload: {
|
|
text: "Hello",
|
|
mediaUrl: "https://example.com/image.jpg",
|
|
},
|
|
accountId: "default",
|
|
cfg,
|
|
onDeliveryResult,
|
|
});
|
|
|
|
expect(onDeliveryResult).toHaveBeenCalledTimes(2);
|
|
expect(onDeliveryResult.mock.calls.map(([result]) => result.messageId)).toEqual([
|
|
"m-text",
|
|
"m-media",
|
|
]);
|
|
});
|
|
|
|
it("sends template message without dropping text", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
text: "Choose one:",
|
|
channelData: {
|
|
line: {
|
|
templateMessage: {
|
|
type: "confirm",
|
|
text: "Continue?",
|
|
confirmLabel: "Yes",
|
|
confirmData: "yes",
|
|
cancelLabel: "No",
|
|
cancelData: "no",
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:1",
|
|
text: payload.text,
|
|
payload,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.buildTemplateMessageFromPayload).toHaveBeenCalledTimes(1);
|
|
expect(mocks.pushTemplateMessage).toHaveBeenCalledTimes(1);
|
|
expect(mocks.pushMessageLine).toHaveBeenCalledWith("line:user:1", "Choose one:", {
|
|
verbose: false,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
});
|
|
|
|
it("attaches quick replies when no text chunks are present", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
channelData: {
|
|
line: {
|
|
quickReplies: ["One", "Two"],
|
|
flexMessage: {
|
|
altText: "Card",
|
|
contents: { type: "bubble" },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:2",
|
|
text: "",
|
|
payload,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.pushFlexMessage).not.toHaveBeenCalled();
|
|
expect(mocks.pushMessagesLine).toHaveBeenCalledWith(
|
|
"line:user:2",
|
|
[
|
|
{
|
|
type: "flex",
|
|
altText: "Card",
|
|
contents: { type: "bubble" },
|
|
quickReply: { items: ["One", "Two"] },
|
|
},
|
|
],
|
|
{ verbose: false, accountId: "default", cfg },
|
|
);
|
|
expect(mocks.createQuickReplyItems).toHaveBeenCalledWith(["One", "Two"]);
|
|
});
|
|
|
|
it("sends quick-reply-only payloads with fallback text", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const result = await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:quick",
|
|
text: "",
|
|
payload: {
|
|
channelData: {
|
|
line: {
|
|
quickReplies: ["One", "Two"],
|
|
},
|
|
},
|
|
},
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.pushTextMessageWithQuickReplies).toHaveBeenCalledWith(
|
|
"line:user:quick",
|
|
"Options:\n- One\n- Two",
|
|
["One", "Two"],
|
|
{ verbose: false, accountId: "default", cfg },
|
|
);
|
|
expect(result).toEqual({
|
|
channel: "line",
|
|
chatId: "c1",
|
|
messageId: "m-quick",
|
|
receipt: {
|
|
parts: [
|
|
{
|
|
index: 0,
|
|
kind: "text",
|
|
platformMessageId: "m-quick",
|
|
raw: {
|
|
channel: "line",
|
|
chatId: "c1",
|
|
conversationId: "c1",
|
|
messageId: "m-quick",
|
|
meta: { messageCount: 1 },
|
|
},
|
|
threadId: "c1",
|
|
},
|
|
],
|
|
platformMessageIds: ["m-quick"],
|
|
primaryPlatformMessageId: "m-quick",
|
|
raw: [
|
|
{
|
|
channel: "line",
|
|
chatId: "c1",
|
|
conversationId: "c1",
|
|
messageId: "m-quick",
|
|
meta: { messageCount: 1 },
|
|
},
|
|
],
|
|
sentAt: 1_800_000_000_000,
|
|
threadId: "c1",
|
|
},
|
|
});
|
|
});
|
|
|
|
it("sends media before quick-reply text so buttons stay visible", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
text: "Hello",
|
|
mediaUrl: "https://example.com/img.jpg",
|
|
channelData: {
|
|
line: {
|
|
quickReplies: ["One", "Two"],
|
|
},
|
|
},
|
|
};
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:3",
|
|
text: payload.text,
|
|
payload,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:3", "", {
|
|
verbose: false,
|
|
mediaUrl: "https://example.com/img.jpg",
|
|
mediaKind: undefined,
|
|
previewImageUrl: undefined,
|
|
durationMs: undefined,
|
|
trackingId: undefined,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
expect(mocks.pushTextMessageWithQuickReplies).toHaveBeenCalledWith(
|
|
"line:user:3",
|
|
"Hello",
|
|
["One", "Two"],
|
|
{ verbose: false, accountId: "default", cfg },
|
|
);
|
|
const mediaOrder = mocks.sendMessageLine.mock.invocationCallOrder[0];
|
|
const quickReplyOrder = mocks.pushTextMessageWithQuickReplies.mock.invocationCallOrder[0];
|
|
expect(mediaOrder).toBeLessThan(quickReplyOrder);
|
|
});
|
|
|
|
it("keeps generic media payloads on the image-only send path", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:4",
|
|
text: "",
|
|
payload: {
|
|
mediaUrl: "https://example.com/video.mp4",
|
|
},
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:4", "", {
|
|
verbose: false,
|
|
mediaUrl: "https://example.com/video.mp4",
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
});
|
|
|
|
it("uses LINE-specific media options for rich media payloads", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:5",
|
|
text: "",
|
|
payload: {
|
|
mediaUrl: "https://example.com/video.mp4",
|
|
channelData: {
|
|
line: {
|
|
mediaKind: "video",
|
|
previewImageUrl: "https://example.com/preview.jpg",
|
|
trackingId: "track-123",
|
|
},
|
|
},
|
|
},
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:5", "", {
|
|
verbose: false,
|
|
mediaUrl: "https://example.com/video.mp4",
|
|
mediaKind: "video",
|
|
previewImageUrl: "https://example.com/preview.jpg",
|
|
durationMs: undefined,
|
|
trackingId: "track-123",
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
});
|
|
|
|
it("uses configured text chunk limit for payloads", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: { textChunkLimit: 123 } } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
text: "Hello world",
|
|
channelData: {
|
|
line: {
|
|
flexMessage: {
|
|
altText: "Card",
|
|
contents: { type: "bubble" },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:3",
|
|
text: payload.text,
|
|
payload,
|
|
accountId: "primary",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.resolveTextChunkLimit).toHaveBeenCalledWith(cfg, "line", "primary", {
|
|
fallbackLimit: 5000,
|
|
});
|
|
expect(mocks.chunkMarkdownText).toHaveBeenCalledWith("Hello world", 123);
|
|
});
|
|
|
|
it("omits trackingId for non-user quick-reply inline video media", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
text: "",
|
|
mediaUrl: "https://example.com/video.mp4",
|
|
channelData: {
|
|
line: {
|
|
quickReplies: ["One"],
|
|
mediaKind: "video" as const,
|
|
previewImageUrl: "https://example.com/preview.jpg",
|
|
trackingId: "track-group",
|
|
},
|
|
},
|
|
};
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:group:C123",
|
|
text: payload.text,
|
|
payload,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.pushMessagesLine).toHaveBeenCalledWith(
|
|
"line:group:C123",
|
|
[
|
|
{
|
|
type: "video",
|
|
originalContentUrl: "https://example.com/video.mp4",
|
|
previewImageUrl: "https://example.com/preview.jpg",
|
|
quickReply: { items: ["One"] },
|
|
},
|
|
],
|
|
{ verbose: false, accountId: "default", cfg },
|
|
);
|
|
});
|
|
|
|
it("keeps trackingId for user quick-reply inline video media", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
text: "",
|
|
mediaUrl: "https://example.com/video.mp4",
|
|
channelData: {
|
|
line: {
|
|
quickReplies: ["One"],
|
|
mediaKind: "video" as const,
|
|
previewImageUrl: "https://example.com/preview.jpg",
|
|
trackingId: "track-user",
|
|
},
|
|
},
|
|
};
|
|
|
|
await lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:U123",
|
|
text: payload.text,
|
|
payload,
|
|
accountId: "default",
|
|
cfg,
|
|
});
|
|
|
|
expect(mocks.pushMessagesLine).toHaveBeenCalledWith(
|
|
"line:user:U123",
|
|
[
|
|
{
|
|
type: "video",
|
|
originalContentUrl: "https://example.com/video.mp4",
|
|
previewImageUrl: "https://example.com/preview.jpg",
|
|
trackingId: "track-user",
|
|
quickReply: { items: ["One"] },
|
|
},
|
|
],
|
|
{ verbose: false, accountId: "default", cfg },
|
|
);
|
|
});
|
|
|
|
it("rejects quick-reply inline video media without previewImageUrl", async () => {
|
|
const { runtime } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const payload = {
|
|
text: "",
|
|
mediaUrl: "https://example.com/video.mp4",
|
|
channelData: {
|
|
line: {
|
|
quickReplies: ["One"],
|
|
mediaKind: "video" as const,
|
|
},
|
|
},
|
|
};
|
|
|
|
await expect(
|
|
lineOutboundAdapter.sendPayload!({
|
|
to: "line:user:U123",
|
|
text: payload.text,
|
|
payload,
|
|
accountId: "default",
|
|
cfg,
|
|
}),
|
|
).rejects.toThrow(/require previewimageurl/i);
|
|
});
|
|
|
|
it("declares message adapter durable text and media with receipt proofs", async () => {
|
|
const { runtime, mocks } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
const cfg = { channels: { line: {} } } as OpenClawConfig;
|
|
|
|
const proofResults = await verifyChannelMessageAdapterCapabilityProofs({
|
|
adapterName: "line",
|
|
adapter: linePlugin.message!,
|
|
proofs: {
|
|
text: async () => {
|
|
const result = await linePlugin.message?.send?.text?.({
|
|
cfg,
|
|
to: "line:user:U123",
|
|
text: "hello",
|
|
accountId: "primary",
|
|
});
|
|
expect(mocks.pushMessageLine).toHaveBeenCalledWith("line:user:U123", "hello", {
|
|
verbose: false,
|
|
accountId: "primary",
|
|
cfg,
|
|
});
|
|
expect(result?.receipt.platformMessageIds).toEqual(["m-text"]);
|
|
},
|
|
media: async () => {
|
|
const result = await linePlugin.message?.send?.media?.({
|
|
cfg,
|
|
to: "line:user:U123",
|
|
text: "image",
|
|
mediaUrl: "https://example.com/image.jpg",
|
|
accountId: "primary",
|
|
});
|
|
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:U123", "", {
|
|
verbose: false,
|
|
mediaUrl: "https://example.com/image.jpg",
|
|
accountId: "primary",
|
|
cfg,
|
|
});
|
|
expect(result?.receipt.platformMessageIds).toEqual(["m-media"]);
|
|
},
|
|
messageSendingHooks: () => {
|
|
expect(linePlugin.message?.send?.text).toBeTypeOf("function");
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(proofResults.find((result) => result.capability === "text")?.status).toBe("verified");
|
|
expect(proofResults.find((result) => result.capability === "media")?.status).toBe("verified");
|
|
expect(proofResults.find((result) => result.capability === "messageSendingHooks")?.status).toBe(
|
|
"verified",
|
|
);
|
|
});
|
|
|
|
it("declares receive ack policies for immediate LINE webhook acknowledgement", async () => {
|
|
const proofResults = await verifyChannelMessageReceiveAckPolicyAdapterProofs({
|
|
adapterName: "line",
|
|
adapter: linePlugin.message!,
|
|
proofs: {
|
|
after_receive_record: () => {
|
|
expect(linePlugin.message?.receive?.defaultAckPolicy).toBe("after_receive_record");
|
|
expect(linePlugin.message?.receive?.supportedAckPolicies).toContain(
|
|
"after_receive_record",
|
|
);
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(proofResults.find((result) => result.policy === "after_receive_record")?.status).toBe(
|
|
"verified",
|
|
);
|
|
expect(proofResults.find((result) => result.policy === "after_agent_dispatch")?.status).toBe(
|
|
"not_declared",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("linePlugin config.formatAllowFrom", () => {
|
|
it("strips line:user: prefixes without lowercasing", () => {
|
|
const formatted = lineConfigAdapter.formatAllowFrom!({
|
|
cfg: {} as OpenClawConfig,
|
|
allowFrom: ["line:user:UABC", "line:UDEF"],
|
|
});
|
|
expect(formatted).toEqual(["UABC", "UDEF"]);
|
|
});
|
|
});
|
|
|
|
describe("linePlugin groups.resolveRequireMention", () => {
|
|
it("uses account-level group settings when provided", () => {
|
|
const { runtime } = createRuntime();
|
|
setLineRuntime(runtime);
|
|
|
|
const cfg = {
|
|
channels: {
|
|
line: {
|
|
groups: {
|
|
"*": { requireMention: false },
|
|
},
|
|
accounts: {
|
|
primary: {
|
|
groups: {
|
|
"group-1": { requireMention: true },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as OpenClawConfig;
|
|
|
|
const requireMention = resolveLineGroupRequireMention({
|
|
cfg,
|
|
accountId: "primary",
|
|
groupId: "group-1",
|
|
});
|
|
|
|
expect(requireMention).toBe(true);
|
|
});
|
|
});
|