refactor: centralize target errors and cache lookups
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { chunkMarkdownText } from "../../../src/auto-reply/chunk.js";
|
||||
import type { ChannelOutboundAdapter } from "../../../src/channels/plugins/types.js";
|
||||
import { sendMessageMatrix, sendPollMatrix } from "./matrix/send.js";
|
||||
import { missingTargetError } from "../../../src/infra/outbound/target-errors.js";
|
||||
|
||||
export const matrixOutbound: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
@@ -11,7 +12,7 @@ export const matrixOutbound: ChannelOutboundAdapter = {
|
||||
if (!trimmed) {
|
||||
return {
|
||||
ok: false,
|
||||
error: new Error("Delivering to Matrix requires target <room|alias|user>"),
|
||||
error: missingTargetError("Matrix", "<room|alias|user>"),
|
||||
};
|
||||
}
|
||||
return { ok: true, to: trimmed };
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { ChannelOutboundAdapter } from "../../../src/channels/plugins/types
|
||||
|
||||
import { createMSTeamsPollStoreFs } from "./polls.js";
|
||||
import { sendMessageMSTeams, sendPollMSTeams } from "./send.js";
|
||||
import { missingTargetError } from "../../../src/infra/outbound/target-errors.js";
|
||||
|
||||
export const msteamsOutbound: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
@@ -14,9 +15,7 @@ export const msteamsOutbound: ChannelOutboundAdapter = {
|
||||
if (!trimmed) {
|
||||
return {
|
||||
ok: false,
|
||||
error: new Error(
|
||||
"Delivering to MS Teams requires target <conversationId|user:ID|conversation:ID>",
|
||||
),
|
||||
error: missingTargetError("MS Teams", "<conversationId|user:ID|conversation:ID>"),
|
||||
};
|
||||
}
|
||||
return { ok: true, to: trimmed };
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import { collectZaloStatusIssues } from "./status-issues.js";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "./shared/account-ids.js";
|
||||
import { missingTargetError } from "../../../src/infra/outbound/target-errors.js";
|
||||
|
||||
const meta = {
|
||||
id: "zalo",
|
||||
@@ -185,7 +186,7 @@ export const zaloPlugin: ChannelPlugin<ResolvedZaloAccount> = {
|
||||
return "ZALO_BOT_TOKEN can only be used for the default account.";
|
||||
}
|
||||
if (!input.useEnv && !input.token && !input.tokenFile) {
|
||||
return "Zalo requires targetken or --token-file (or --use-env).";
|
||||
return "Zalo requires token or --token-file (or --use-env).";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -284,7 +285,7 @@ export const zaloPlugin: ChannelPlugin<ResolvedZaloAccount> = {
|
||||
if (!trimmed) {
|
||||
return {
|
||||
ok: false,
|
||||
error: new Error("Delivering to Zalo requires target <chatId>"),
|
||||
error: missingTargetError("Zalo", "<chatId>"),
|
||||
};
|
||||
}
|
||||
return { ok: true, to: trimmed };
|
||||
|
||||
@@ -17,6 +17,7 @@ import { zalouserOnboardingAdapter } from "./onboarding.js";
|
||||
import { sendMessageZalouser } from "./send.js";
|
||||
import { checkZcaInstalled, parseJsonOutput, runZca, runZcaInteractive } from "./zca.js";
|
||||
import {
|
||||
import { missingTargetError } from "../../../src/infra/outbound/target-errors.js";
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
type CoreConfig,
|
||||
type ZalouserConfig,
|
||||
@@ -378,7 +379,7 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
|
||||
if (!trimmed) {
|
||||
return {
|
||||
ok: false,
|
||||
error: new Error("Delivering to Zalouser requires target <threadId>"),
|
||||
error: missingTargetError("Zalouser", "<threadId>"),
|
||||
};
|
||||
}
|
||||
return { ok: true, to: trimmed };
|
||||
|
||||
Reference in New Issue
Block a user