mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:01:23 +00:00
Feature/default messenger delivery target (openclaw#16985) thanks @KirillShchetinin
Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: KirillShchetinin <13061871+KirillShchetinin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
59e58bf81c
commit
ee519086f6
@@ -63,6 +63,10 @@ export type ChannelDock = {
|
||||
accountId?: string | null;
|
||||
allowFrom: Array<string | number>;
|
||||
}) => string[];
|
||||
resolveDefaultTo?: (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
}) => string | undefined;
|
||||
};
|
||||
groups?: ChannelGroupAdapter;
|
||||
mentions?: ChannelMentionAdapter;
|
||||
@@ -174,6 +178,10 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
.filter(Boolean)
|
||||
.map((entry) => entry.replace(/^(telegram|tg):/i, ""))
|
||||
.map((entry) => entry.toLowerCase()),
|
||||
resolveDefaultTo: ({ cfg, accountId }) => {
|
||||
const val = resolveTelegramAccount({ cfg, accountId }).config.defaultTo;
|
||||
return val != null ? String(val) : undefined;
|
||||
},
|
||||
},
|
||||
groups: {
|
||||
resolveRequireMention: resolveTelegramGroupRequireMention,
|
||||
@@ -213,6 +221,12 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
.filter((entry): entry is string => Boolean(entry))
|
||||
.map((entry) => (entry === "*" ? entry : normalizeWhatsAppTarget(entry)))
|
||||
.filter((entry): entry is string => Boolean(entry)),
|
||||
resolveDefaultTo: ({ cfg, accountId }) => {
|
||||
const root = cfg.channels?.whatsapp;
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
const account = root?.accounts?.[normalized];
|
||||
return (account?.defaultTo ?? root?.defaultTo)?.trim() || undefined;
|
||||
},
|
||||
},
|
||||
groups: {
|
||||
resolveRequireMention: resolveWhatsAppGroupRequireMention,
|
||||
@@ -267,6 +281,8 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
);
|
||||
},
|
||||
formatAllowFrom: ({ allowFrom }) => formatDiscordAllowFrom(allowFrom),
|
||||
resolveDefaultTo: ({ cfg, accountId }) =>
|
||||
resolveDiscordAccount({ cfg, accountId }).config.defaultTo?.trim() || undefined,
|
||||
},
|
||||
groups: {
|
||||
resolveRequireMention: resolveDiscordGroupRequireMention,
|
||||
@@ -311,6 +327,20 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
.replace(/^user:/i, "")
|
||||
.toLowerCase(),
|
||||
),
|
||||
resolveDefaultTo: ({ cfg, accountId }) => {
|
||||
const channel = cfg.channels?.irc as
|
||||
| { accounts?: Record<string, { defaultTo?: string }>; defaultTo?: string }
|
||||
| undefined;
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
const account =
|
||||
channel?.accounts?.[normalized] ??
|
||||
channel?.accounts?.[
|
||||
Object.keys(channel?.accounts ?? {}).find(
|
||||
(key) => key.toLowerCase() === normalized.toLowerCase(),
|
||||
) ?? ""
|
||||
];
|
||||
return (account?.defaultTo ?? channel?.defaultTo)?.trim() || undefined;
|
||||
},
|
||||
},
|
||||
groups: {
|
||||
resolveRequireMention: ({ cfg, accountId, groupId }) => {
|
||||
@@ -378,6 +408,20 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
.replace(/^users\//i, "")
|
||||
.toLowerCase(),
|
||||
),
|
||||
resolveDefaultTo: ({ cfg, accountId }) => {
|
||||
const channel = cfg.channels?.googlechat as
|
||||
| { accounts?: Record<string, { defaultTo?: string }>; defaultTo?: string }
|
||||
| undefined;
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
const account =
|
||||
channel?.accounts?.[normalized] ??
|
||||
channel?.accounts?.[
|
||||
Object.keys(channel?.accounts ?? {}).find(
|
||||
(key) => key.toLowerCase() === normalized.toLowerCase(),
|
||||
) ?? ""
|
||||
];
|
||||
return (account?.defaultTo ?? channel?.defaultTo)?.trim() || undefined;
|
||||
},
|
||||
},
|
||||
groups: {
|
||||
resolveRequireMention: resolveGoogleChatGroupRequireMention,
|
||||
@@ -416,6 +460,8 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
);
|
||||
},
|
||||
formatAllowFrom: ({ allowFrom }) => formatLower(allowFrom),
|
||||
resolveDefaultTo: ({ cfg, accountId }) =>
|
||||
resolveSlackAccount({ cfg, accountId }).config.defaultTo?.trim() || undefined,
|
||||
},
|
||||
groups: {
|
||||
resolveRequireMention: resolveSlackGroupRequireMention,
|
||||
@@ -453,6 +499,8 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
.filter(Boolean)
|
||||
.map((entry) => (entry === "*" ? "*" : normalizeE164(entry.replace(/^signal:/i, ""))))
|
||||
.filter(Boolean),
|
||||
resolveDefaultTo: ({ cfg, accountId }) =>
|
||||
resolveSignalAccount({ cfg, accountId }).config.defaultTo?.trim() || undefined,
|
||||
},
|
||||
threading: {
|
||||
buildToolContext: ({ context, hasRepliedRef }) =>
|
||||
@@ -474,6 +522,8 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
|
||||
),
|
||||
formatAllowFrom: ({ allowFrom }) =>
|
||||
allowFrom.map((entry) => String(entry).trim()).filter(Boolean),
|
||||
resolveDefaultTo: ({ cfg, accountId }) =>
|
||||
resolveIMessageAccount({ cfg, accountId }).config.defaultTo?.trim() || undefined,
|
||||
},
|
||||
groups: {
|
||||
resolveRequireMention: resolveIMessageGroupRequireMention,
|
||||
@@ -502,6 +552,7 @@ function buildDockFromPlugin(plugin: ChannelPlugin): ChannelDock {
|
||||
? {
|
||||
resolveAllowFrom: plugin.config.resolveAllowFrom,
|
||||
formatAllowFrom: plugin.config.formatAllowFrom,
|
||||
resolveDefaultTo: plugin.config.resolveDefaultTo,
|
||||
}
|
||||
: undefined,
|
||||
groups: plugin.groups,
|
||||
|
||||
@@ -63,6 +63,10 @@ export type ChannelConfigAdapter<ResolvedAccount> = {
|
||||
accountId?: string | null;
|
||||
allowFrom: Array<string | number>;
|
||||
}) => string[];
|
||||
resolveDefaultTo?: (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
}) => string | undefined;
|
||||
};
|
||||
|
||||
export type ChannelGroupAdapter = {
|
||||
|
||||
Reference in New Issue
Block a user