Unify WeCom platform display

This commit is contained in:
xmanrui
2026-03-17 16:32:37 +08:00
parent 030bd4c8f5
commit 4d1ceaea3e
7 changed files with 34 additions and 9 deletions
+4 -3
View File
@@ -3,6 +3,7 @@ import fs from "fs";
import path from "path"; import path from "path";
import { getConfigCache, setConfigCache } from "@/lib/config-cache"; import { getConfigCache, setConfigCache } from "@/lib/config-cache";
import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths"; import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths";
import { shouldHidePlatformChannel } from "@/lib/platforms";
// 配置文件路径:优先使用 OPENCLAW_HOME 环境变量,否则默认 ~/.openclaw // 配置文件路径:优先使用 OPENCLAW_HOME 环境变量,否则默认 ~/.openclaw
const CONFIG_PATH = OPENCLAW_CONFIG_PATH; const CONFIG_PATH = OPENCLAW_CONFIG_PATH;
@@ -329,12 +330,12 @@ export async function GET() {
// 从预读的 sessions 数据获取飞书用户 open_id // 从预读的 sessions 数据获取飞书用户 open_id
const feishuUserOpenIds = getFeishuUserOpenIds(agentIds, sessionsMap); const feishuUserOpenIds = getFeishuUserOpenIds(agentIds, sessionsMap);
const enabledChannelNames: string[] = Object.entries(channels) const enabledChannelNames: string[] = Object.entries(channels)
.filter(([, cfg]) => cfg && typeof cfg === "object" && (cfg as any).enabled !== false) .filter(([channelName, cfg]) => cfg && typeof cfg === "object" && (cfg as any).enabled !== false && !shouldHidePlatformChannel(channelName, channels))
.map(([channelName]) => channelName); .map(([channelName]) => channelName);
const boundChannelNames: string[] = Array.from(new Set( const boundChannelNames: string[] = Array.from(new Set(
bindings bindings
.map((b: any) => b.match?.channel) .map((b: any) => b.match?.channel)
.filter((v: any): v is string => typeof v === "string" && v.length > 0) .filter((v: any): v is string => typeof v === "string" && v.length > 0 && !shouldHidePlatformChannel(v, channels))
)); ));
const discoverChannelNames: string[] = Array.from(new Set([...enabledChannelNames, ...boundChannelNames])); const discoverChannelNames: string[] = Array.from(new Set([...enabledChannelNames, ...boundChannelNames]));
const directPeerIdsByChannel: Record<string, Record<string, string>> = {}; const directPeerIdsByChannel: Record<string, Record<string, string>> = {};
@@ -406,7 +407,7 @@ export async function GET() {
for (const binding of bindings) { for (const binding of bindings) {
if (binding?.agentId !== id) continue; if (binding?.agentId !== id) continue;
const channelName = binding?.match?.channel; const channelName = binding?.match?.channel;
if (!channelName || channelName === "feishu") continue; if (!channelName || channelName === "feishu" || shouldHidePlatformChannel(channelName, channels)) continue;
if (seenBindingChannels.has(channelName)) continue; if (seenBindingChannels.has(channelName)) continue;
seenBindingChannels.add(channelName); seenBindingChannels.add(channelName);
const botUserId = directPeerIdsByChannel[channelName]?.[id] || null; const botUserId = directPeerIdsByChannel[channelName]?.[id] || null;
+3 -2
View File
@@ -3,6 +3,7 @@ import fs from "fs";
import path from "path"; import path from "path";
import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths"; import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths";
import { parseApiJsonSafely, shouldFallbackToCli, testSessionViaCli } from "@/lib/session-test-fallback"; import { parseApiJsonSafely, shouldFallbackToCli, testSessionViaCli } from "@/lib/session-test-fallback";
import { shouldHidePlatformChannel } from "@/lib/platforms";
const CONFIG_PATH = OPENCLAW_CONFIG_PATH; const CONFIG_PATH = OPENCLAW_CONFIG_PATH;
interface DmSessionResult { interface DmSessionResult {
@@ -110,11 +111,11 @@ export async function POST() {
const results: DmSessionResult[] = []; const results: DmSessionResult[] = [];
const platformsToTest = Array.from(new Set([ const platformsToTest = Array.from(new Set([
...Object.entries(channels) ...Object.entries(channels)
.filter(([, cfg]) => cfg && typeof cfg === "object" && (cfg as any).enabled !== false) .filter(([name, cfg]) => cfg && typeof cfg === "object" && (cfg as any).enabled !== false && !shouldHidePlatformChannel(name, channels))
.map(([name]) => name), .map(([name]) => name),
...bindings ...bindings
.map((b: any) => b?.match?.channel) .map((b: any) => b?.match?.channel)
.filter((name: unknown): name is string => typeof name === "string" && name.length > 0), .filter((name: unknown): name is string => typeof name === "string" && name.length > 0 && !shouldHidePlatformChannel(name, channels)),
])); ]));
for (const agent of agentList) { for (const agent of agentList) {
+2
View File
@@ -4,6 +4,7 @@ import path from "path";
import { execFileSync } from "child_process"; import { execFileSync } from "child_process";
import { pathToFileURL } from "url"; import { pathToFileURL } from "url";
import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths"; import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths";
import { shouldHidePlatformChannel } from "@/lib/platforms";
const CONFIG_PATH = OPENCLAW_CONFIG_PATH; const CONFIG_PATH = OPENCLAW_CONFIG_PATH;
const QQBOT_TOKEN_URL = "https://bots.qq.com/app/getAppAccessToken"; const QQBOT_TOKEN_URL = "https://bots.qq.com/app/getAppAccessToken";
const QQBOT_API_BASE = "https://api.sgroup.qq.com"; const QQBOT_API_BASE = "https://api.sgroup.qq.com";
@@ -1184,6 +1185,7 @@ export async function POST() {
for (const [channelName, channelConfig] of Object.entries(channels)) { for (const [channelName, channelConfig] of Object.entries(channels)) {
if (specialPlatformNames.has(channelName)) continue; if (specialPlatformNames.has(channelName)) continue;
if (shouldHidePlatformChannel(channelName, channels)) continue;
if (!channelConfig || typeof channelConfig !== "object" || (channelConfig as any).enabled === false) continue; if (!channelConfig || typeof channelConfig !== "object" || (channelConfig as any).enabled === false) continue;
const hasBinding = bindings.some( const hasBinding = bindings.some(
+11 -4
View File
@@ -2,6 +2,7 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { buildGatewayUrl } from "@/lib/gateway-url"; import { buildGatewayUrl } from "@/lib/gateway-url";
import { getPlatformDisplayName } from "@/lib/platforms";
export interface AgentPlatform { export interface AgentPlatform {
name: string; name: string;
@@ -160,6 +161,7 @@ function PlatformBadge({
testResult?: PlatformTestResult | null; testResult?: PlatformTestResult | null;
}) { }) {
const pName = platform.name; const pName = platform.name;
const displayName = getPlatformDisplayName(pName);
const badgeWidthClass = "w-[8.25rem]"; const badgeWidthClass = "w-[8.25rem]";
const knownMeta: Record<string, { remoteLogoSrc: string; logoFallbackSrc: string; badgeStyle: string; logoSizeClass?: string }> = { const knownMeta: Record<string, { remoteLogoSrc: string; logoFallbackSrc: string; badgeStyle: string; logoSizeClass?: string }> = {
feishu: { feishu: {
@@ -193,8 +195,13 @@ function PlatformBadge({
logoFallbackSrc: "/assets/platform-logos/qq-favicon.ico?v=1", logoFallbackSrc: "/assets/platform-logos/qq-favicon.ico?v=1",
badgeStyle: "bg-blue-500/20 text-blue-300 border border-blue-500/30 hover:bg-blue-500/40 hover:border-blue-400", badgeStyle: "bg-blue-500/20 text-blue-300 border border-blue-500/30 hover:bg-blue-500/40 hover:border-blue-400",
}, },
wecom: {
remoteLogoSrc: "/assets/platform-logos/wecom.svg?v=1",
logoFallbackSrc: "/assets/platform-logos/wecom.svg?v=1",
badgeStyle: "bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 hover:bg-emerald-500/40 hover:border-emerald-400",
},
}; };
const meta = knownMeta[pName]; const meta = knownMeta[displayName];
const logoSizeClass = meta?.logoSizeClass || "w-3.5 h-3.5"; const logoSizeClass = meta?.logoSizeClass || "w-3.5 h-3.5";
let sessionKey: string; let sessionKey: string;
@@ -209,9 +216,9 @@ function PlatformBadge({
if (gatewayToken) sessionUrl = buildGatewayUrl(gatewayPort, "/chat", { session: sessionKey, token: gatewayToken }, gatewayHost); if (gatewayToken) sessionUrl = buildGatewayUrl(gatewayPort, "/chat", { session: sessionKey, token: gatewayToken }, gatewayHost);
const badgeStyle = meta?.badgeStyle || "bg-gray-500/20 text-gray-300 border border-gray-500/30 hover:bg-gray-500/40 hover:border-gray-400"; const badgeStyle = meta?.badgeStyle || "bg-gray-500/20 text-gray-300 border border-gray-500/30 hover:bg-gray-500/40 hover:border-gray-400";
const translated = t(`platform.${pName}`); const translated = t(`platform.${displayName}`);
const labelRaw = translated !== `platform.${pName}` ? translated : pName; const labelRaw = translated !== `platform.${displayName}` ? translated : displayName;
const label = labelRaw.replace(/^[^\p{L}\p{N}]+/u, "").trim() || pName; const label = labelRaw.replace(/^[^\p{L}\p{N}]+/u, "").trim() || displayName;
return ( return (
<div className="inline-flex items-center gap-1.5 max-w-full"> <div className="inline-flex items-center gap-1.5 max-w-full">
+3
View File
@@ -141,6 +141,7 @@ const translations: Record<Locale, Record<string, string>> = {
"platform.telegram": "✈️ Telegram", "platform.telegram": "✈️ Telegram",
"platform.whatsapp": "💬 WhatsApp", "platform.whatsapp": "💬 WhatsApp",
"platform.qqbot": "🐧 QQBot", "platform.qqbot": "🐧 QQBot",
"platform.wecom": "💼 企業微信",
// time range // time range
"range.daily": "按日", "range.daily": "按日",
@@ -428,6 +429,7 @@ const translations: Record<Locale, Record<string, string>> = {
"platform.telegram": "✈️ Telegram", "platform.telegram": "✈️ Telegram",
"platform.whatsapp": "💬 WhatsApp", "platform.whatsapp": "💬 WhatsApp",
"platform.qqbot": "🐧 QQBot", "platform.qqbot": "🐧 QQBot",
"platform.wecom": "💼 企业微信",
// time range // time range
"range.daily": "按天", "range.daily": "按天",
@@ -715,6 +717,7 @@ const translations: Record<Locale, Record<string, string>> = {
"platform.telegram": "✈️ Telegram", "platform.telegram": "✈️ Telegram",
"platform.whatsapp": "💬 WhatsApp", "platform.whatsapp": "💬 WhatsApp",
"platform.qqbot": "🐧 QQBot", "platform.qqbot": "🐧 QQBot",
"platform.wecom": "💼 WeCom",
// time range // time range
"range.daily": "Daily", "range.daily": "Daily",
+10
View File
@@ -0,0 +1,10 @@
export function shouldHidePlatformChannel(
channelName: string,
channels: Record<string, any>
): boolean {
return channelName === "wechat-access" && !!channels.wecom && channels.wecom.enabled !== false;
}
export function getPlatformDisplayName(channelName: string): string {
return channelName === "wechat-access" ? "wecom" : channelName;
}
+1
View File
@@ -0,0 +1 @@
<svg fill="#07C160" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>WeChat</title><path d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-4.196-6.348-8.596-6.348zM5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178 1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18zm5.34 2.867c-1.797-.052-3.746.512-5.28 1.786-1.72 1.428-2.687 3.72-1.78 6.22.942 2.453 3.666 4.229 6.884 4.229.826 0 1.622-.12 2.361-.336a.722.722 0 0 1 .598.082l1.584.926a.272.272 0 0 0 .14.047c.134 0 .24-.111.24-.247 0-.06-.023-.12-.038-.177l-.327-1.233a.582.582 0 0 1-.023-.156.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-6.656-6.088V8.89c-.135-.01-.27-.027-.407-.03zm-2.53 3.274c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.97-.982zm4.844 0c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB