fix(web): save channel configs with nested channel_list patches (#2530)
Persist channel settings through the current channel_list schema, keeping common channel fields at the top level and channel-specific fields under settings. Return common fields and default config shapes from channel config endpoints, and add coverage for nested patches, missing channel defaults, and secret handling.
This commit is contained in:
1 parent
f32b303d2a
commit
a8d0b03515
6 files changed
+295
-14
No files matched your search
@@ -48,6 +48,14 @@ function asBool(value: unknown): boolean {
|
||||
return value === true
|
||||
}
|
||||
|
||||
const CHANNEL_COMMON_CONFIG_KEYS = new Set([
|
||||
"allow_from",
|
||||
"group_trigger",
|
||||
"placeholder",
|
||||
"reasoning_channel_id",
|
||||
"typing",
|
||||
])
|
||||
|
||||
function normalizeConfig(
|
||||
channel: SupportedChannel,
|
||||
rawConfig: ChannelConfig,
|
||||
@@ -67,33 +75,42 @@ function buildSavePayload(
|
||||
editConfig: ChannelConfig,
|
||||
enabled: boolean,
|
||||
): ChannelConfig {
|
||||
const payload: ChannelConfig = { enabled }
|
||||
const payload: ChannelConfig = { enabled, type: channel.config_key }
|
||||
const settings: ChannelConfig = {}
|
||||
|
||||
for (const [key, value] of Object.entries(editConfig)) {
|
||||
if (key.startsWith("_")) continue
|
||||
if (key === "enabled") continue
|
||||
if (CHANNEL_COMMON_CONFIG_KEYS.has(key)) {
|
||||
payload[key] = value
|
||||
continue
|
||||
}
|
||||
if (isSecretField(key)) continue
|
||||
|
||||
payload[key] = value
|
||||
settings[key] = value
|
||||
}
|
||||
|
||||
for (const [secretKey, editKey] of Object.entries(SECRET_FIELD_MAP)) {
|
||||
const incoming = asString(editConfig[editKey])
|
||||
if (incoming !== "") {
|
||||
payload[secretKey] = incoming
|
||||
settings[secretKey] = incoming
|
||||
continue
|
||||
}
|
||||
const existing = asString(editConfig[secretKey]).trim()
|
||||
if (existing !== "") {
|
||||
payload[secretKey] = existing
|
||||
settings[secretKey] = existing
|
||||
}
|
||||
}
|
||||
|
||||
if (channel.name === "whatsapp_native") {
|
||||
payload.use_native = true
|
||||
settings.use_native = true
|
||||
}
|
||||
if (channel.name === "whatsapp") {
|
||||
payload.use_native = false
|
||||
settings.use_native = false
|
||||
}
|
||||
|
||||
if (Object.keys(settings).length > 0) {
|
||||
payload.settings = settings
|
||||
}
|
||||
|
||||
return payload
|
||||
@@ -377,7 +394,7 @@ export function ChannelConfigPage({ channelName }: ChannelConfigPageProps) {
|
||||
setFieldErrors({})
|
||||
try {
|
||||
await patchAppConfig({
|
||||
channels: {
|
||||
channel_list: {
|
||||
[channel.config_key]: savePayload,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -130,9 +130,10 @@ export function WecomForm({
|
||||
setToggleError("")
|
||||
try {
|
||||
await patchAppConfig({
|
||||
channels: {
|
||||
channel_list: {
|
||||
wecom: {
|
||||
enabled: checked,
|
||||
type: "wecom",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user