mirror of
https://github.com/xmanrui/OpenClaw-bot-review.git
synced 2026-08-14 00:47:49 +00:00
Unify WeCom platform display
This commit is contained in:
@@ -3,6 +3,7 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
import { getConfigCache, setConfigCache } from "@/lib/config-cache";
|
||||
import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths";
|
||||
import { shouldHidePlatformChannel } from "@/lib/platforms";
|
||||
|
||||
// 配置文件路径:优先使用 OPENCLAW_HOME 环境变量,否则默认 ~/.openclaw
|
||||
const CONFIG_PATH = OPENCLAW_CONFIG_PATH;
|
||||
@@ -329,12 +330,12 @@ export async function GET() {
|
||||
// 从预读的 sessions 数据获取飞书用户 open_id
|
||||
const feishuUserOpenIds = getFeishuUserOpenIds(agentIds, sessionsMap);
|
||||
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);
|
||||
const boundChannelNames: string[] = Array.from(new Set(
|
||||
bindings
|
||||
.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 directPeerIdsByChannel: Record<string, Record<string, string>> = {};
|
||||
@@ -406,7 +407,7 @@ export async function GET() {
|
||||
for (const binding of bindings) {
|
||||
if (binding?.agentId !== id) continue;
|
||||
const channelName = binding?.match?.channel;
|
||||
if (!channelName || channelName === "feishu") continue;
|
||||
if (!channelName || channelName === "feishu" || shouldHidePlatformChannel(channelName, channels)) continue;
|
||||
if (seenBindingChannels.has(channelName)) continue;
|
||||
seenBindingChannels.add(channelName);
|
||||
const botUserId = directPeerIdsByChannel[channelName]?.[id] || null;
|
||||
|
||||
@@ -3,6 +3,7 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths";
|
||||
import { parseApiJsonSafely, shouldFallbackToCli, testSessionViaCli } from "@/lib/session-test-fallback";
|
||||
import { shouldHidePlatformChannel } from "@/lib/platforms";
|
||||
const CONFIG_PATH = OPENCLAW_CONFIG_PATH;
|
||||
|
||||
interface DmSessionResult {
|
||||
@@ -110,11 +111,11 @@ export async function POST() {
|
||||
const results: DmSessionResult[] = [];
|
||||
const platformsToTest = Array.from(new Set([
|
||||
...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),
|
||||
...bindings
|
||||
.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) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import path from "path";
|
||||
import { execFileSync } from "child_process";
|
||||
import { pathToFileURL } from "url";
|
||||
import { OPENCLAW_CONFIG_PATH, OPENCLAW_HOME } from "@/lib/openclaw-paths";
|
||||
import { shouldHidePlatformChannel } from "@/lib/platforms";
|
||||
const CONFIG_PATH = OPENCLAW_CONFIG_PATH;
|
||||
const QQBOT_TOKEN_URL = "https://bots.qq.com/app/getAppAccessToken";
|
||||
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)) {
|
||||
if (specialPlatformNames.has(channelName)) continue;
|
||||
if (shouldHidePlatformChannel(channelName, channels)) continue;
|
||||
if (!channelConfig || typeof channelConfig !== "object" || (channelConfig as any).enabled === false) continue;
|
||||
|
||||
const hasBinding = bindings.some(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { buildGatewayUrl } from "@/lib/gateway-url";
|
||||
import { getPlatformDisplayName } from "@/lib/platforms";
|
||||
|
||||
export interface AgentPlatform {
|
||||
name: string;
|
||||
@@ -160,6 +161,7 @@ function PlatformBadge({
|
||||
testResult?: PlatformTestResult | null;
|
||||
}) {
|
||||
const pName = platform.name;
|
||||
const displayName = getPlatformDisplayName(pName);
|
||||
const badgeWidthClass = "w-[8.25rem]";
|
||||
const knownMeta: Record<string, { remoteLogoSrc: string; logoFallbackSrc: string; badgeStyle: string; logoSizeClass?: string }> = {
|
||||
feishu: {
|
||||
@@ -193,8 +195,13 @@ function PlatformBadge({
|
||||
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",
|
||||
},
|
||||
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";
|
||||
|
||||
let sessionKey: string;
|
||||
@@ -209,9 +216,9 @@ function PlatformBadge({
|
||||
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 translated = t(`platform.${pName}`);
|
||||
const labelRaw = translated !== `platform.${pName}` ? translated : pName;
|
||||
const label = labelRaw.replace(/^[^\p{L}\p{N}]+/u, "").trim() || pName;
|
||||
const translated = t(`platform.${displayName}`);
|
||||
const labelRaw = translated !== `platform.${displayName}` ? translated : displayName;
|
||||
const label = labelRaw.replace(/^[^\p{L}\p{N}]+/u, "").trim() || displayName;
|
||||
|
||||
return (
|
||||
<div className="inline-flex items-center gap-1.5 max-w-full">
|
||||
|
||||
@@ -141,6 +141,7 @@ const translations: Record<Locale, Record<string, string>> = {
|
||||
"platform.telegram": "✈️ Telegram",
|
||||
"platform.whatsapp": "💬 WhatsApp",
|
||||
"platform.qqbot": "🐧 QQBot",
|
||||
"platform.wecom": "💼 企業微信",
|
||||
|
||||
// time range
|
||||
"range.daily": "按日",
|
||||
@@ -428,6 +429,7 @@ const translations: Record<Locale, Record<string, string>> = {
|
||||
"platform.telegram": "✈️ Telegram",
|
||||
"platform.whatsapp": "💬 WhatsApp",
|
||||
"platform.qqbot": "🐧 QQBot",
|
||||
"platform.wecom": "💼 企业微信",
|
||||
|
||||
// time range
|
||||
"range.daily": "按天",
|
||||
@@ -715,6 +717,7 @@ const translations: Record<Locale, Record<string, string>> = {
|
||||
"platform.telegram": "✈️ Telegram",
|
||||
"platform.whatsapp": "💬 WhatsApp",
|
||||
"platform.qqbot": "🐧 QQBot",
|
||||
"platform.wecom": "💼 WeCom",
|
||||
|
||||
// time range
|
||||
"range.daily": "Daily",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 |
Reference in New Issue
Block a user