mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:18:27 +00:00
refactor(outbound): centralize outbound identity
This commit is contained in:
@@ -6,6 +6,7 @@ import type { sendMessageIMessage } from "../../imessage/send.js";
|
||||
import type { sendMessageSlack } from "../../slack/send.js";
|
||||
import type { sendMessageTelegram } from "../../telegram/send.js";
|
||||
import type { sendMessageWhatsApp } from "../../web/outbound.js";
|
||||
import type { OutboundIdentity } from "./identity.js";
|
||||
import type { NormalizedOutboundPayload } from "./payloads.js";
|
||||
import type { OutboundChannel } from "./targets.js";
|
||||
import {
|
||||
@@ -85,9 +86,7 @@ async function createChannelHandler(params: {
|
||||
accountId?: string;
|
||||
replyToId?: string | null;
|
||||
threadId?: string | number | null;
|
||||
username?: string;
|
||||
icon_url?: string;
|
||||
icon_emoji?: string;
|
||||
identity?: OutboundIdentity;
|
||||
deps?: OutboundSendDeps;
|
||||
gifPlayback?: boolean;
|
||||
silent?: boolean;
|
||||
@@ -104,9 +103,7 @@ async function createChannelHandler(params: {
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
username: params.username,
|
||||
icon_url: params.icon_url,
|
||||
icon_emoji: params.icon_emoji,
|
||||
identity: params.identity,
|
||||
deps: params.deps,
|
||||
gifPlayback: params.gifPlayback,
|
||||
silent: params.silent,
|
||||
@@ -125,9 +122,7 @@ function createPluginHandler(params: {
|
||||
accountId?: string;
|
||||
replyToId?: string | null;
|
||||
threadId?: string | number | null;
|
||||
username?: string;
|
||||
icon_url?: string;
|
||||
icon_emoji?: string;
|
||||
identity?: OutboundIdentity;
|
||||
deps?: OutboundSendDeps;
|
||||
gifPlayback?: boolean;
|
||||
silent?: boolean;
|
||||
@@ -154,9 +149,7 @@ function createPluginHandler(params: {
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
username: params.username,
|
||||
icon_url: params.icon_url,
|
||||
icon_emoji: params.icon_emoji,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
deps: params.deps,
|
||||
silent: params.silent,
|
||||
@@ -171,9 +164,7 @@ function createPluginHandler(params: {
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
username: params.username,
|
||||
icon_url: params.icon_url,
|
||||
icon_emoji: params.icon_emoji,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
deps: params.deps,
|
||||
silent: params.silent,
|
||||
@@ -187,9 +178,7 @@ function createPluginHandler(params: {
|
||||
accountId: params.accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
username: params.username,
|
||||
icon_url: params.icon_url,
|
||||
icon_emoji: params.icon_emoji,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
deps: params.deps,
|
||||
silent: params.silent,
|
||||
@@ -207,9 +196,7 @@ export async function deliverOutboundPayloads(params: {
|
||||
payloads: ReplyPayload[];
|
||||
replyToId?: string | null;
|
||||
threadId?: string | number | null;
|
||||
username?: string;
|
||||
icon_url?: string;
|
||||
icon_emoji?: string;
|
||||
identity?: OutboundIdentity;
|
||||
deps?: OutboundSendDeps;
|
||||
gifPlayback?: boolean;
|
||||
abortSignal?: AbortSignal;
|
||||
@@ -292,9 +279,7 @@ async function deliverOutboundPayloadsCore(params: {
|
||||
payloads: ReplyPayload[];
|
||||
replyToId?: string | null;
|
||||
threadId?: string | number | null;
|
||||
username?: string;
|
||||
icon_url?: string;
|
||||
icon_emoji?: string;
|
||||
identity?: OutboundIdentity;
|
||||
deps?: OutboundSendDeps;
|
||||
gifPlayback?: boolean;
|
||||
abortSignal?: AbortSignal;
|
||||
@@ -323,9 +308,7 @@ async function deliverOutboundPayloadsCore(params: {
|
||||
accountId,
|
||||
replyToId: params.replyToId,
|
||||
threadId: params.threadId,
|
||||
username: params.username,
|
||||
icon_url: params.icon_url,
|
||||
icon_emoji: params.icon_emoji,
|
||||
identity: params.identity,
|
||||
gifPlayback: params.gifPlayback,
|
||||
silent: params.silent,
|
||||
});
|
||||
|
||||
37
src/infra/outbound/identity.ts
Normal file
37
src/infra/outbound/identity.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { resolveAgentAvatar } from "../../agents/identity-avatar.js";
|
||||
import { resolveAgentIdentity } from "../../agents/identity.js";
|
||||
|
||||
export type OutboundIdentity = {
|
||||
name?: string;
|
||||
avatarUrl?: string;
|
||||
emoji?: string;
|
||||
};
|
||||
|
||||
export function normalizeOutboundIdentity(
|
||||
identity?: OutboundIdentity | null,
|
||||
): OutboundIdentity | undefined {
|
||||
if (!identity) {
|
||||
return undefined;
|
||||
}
|
||||
const name = identity.name?.trim() || undefined;
|
||||
const avatarUrl = identity.avatarUrl?.trim() || undefined;
|
||||
const emoji = identity.emoji?.trim() || undefined;
|
||||
if (!name && !avatarUrl && !emoji) {
|
||||
return undefined;
|
||||
}
|
||||
return { name, avatarUrl, emoji };
|
||||
}
|
||||
|
||||
export function resolveAgentOutboundIdentity(
|
||||
cfg: OpenClawConfig,
|
||||
agentId: string,
|
||||
): OutboundIdentity | undefined {
|
||||
const agentIdentity = resolveAgentIdentity(cfg, agentId);
|
||||
const avatar = resolveAgentAvatar(cfg, agentId);
|
||||
return normalizeOutboundIdentity({
|
||||
name: agentIdentity?.name,
|
||||
emoji: agentIdentity?.emoji,
|
||||
avatarUrl: avatar.kind === "remote" ? avatar.url : undefined,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user