mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 01:53:21 +08:00
Sync WhatsApp group subjects into access UI (4.9.1-ops.10).
Refresh missing/forced group titles via groupMetadata and participating catalog so cards show real names instead of bare JIDs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a169b164a8
commit
f96157da1e
13 changed files with 568 additions and 260 deletions
|
|
@ -2,6 +2,7 @@ import { validateAccessGrant, normalizeAccessGrant } from '../../../../src/chann
|
|||
|
||||
export const SET_ACCESS_GRANT_ENDPOINT = 'bot.access-grant.set';
|
||||
export const RESOLVE_ACCESS_PENDING_ENDPOINT = 'bot.access-pending.resolve';
|
||||
export const REFRESH_ACCESS_GROUP_TITLES_ENDPOINT = 'bot.access-group-titles.refresh';
|
||||
|
||||
export function validAccessGrantPayload(payload) {
|
||||
try {
|
||||
|
|
@ -41,6 +42,21 @@ export function validAccessPendingResolvePayload(payload) {
|
|||
}
|
||||
}
|
||||
|
||||
export function validAccessGroupTitlesRefreshPayload(payload) {
|
||||
try {
|
||||
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return false;
|
||||
if (!Object.hasOwn(payload, 'botId') || typeof payload.botId !== 'string'
|
||||
|| !/^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)) return false;
|
||||
const keys = Reflect.ownKeys(payload);
|
||||
if (keys.length === 1) return true;
|
||||
if (keys.length !== 2 || !Object.hasOwn(payload, 'groupJids')) return false;
|
||||
if (!Array.isArray(payload.groupJids)) return false;
|
||||
return payload.groupJids.every((jid) => typeof jid === 'string' && /^\d{5,32}@g\.us$/.test(jid));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function publicAccessGrant(grant) {
|
||||
const normalized = normalizeAccessGrant(grant);
|
||||
if (!normalized) return null;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ import QRCode from 'qrcode';
|
|||
import { publicConnectionTestResult } from '../../../../src/channels/shared/connection-test.mjs';
|
||||
import { SET_ACCESS_POLICY_ENDPOINT, validAccessPolicyPayload } from '../shared/access-policy-rpc.mjs';
|
||||
import {
|
||||
REFRESH_ACCESS_GROUP_TITLES_ENDPOINT,
|
||||
RESOLVE_ACCESS_PENDING_ENDPOINT,
|
||||
SET_ACCESS_GRANT_ENDPOINT,
|
||||
validAccessGrantPayload,
|
||||
validAccessGroupTitlesRefreshPayload,
|
||||
validAccessPendingResolvePayload,
|
||||
} from '../shared/access-grant-rpc.mjs';
|
||||
import { SET_GROUP_SESSION_SCOPE_ENDPOINT, validGroupSessionScopePayload } from '../shared/group-session-scope-rpc.mjs';
|
||||
|
|
@ -25,6 +27,7 @@ export const WHATSAPP_ENDPOINTS = Object.freeze({
|
|||
setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
|
||||
setAccessGrant: SET_ACCESS_GRANT_ENDPOINT,
|
||||
resolveAccessPending: RESOLVE_ACCESS_PENDING_ENDPOINT,
|
||||
refreshAccessGroupTitles: REFRESH_ACCESS_GROUP_TITLES_ENDPOINT,
|
||||
setGroupSessionScope: SET_GROUP_SESSION_SCOPE_ENDPOINT,
|
||||
setWorkspace: SET_WORKSPACE_ENDPOINT,
|
||||
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
||||
|
|
@ -76,6 +79,10 @@ function payloadFailure(endpoint, payload) {
|
|||
return validAccessPendingResolvePayload(payload)
|
||||
? null : '请提交有效的审批请求。';
|
||||
}
|
||||
if (endpoint === WHATSAPP_ENDPOINTS.refreshAccessGroupTitles) {
|
||||
return validAccessGroupTitlesRefreshPayload(payload)
|
||||
? null : '请提交有效的群名同步请求。';
|
||||
}
|
||||
if (endpoint === WHATSAPP_ENDPOINTS.setGroupSessionScope) {
|
||||
return validGroupSessionScopePayload(payload)
|
||||
? null : '请提交有效的群会话策略。';
|
||||
|
|
@ -230,6 +237,14 @@ export function createWhatsappRpcHandler(controller, { encodeQr = qrDataUrl } =
|
|||
},
|
||||
(status) => publicStatus(status, cachedEncode),
|
||||
);
|
||||
} else if (endpoint === WHATSAPP_ENDPOINTS.refreshAccessGroupTitles) {
|
||||
if (typeof controller.refreshAccessGroupTitles !== 'function') {
|
||||
throw new Error('Group title refresh is unavailable');
|
||||
}
|
||||
value = await publicStatus(
|
||||
await controller.refreshAccessGroupTitles(payload.botId, payload.groupJids),
|
||||
cachedEncode,
|
||||
);
|
||||
} else if (endpoint === WHATSAPP_ENDPOINTS.setGroupSessionScope) {
|
||||
if (typeof controller.updateGroupSessionScope !== 'function') throw new Error('Group session scope update is unavailable');
|
||||
value = await controller.updateGroupSessionScope(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue