refactor: remove externalSource references from various components for consistency

This commit is contained in:
mlogclub
2026-04-28 11:11:16 +08:00
parent cf63b75590
commit 75afe60d4b
8 changed files with 4 additions and 28 deletions
@@ -828,7 +828,6 @@ function WechatMPAccessGuide({ channelId }: { channelId: string }) {
} }
const url = new URL("/kefu/chat/", origin) const url = new URL("/kefu/chat/", origin)
url.searchParams.set("channelId", channelId) url.searchParams.set("channelId", channelId)
url.searchParams.set("externalSource", "wechat_mp")
return url.toString() return url.toString()
}, [channelId, origin]) }, [channelId, origin])
+1 -7
View File
@@ -104,7 +104,6 @@ export type ImAsset = {
export type ImWidgetConfig = { export type ImWidgetConfig = {
channelId?: string channelId?: string
channelType?: string channelType?: string
externalSource?: string
userToken?: string userToken?: string
title?: string title?: string
subtitle?: string subtitle?: string
@@ -118,8 +117,6 @@ const API_BASE_URL =
process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || "" process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || ""
const OPEN_IM_CHANNEL_ID = const OPEN_IM_CHANNEL_ID =
process.env.NEXT_PUBLIC_OPEN_IM_CHANNEL_ID?.trim() || "" process.env.NEXT_PUBLIC_OPEN_IM_CHANNEL_ID?.trim() || ""
const OPEN_IM_EXTERNAL_SOURCE =
process.env.NEXT_PUBLIC_OPEN_IM_EXTERNAL_SOURCE?.trim() || "web_chat"
function buildGuestId() { function buildGuestId() {
return `guest_${generateUUID()}` return `guest_${generateUUID()}`
@@ -146,8 +143,6 @@ function getRuntimeImConfig() {
return { return {
baseUrl, baseUrl,
channelId: widgetConfig.channelId || OPEN_IM_CHANNEL_ID, channelId: widgetConfig.channelId || OPEN_IM_CHANNEL_ID,
externalSource:
(widgetConfig.externalSource || OPEN_IM_EXTERNAL_SOURCE).trim() || "web_chat",
externalId: (widgetConfig.externalId || "").trim(), externalId: (widgetConfig.externalId || "").trim(),
externalName: (widgetConfig.externalName || "").trim(), externalName: (widgetConfig.externalName || "").trim(),
userToken: (widgetConfig.userToken || "").trim(), userToken: (widgetConfig.userToken || "").trim(),
@@ -162,7 +157,6 @@ function createImHeaders() {
if (config.userToken) { if (config.userToken) {
headers.Authorization = `Bearer ${config.userToken}` headers.Authorization = `Bearer ${config.userToken}`
} else { } else {
headers["X-External-Source"] = config.externalSource
headers["X-External-Id"] = config.externalId || getGuestId() headers["X-External-Id"] = config.externalId || getGuestId()
if (config.externalName) { if (config.externalName) {
headers["X-External-Name"] = encodeURIComponent(config.externalName) headers["X-External-Name"] = encodeURIComponent(config.externalName)
@@ -218,7 +212,7 @@ export function fetchImMessages(
) )
} }
/** 外部身份仅通过 createImHeaders()Authorization 或 X-External-*)传递,无 JSON body */ /** 外部身份仅通过 createImHeaders()Authorization 或 X-External-Id/Name)传递,无 JSON body */
export function createOrMatchImConversation() { export function createOrMatchImConversation() {
return request<ImConversation>("/api/conversation/create_or_match", { return request<ImConversation>("/api/conversation/create_or_match", {
...createRequestOptions({ method: "POST" }), ...createRequestOptions({ method: "POST" }),
+1 -4
View File
@@ -22,9 +22,6 @@ export function createImRealtimeConnection() {
const resolvedExternalId = encodeURIComponent( const resolvedExternalId = encodeURIComponent(
(config.externalId ?? "").trim() || getGuestId() (config.externalId ?? "").trim() || getGuestId()
) )
const externalSource = encodeURIComponent(
(config.externalSource ?? "web_chat").trim() || "web_chat"
)
const channelId = encodeURIComponent(config.channelId || "") const channelId = encodeURIComponent(config.channelId || "")
const userToken = (config.userToken ?? "").trim() const userToken = (config.userToken ?? "").trim()
if (userToken) { if (userToken) {
@@ -38,6 +35,6 @@ export function createImRealtimeConnection() {
? `&externalName=${encodeURIComponent(externalName)}` ? `&externalName=${encodeURIComponent(externalName)}`
: "" : ""
return new WebSocket( return new WebSocket(
`${baseUrl}/api/ws/open?externalId=${resolvedExternalId}&externalSource=${externalSource}&channelId=${channelId}${nameQuery}` `${baseUrl}/api/ws/open?externalId=${resolvedExternalId}&channelId=${channelId}${nameQuery}`
) )
} }
-6
View File
@@ -2,8 +2,6 @@ export type KefuWidgetHostConfig = {
channelId: string channelId: string
baseUrl: string baseUrl: string
apiBaseUrl?: string apiBaseUrl?: string
/** 与后端 enums.ExternalSource 一致,默认 web_chat */
externalSource?: string
/** 外部访客稳定标识;未传时使用浏览器本地访客 ID */ /** 外部访客稳定标识;未传时使用浏览器本地访客 ID */
externalId?: string externalId?: string
/** 访客展示名,随请求以 X-External-Name / WS query externalName 传给后端 */ /** 访客展示名,随请求以 X-External-Name / WS query externalName 传给后端 */
@@ -48,10 +46,6 @@ export function readKefuWidgetConfig(): KefuWidgetHostConfig {
query.get("apiBaseUrl") ?? query.get("apiBaseUrl") ??
process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ?? process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ??
undefined, undefined,
externalSource:
query.get("externalSource") ??
process.env.NEXT_PUBLIC_OPEN_IM_EXTERNAL_SOURCE?.trim() ??
undefined,
externalId: query.get("externalId") ?? undefined, externalId: query.get("externalId") ?? undefined,
externalName: query.get("externalName") ?? undefined, externalName: query.get("externalName") ?? undefined,
userToken: query.get("userToken") ?? undefined, userToken: query.get("userToken") ?? undefined,
-3
View File
@@ -3,7 +3,6 @@
position: "right", position: "right",
themeColor: "#0f6cbd", themeColor: "#0f6cbd",
width: "380px", width: "380px",
externalSource: "web_chat",
}; };
var state = window.__CS_AGENT_WIDGET_STATE__; var state = window.__CS_AGENT_WIDGET_STATE__;
@@ -47,7 +46,6 @@
delete merged.apiBaseUrl; delete merged.apiBaseUrl;
} }
merged.channelId = String(merged.channelId || ""); merged.channelId = String(merged.channelId || "");
merged.externalSource = String(merged.externalSource || "web_chat");
if (merged.userToken) { if (merged.userToken) {
merged.userToken = String(merged.userToken); merged.userToken = String(merged.userToken);
} }
@@ -68,7 +66,6 @@
frameUrl.searchParams.set("channelId", config.channelId); frameUrl.searchParams.set("channelId", config.channelId);
frameUrl.searchParams.set("baseUrl", config.baseUrl); frameUrl.searchParams.set("baseUrl", config.baseUrl);
if (config.apiBaseUrl) frameUrl.searchParams.set("apiBaseUrl", config.apiBaseUrl); if (config.apiBaseUrl) frameUrl.searchParams.set("apiBaseUrl", config.apiBaseUrl);
if (config.externalSource) frameUrl.searchParams.set("externalSource", config.externalSource);
if (config.externalName) frameUrl.searchParams.set("externalName", config.externalName); if (config.externalName) frameUrl.searchParams.set("externalName", config.externalName);
if (config.userToken) frameUrl.searchParams.set("userToken", config.userToken); if (config.userToken) frameUrl.searchParams.set("userToken", config.userToken);
return frameUrl; return frameUrl;
+1 -3
View File
@@ -268,12 +268,10 @@ export const useKefuChatStore = create<KefuChatStore>((set, get) => {
return return
} }
if (widgetConfig.channelId || widgetConfig.externalSource) { if (widgetConfig.channelId) {
setKefuWidgetConfig({ setKefuWidgetConfig({
...readKefuWidgetConfig(), ...readKefuWidgetConfig(),
channelId: widgetConfig.channelId || readKefuWidgetConfig().channelId, channelId: widgetConfig.channelId || readKefuWidgetConfig().channelId,
externalSource:
widgetConfig.externalSource || readKefuWidgetConfig().externalSource,
}) })
} }
-3
View File
@@ -3,7 +3,6 @@
position: "right", position: "right",
themeColor: "#0f6cbd", themeColor: "#0f6cbd",
width: "380px", width: "380px",
externalSource: "web_chat",
}; };
var state = window.__CS_AGENT_WIDGET_STATE__; var state = window.__CS_AGENT_WIDGET_STATE__;
@@ -42,7 +41,6 @@
merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, ""); merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, "");
merged.apiBaseUrl = String(merged.apiBaseUrl || merged.baseUrl).replace(/\/$/, ""); merged.apiBaseUrl = String(merged.apiBaseUrl || merged.baseUrl).replace(/\/$/, "");
merged.channelId = String(merged.channelId || ""); merged.channelId = String(merged.channelId || "");
merged.externalSource = String(merged.externalSource || "web_chat");
if (merged.userToken) { if (merged.userToken) {
merged.userToken = String(merged.userToken); merged.userToken = String(merged.userToken);
} }
@@ -63,7 +61,6 @@
frameUrl.searchParams.set("channelId", config.channelId); frameUrl.searchParams.set("channelId", config.channelId);
frameUrl.searchParams.set("baseUrl", config.baseUrl); frameUrl.searchParams.set("baseUrl", config.baseUrl);
if (config.apiBaseUrl) frameUrl.searchParams.set("apiBaseUrl", config.apiBaseUrl); if (config.apiBaseUrl) frameUrl.searchParams.set("apiBaseUrl", config.apiBaseUrl);
if (config.externalSource) frameUrl.searchParams.set("externalSource", config.externalSource);
if (config.title) frameUrl.searchParams.set("title", config.title); if (config.title) frameUrl.searchParams.set("title", config.title);
if (config.subtitle) frameUrl.searchParams.set("subtitle", config.subtitle); if (config.subtitle) frameUrl.searchParams.set("subtitle", config.subtitle);
if (config.position) frameUrl.searchParams.set("position", config.position); if (config.position) frameUrl.searchParams.set("position", config.position);
File diff suppressed because one or more lines are too long