@omnizap-system/omnizap 2.6.1 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +78 -9
- package/.github/workflows/ci.yml +3 -3
- package/.github/workflows/security-runner-hardening.yml +1 -1
- package/.github/workflows/security-zap-full-scan.yml +1 -0
- package/app/config/index.js +6 -0
- package/app/configParts/adminIdentity.js +36 -7
- package/app/configParts/baileysConfig.js +343 -56
- package/app/configParts/groupUtils.js +226 -0
- package/app/configParts/loggerConfig.js +185 -0
- package/app/configParts/messagePersistenceService.js +307 -5
- package/app/configParts/sessionConfig.js +242 -0
- package/app/connection/baileysCompatibility.test.js +10 -1
- package/app/connection/baileysDbAuthState.js +205 -9
- package/app/connection/baileysLibsignalPatch.js +210 -0
- package/app/connection/groupOwnerWriteStateResolver.js +141 -0
- package/app/connection/socketController.js +694 -123
- package/app/connection/socketController.multiSession.test.js +128 -0
- package/app/controllers/messageController.js +1 -1
- package/app/controllers/messagePipeline/commandMiddleware.js +12 -10
- package/app/controllers/messagePipeline/conversationMiddleware.js +2 -1
- package/app/controllers/messagePipeline/messagePipelineMiddlewares.test.js +104 -0
- package/app/controllers/messagePipeline/preProcessingMiddlewares.js +96 -4
- package/app/controllers/messageProcessingPipeline.js +90 -9
- package/app/controllers/messageProcessingPipeline.test.js +202 -0
- package/app/modules/adminModule/AGENT.md +1 -1
- package/app/modules/adminModule/commandConfig.json +3318 -1347
- package/app/modules/adminModule/groupCommandHandlers.js +856 -14
- package/app/modules/adminModule/groupCommandHandlers.test.js +375 -9
- package/app/modules/adminModule/groupWarningRepository.js +152 -0
- package/app/modules/aiModule/AGENT.md +47 -30
- package/app/modules/aiModule/aiConfigRuntime.js +1 -0
- package/app/modules/aiModule/catCommand.js +132 -25
- package/app/modules/aiModule/commandConfig.json +114 -28
- package/app/modules/analyticsModule/messageAnalysisEventRepository.js +54 -6
- package/app/modules/gameModule/AGENT.md +1 -1
- package/app/modules/gameModule/commandConfig.json +29 -0
- package/app/modules/menuModule/AGENT.md +1 -1
- package/app/modules/menuModule/commandConfig.json +45 -10
- package/app/modules/menuModule/menuCatalogService.js +190 -0
- package/app/modules/menuModule/menuCommandUsageRepository.js +109 -0
- package/app/modules/menuModule/menuDynamicService.js +511 -0
- package/app/modules/menuModule/menuDynamicService.test.js +141 -0
- package/app/modules/menuModule/menus.js +36 -5
- package/app/modules/playModule/AGENT.md +10 -5
- package/app/modules/playModule/commandConfig.json +74 -16
- package/app/modules/playModule/playCommandConstants.js +13 -7
- package/app/modules/playModule/playCommandCore.js +4 -6
- package/app/modules/playModule/{playCommandYtDlpClient.js → playCommandMediaClient.js} +684 -332
- package/app/modules/playModule/playConfigRuntime.js +5 -6
- package/app/modules/playModule/playModuleCriticalFlows.test.js +44 -59
- package/app/modules/quoteModule/AGENT.md +1 -1
- package/app/modules/quoteModule/commandConfig.json +29 -0
- package/app/modules/rpgPokemonModule/AGENT.md +1 -1
- package/app/modules/rpgPokemonModule/commandConfig.json +29 -0
- package/app/modules/statsModule/AGENT.md +1 -1
- package/app/modules/statsModule/commandConfig.json +58 -0
- package/app/modules/stickerModule/AGENT.md +1 -1
- package/app/modules/stickerModule/commandConfig.json +145 -0
- package/app/modules/stickerPackModule/AGENT.md +1 -1
- package/app/modules/stickerPackModule/autoPackCollectorService.js +5 -1
- package/app/modules/stickerPackModule/commandConfig.json +29 -0
- package/app/modules/stickerPackModule/stickerAutoPackByTagsRuntime.js +1 -1
- package/app/modules/stickerPackModule/stickerPackCommandHandlers.js +78 -57
- package/app/modules/stickerPackModule/stickerPackService.js +13 -6
- package/app/modules/systemMetricsModule/AGENT.md +1 -1
- package/app/modules/systemMetricsModule/commandConfig.json +29 -0
- package/app/modules/tiktokModule/AGENT.md +1 -1
- package/app/modules/tiktokModule/commandConfig.json +29 -0
- package/app/modules/userModule/AGENT.md +1 -1
- package/app/modules/userModule/commandConfig.json +29 -0
- package/app/modules/waifuPicsModule/AGENT.md +57 -27
- package/app/modules/waifuPicsModule/commandConfig.json +87 -0
- package/app/observability/metrics.js +136 -0
- package/app/services/ai/commandConfigEnrichmentService.js +229 -47
- package/app/services/ai/geminiService.js +131 -7
- package/app/services/ai/geminiService.test.js +59 -2
- package/app/services/ai/moduleAiHelpCoreService.js +33 -4
- package/app/services/group/groupMetadataService.js +24 -1
- package/app/services/infra/dbWriteQueue.js +51 -21
- package/app/services/messaging/newsBroadcastService.js +843 -27
- package/app/services/multiSession/assignmentBalancerService.js +452 -0
- package/app/services/multiSession/groupOwnershipRepository.js +346 -0
- package/app/services/multiSession/groupOwnershipService.js +809 -0
- package/app/services/multiSession/groupOwnershipService.test.js +317 -0
- package/app/services/multiSession/sessionRegistryService.js +239 -0
- package/app/store/aiPromptStore.js +36 -19
- package/app/store/groupConfigStore.js +41 -5
- package/app/store/premiumUserStore.js +21 -7
- package/app/utils/antiLink/antiLinkModule.js +391 -25
- package/app/workers/aiHelperContinuousLearningWorker.js +512 -0
- package/database/index.js +6 -0
- package/database/migrations/20260307_d0_hardening_down.sql +1 -1
- package/database/migrations/20260314_d7_canonical_sender_down.sql +1 -1
- package/database/migrations/20260406_d30_security_analytics_down.sql +1 -1
- package/database/migrations/20260411_d35_group_community_metadata_down.sql +59 -0
- package/database/migrations/20260411_d35_group_community_metadata_up.sql +62 -0
- package/database/migrations/20260412_d36_system_config_tables_down.sql +32 -0
- package/database/migrations/20260412_d36_system_config_tables_up.sql +66 -0
- package/database/migrations/20260413_d37_group_user_warnings_down.sql +11 -0
- package/database/migrations/20260413_d37_group_user_warnings_up.sql +24 -0
- package/database/migrations/20260414_d38_multi_session_foundation_down.sql +72 -0
- package/database/migrations/20260414_d38_multi_session_foundation_up.sql +125 -0
- package/database/migrations/20260414_d39_multi_session_cutover_down.sql +103 -0
- package/database/migrations/20260414_d39_multi_session_cutover_up.sql +83 -0
- package/database/schema.sql +102 -1
- package/docker-compose.yml +4 -1
- package/docs/compliance/acceptable-use-policy-2026-03-07.md +1 -1
- package/docs/compliance/privacy-policy-2026-03-07.md +2 -2
- package/docs/security/dsar-lgpd-runbook-2026-03-07.md +1 -1
- package/docs/security/network-hardening-runbook-2026-03-07.md +53 -0
- package/docs/security/omnizap-static-security-headers.conf +25 -0
- package/ecosystem.prod.config.cjs +31 -11
- package/index.js +52 -18
- package/observability/alert-rules.yml +20 -0
- package/observability/grafana/dashboards/omnizap-system-admin.json +229 -0
- package/observability/mysql-setup.sql +4 -4
- package/observability/system-admin-observability.md +26 -0
- package/package.json +14 -6
- package/public/comandos/commands-catalog.json +2253 -78
- package/public/css/payments-react.css +478 -0
- package/public/js/apps/commandsReactApp.js +267 -87
- package/public/js/apps/createPackApp.js +3 -3
- package/public/js/apps/homeReactApp.js +2 -2
- package/public/js/apps/paymentsCancelReactApp.js +45 -0
- package/public/js/apps/paymentsReactApp.js +399 -0
- package/public/js/apps/paymentsSuccessReactApp.js +148 -0
- package/public/js/apps/stickersApp.js +255 -103
- package/public/js/apps/termsReactApp.js +57 -8
- package/public/js/apps/userPasswordResetReactApp.js +406 -0
- package/public/js/apps/userReactApp.js +96 -47
- package/public/js/apps/userSystemAdmReactApp.js +1506 -0
- package/public/pages/pagamentos-cancelado.html +21 -0
- package/public/pages/pagamentos-sucesso.html +21 -0
- package/public/pages/pagamentos.html +30 -0
- package/public/pages/politica-de-privacidade.html +1 -1
- package/public/pages/stickers.html +5 -5
- package/public/pages/termos-de-uso-texto-integral.html +1 -1
- package/public/pages/termos-de-uso.html +1 -1
- package/public/pages/user-password-reset.html +3 -4
- package/public/pages/user-systemadm.html +8 -462
- package/public/pages/user.html +1 -1
- package/scripts/clear-whatsapp-session.sh +123 -0
- package/scripts/core-ai-mode.mjs +163 -0
- package/scripts/deploy.sh +13 -0
- package/scripts/enrich-command-config-ux-openai.mjs +492 -0
- package/scripts/generate-commands-catalog.mjs +155 -0
- package/scripts/new-whatsapp-session.sh +564 -0
- package/scripts/security-web-surface-check.mjs +218 -0
- package/server/controllers/admin/adminPanelHandlers.js +253 -3
- package/server/controllers/admin/systemAdminController.js +254 -0
- package/server/controllers/payments/paymentsController.js +731 -0
- package/server/controllers/sticker/stickerCatalogController.js +9 -23
- package/server/controllers/system/contactController.js +9 -17
- package/server/controllers/system/stickerCatalogSystemContext.js +27 -6
- package/server/controllers/system/systemController.js +228 -1
- package/server/controllers/userController.js +6 -0
- package/server/email/emailAutomationRuntime.js +36 -1
- package/server/email/emailAutomationService.js +42 -1
- package/server/email/emailTemplateService.js +140 -33
- package/server/http/httpRequestUtils.js +18 -14
- package/server/http/httpServer.js +8 -4
- package/server/middleware/securityHeaders.js +35 -3
- package/server/routes/admin/systemAdminRouter.js +6 -0
- package/server/routes/indexRouter.js +50 -6
- package/server/routes/observability/grafanaProxyRouter.js +254 -0
- package/server/routes/payments/paymentsRouter.js +47 -0
- package/server/routes/static/staticPageRouter.js +30 -1
- package/server/utils/publicContact.js +31 -0
- package/utils/whatsapp/contactEnv.js +39 -0
- package/vite.config.mjs +5 -1
- package/app/modules/playModule/local/installYtDlp.js +0 -25
- package/app/modules/playModule/local/ytDlpInstaller.js +0 -28
|
@@ -5,15 +5,37 @@ import { parseParticipantsFromDb } from '../services/group/groupMetadataService.
|
|
|
5
5
|
import { extractUserIdInfo, resolveUserIdCached } from './baileysConfig.js';
|
|
6
6
|
import { getActiveSocket, runSocketMethod } from './baileysConfig.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Comprimento mínimo de telefone válido para extração de usuário.
|
|
10
|
+
* @type {number}
|
|
11
|
+
*/
|
|
8
12
|
const USER_ID_DIGITS_MIN = 10;
|
|
13
|
+
/**
|
|
14
|
+
* Comprimento máximo de telefone válido para extração de usuário.
|
|
15
|
+
* @type {number}
|
|
16
|
+
*/
|
|
9
17
|
const USER_ID_DIGITS_MAX = 15;
|
|
18
|
+
/**
|
|
19
|
+
* Sufixo oficial de JID de grupos.
|
|
20
|
+
* @type {string}
|
|
21
|
+
*/
|
|
10
22
|
const GROUP_ID_SUFFIX = '@g.us';
|
|
11
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Converte valor para string não vazia (trim), ou vazio.
|
|
26
|
+
* @param {unknown} value
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
12
29
|
const _toNonEmptyString = (value) => {
|
|
13
30
|
if (typeof value !== 'string') return '';
|
|
14
31
|
return value.trim();
|
|
15
32
|
};
|
|
16
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Normaliza qualquer JID possível preservando entradas sem domínio.
|
|
36
|
+
* @param {unknown} value
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
17
39
|
const _normalizeAnyJid = (value) => {
|
|
18
40
|
const raw = _toNonEmptyString(value);
|
|
19
41
|
if (!raw) return '';
|
|
@@ -21,6 +43,11 @@ const _normalizeAnyJid = (value) => {
|
|
|
21
43
|
return normalizeJid(raw) || raw;
|
|
22
44
|
};
|
|
23
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Normaliza e valida ID de grupo.
|
|
48
|
+
* @param {unknown} groupId
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
24
51
|
const _normalizeGroupId = (groupId) => {
|
|
25
52
|
const normalized = _normalizeAnyJid(groupId);
|
|
26
53
|
if (!normalized) return '';
|
|
@@ -29,6 +56,11 @@ const _normalizeGroupId = (groupId) => {
|
|
|
29
56
|
return '';
|
|
30
57
|
};
|
|
31
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Normaliza candidatos de identidade de usuário (JID/LID/telefone).
|
|
61
|
+
* @param {unknown} value
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
32
64
|
const _normalizeUserIdCandidate = (value) => {
|
|
33
65
|
const raw = _toNonEmptyString(value);
|
|
34
66
|
if (!raw) return '';
|
|
@@ -46,10 +78,19 @@ const _normalizeUserIdCandidate = (value) => {
|
|
|
46
78
|
return jidCandidate;
|
|
47
79
|
};
|
|
48
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Coleta candidatos de identidade de usuário a partir de string/objeto.
|
|
83
|
+
* @param {unknown} value
|
|
84
|
+
* @returns {string[]}
|
|
85
|
+
*/
|
|
49
86
|
const _collectUserIdCandidates = (value) => {
|
|
50
87
|
if (!value) return [];
|
|
51
88
|
|
|
52
89
|
const candidates = [];
|
|
90
|
+
/**
|
|
91
|
+
* @param {unknown} candidate
|
|
92
|
+
* @returns {void}
|
|
93
|
+
*/
|
|
53
94
|
const pushCandidate = (candidate) => {
|
|
54
95
|
const normalized = _normalizeUserIdCandidate(candidate);
|
|
55
96
|
if (!normalized) return;
|
|
@@ -79,12 +120,21 @@ const _collectUserIdCandidates = (value) => {
|
|
|
79
120
|
return candidates;
|
|
80
121
|
};
|
|
81
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Extrai candidatos de identidade a partir de um participante.
|
|
125
|
+
* @param {unknown} participant
|
|
126
|
+
* @returns {string[]}
|
|
127
|
+
*/
|
|
82
128
|
const _extractParticipantCandidates = (participant) => {
|
|
83
129
|
if (!participant) return [];
|
|
84
130
|
const raw = typeof participant === 'string' ? { id: participant } : participant;
|
|
85
131
|
|
|
86
132
|
const info = extractUserIdInfo(raw);
|
|
87
133
|
const candidates = [];
|
|
134
|
+
/**
|
|
135
|
+
* @param {unknown} candidate
|
|
136
|
+
* @returns {void}
|
|
137
|
+
*/
|
|
88
138
|
const pushCandidate = (candidate) => {
|
|
89
139
|
const normalized = _normalizeUserIdCandidate(candidate);
|
|
90
140
|
if (!normalized) return;
|
|
@@ -106,6 +156,11 @@ const _extractParticipantCandidates = (participant) => {
|
|
|
106
156
|
return candidates;
|
|
107
157
|
};
|
|
108
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Resolve versão canônica de usuário via cache LID/JID.
|
|
161
|
+
* @param {unknown} value
|
|
162
|
+
* @returns {string}
|
|
163
|
+
*/
|
|
109
164
|
const _resolveCanonicalCachedUserId = (value) => {
|
|
110
165
|
const normalized = _normalizeUserIdCandidate(value);
|
|
111
166
|
if (!normalized) return '';
|
|
@@ -117,6 +172,12 @@ const _resolveCanonicalCachedUserId = (value) => {
|
|
|
117
172
|
return _normalizeUserIdCandidate(resolved || normalized);
|
|
118
173
|
};
|
|
119
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Verifica equivalência entre dois identificadores de usuário.
|
|
177
|
+
* @param {unknown} leftValue
|
|
178
|
+
* @param {unknown} rightValue
|
|
179
|
+
* @returns {boolean}
|
|
180
|
+
*/
|
|
120
181
|
const _areUserIdsEquivalent = (leftValue, rightValue) => {
|
|
121
182
|
const left = _normalizeUserIdCandidate(leftValue);
|
|
122
183
|
const right = _normalizeUserIdCandidate(rightValue);
|
|
@@ -142,8 +203,19 @@ const _areUserIdsEquivalent = (leftValue, rightValue) => {
|
|
|
142
203
|
return leftDigits === rightDigits || leftDigits.endsWith(rightDigits) || rightDigits.endsWith(leftDigits);
|
|
143
204
|
};
|
|
144
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Indica se um participante é admin/superadmin.
|
|
208
|
+
* @param {any} participant
|
|
209
|
+
* @returns {boolean}
|
|
210
|
+
*/
|
|
145
211
|
const _isParticipantAdmin = (participant) => Boolean(participant && (participant.admin === 'admin' || participant.admin === 'superadmin' || participant.isAdmin === true));
|
|
146
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Detecta se valor se comporta como socket Baileys.
|
|
215
|
+
* @param {unknown} value
|
|
216
|
+
* @param {string} [methodName]
|
|
217
|
+
* @returns {boolean}
|
|
218
|
+
*/
|
|
147
219
|
const _isSocketLike = (value, methodName) => {
|
|
148
220
|
if (!value || typeof value !== 'object') return false;
|
|
149
221
|
if (methodName && typeof value[methodName] === 'function') return true;
|
|
@@ -152,6 +224,12 @@ const _isSocketLike = (value, methodName) => {
|
|
|
152
224
|
return false;
|
|
153
225
|
};
|
|
154
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Resolve assinatura flexível `sock + args` para helpers de grupo.
|
|
229
|
+
* @param {string} methodName
|
|
230
|
+
* @param {any[]} [inputArgs=[]]
|
|
231
|
+
* @returns {{sock: any, args: any[]}}
|
|
232
|
+
*/
|
|
155
233
|
const _resolveSocketAndArgs = (methodName, inputArgs = []) => {
|
|
156
234
|
const [firstArg, ...remaining] = inputArgs;
|
|
157
235
|
if (_isSocketLike(firstArg, methodName)) {
|
|
@@ -167,6 +245,11 @@ const _resolveSocketAndArgs = (methodName, inputArgs = []) => {
|
|
|
167
245
|
};
|
|
168
246
|
};
|
|
169
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Normaliza lista de participantes removendo duplicados equivalentes.
|
|
250
|
+
* @param {any[]} [participants=[]]
|
|
251
|
+
* @returns {string[]}
|
|
252
|
+
*/
|
|
170
253
|
const _normalizeParticipantsInput = (participants = []) => {
|
|
171
254
|
if (!Array.isArray(participants)) return [];
|
|
172
255
|
const normalized = [];
|
|
@@ -179,6 +262,11 @@ const _normalizeParticipantsInput = (participants = []) => {
|
|
|
179
262
|
return normalized;
|
|
180
263
|
};
|
|
181
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Converte valor para número finito ou `null`.
|
|
267
|
+
* @param {unknown} value
|
|
268
|
+
* @returns {number|null}
|
|
269
|
+
*/
|
|
182
270
|
const _normalizeNumberOrNull = (value) => {
|
|
183
271
|
const parsed = Number(value);
|
|
184
272
|
return Number.isFinite(parsed) ? parsed : null;
|
|
@@ -254,11 +342,22 @@ export async function isUserAdmin(groupId, userIdOrObj) {
|
|
|
254
342
|
return await isUserAdminAsync(groupId, userIdOrObj);
|
|
255
343
|
}
|
|
256
344
|
|
|
345
|
+
/**
|
|
346
|
+
* Mantém apenas dígitos de uma string.
|
|
347
|
+
* @param {string} str
|
|
348
|
+
* @returns {string}
|
|
349
|
+
*/
|
|
257
350
|
export function _normalizeDigits(str) {
|
|
258
351
|
if (!str || typeof str !== 'string') return '';
|
|
259
352
|
return str.replace(/\D/g, '');
|
|
260
353
|
}
|
|
261
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Verifica se o participante corresponde ao usuário informado.
|
|
357
|
+
* @param {any} participant
|
|
358
|
+
* @param {unknown} userIdOrObj
|
|
359
|
+
* @returns {boolean}
|
|
360
|
+
*/
|
|
262
361
|
export function _matchesParticipantId(participant, userIdOrObj) {
|
|
263
362
|
if (!participant || !userIdOrObj) return false;
|
|
264
363
|
const participantCandidates = _extractParticipantCandidates(participant);
|
|
@@ -288,6 +387,7 @@ export async function getGroupInfoAsync(groupId) {
|
|
|
288
387
|
const participants = parseParticipantsFromDb(data.participants || data.participants_json || null);
|
|
289
388
|
const creation = _normalizeNumberOrNull(data.creation);
|
|
290
389
|
const ephemeralDuration = _normalizeNumberOrNull(data.ephemeral_duration ?? data.ephemeralDuration);
|
|
390
|
+
const linkedParent = _normalizeGroupId(data.linked_parent_jid || data.linkedParent) || null;
|
|
291
391
|
|
|
292
392
|
const group = {
|
|
293
393
|
id: _normalizeGroupId(data.id) || normalizedGroupId,
|
|
@@ -299,6 +399,10 @@ export async function getGroupInfoAsync(groupId) {
|
|
|
299
399
|
restrict: Boolean(data.restrict),
|
|
300
400
|
announce: Boolean(data.announce),
|
|
301
401
|
isCommunity: Boolean(data.is_community ?? data.isCommunity),
|
|
402
|
+
isCommunityAnnounce: Boolean(data.is_community_announce ?? data.isCommunityAnnounce),
|
|
403
|
+
linkedParent,
|
|
404
|
+
memberAddMode: data.member_add_mode === null || data.member_add_mode === undefined ? null : Boolean(data.member_add_mode),
|
|
405
|
+
joinApprovalMode: data.join_approval_mode === null || data.join_approval_mode === undefined ? null : Boolean(data.join_approval_mode),
|
|
302
406
|
addressingMode: data.addressing_mode || data.addressingMode || null,
|
|
303
407
|
ephemeralDuration,
|
|
304
408
|
};
|
|
@@ -310,11 +414,22 @@ export async function getGroupInfoAsync(groupId) {
|
|
|
310
414
|
}
|
|
311
415
|
}
|
|
312
416
|
|
|
417
|
+
/**
|
|
418
|
+
* Retorna participantes normalizados do grupo.
|
|
419
|
+
* @param {string} groupId
|
|
420
|
+
* @returns {Promise<Array<object>|null>}
|
|
421
|
+
*/
|
|
313
422
|
export async function getGroupParticipantsAsync(groupId) {
|
|
314
423
|
const group = await getGroupInfoAsync(groupId);
|
|
315
424
|
return group ? group.participants : null;
|
|
316
425
|
}
|
|
317
426
|
|
|
427
|
+
/**
|
|
428
|
+
* Versão assíncrona de validação de admin no grupo.
|
|
429
|
+
* @param {string} groupId
|
|
430
|
+
* @param {string|object} userIdOrObj
|
|
431
|
+
* @returns {Promise<boolean>}
|
|
432
|
+
*/
|
|
318
433
|
export async function isUserAdminAsync(groupId, userIdOrObj) {
|
|
319
434
|
const normalizedGroupId = _normalizeGroupId(groupId);
|
|
320
435
|
const userCandidates = _collectUserIdCandidates(userIdOrObj);
|
|
@@ -326,6 +441,11 @@ export async function isUserAdminAsync(groupId, userIdOrObj) {
|
|
|
326
441
|
return participants.some((participant) => _isParticipantAdmin(participant) && userCandidates.some((candidate) => _matchesParticipantId(participant, candidate)));
|
|
327
442
|
}
|
|
328
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Retorna administradores normalizados de um grupo.
|
|
446
|
+
* @param {string} groupId
|
|
447
|
+
* @returns {Promise<string[]>}
|
|
448
|
+
*/
|
|
329
449
|
export async function getGroupAdminsAsync(groupId) {
|
|
330
450
|
const normalizedGroupId = _normalizeGroupId(groupId);
|
|
331
451
|
if (!_isValidId(normalizedGroupId, 'Grupo')) return [];
|
|
@@ -486,6 +606,14 @@ export async function _safeGroupApiCall(sock, functionName, args, errorMessage)
|
|
|
486
606
|
}
|
|
487
607
|
}
|
|
488
608
|
|
|
609
|
+
/**
|
|
610
|
+
* Cria grupo no WhatsApp.
|
|
611
|
+
* Aceita assinatura flexível com ou sem socket explícito.
|
|
612
|
+
* @param {any} sockOrTitle
|
|
613
|
+
* @param {string|Array<any>} titleOrParticipants
|
|
614
|
+
* @param {Array<any>} [participantsMaybe]
|
|
615
|
+
* @returns {Promise<any>}
|
|
616
|
+
*/
|
|
489
617
|
export async function createGroup(sockOrTitle, titleOrParticipants, participantsMaybe) {
|
|
490
618
|
const { sock, args } = _resolveSocketAndArgs('groupCreate', [sockOrTitle, titleOrParticipants, participantsMaybe]);
|
|
491
619
|
const [title, participants] = args;
|
|
@@ -504,6 +632,14 @@ export async function createGroup(sockOrTitle, titleOrParticipants, participants
|
|
|
504
632
|
return result;
|
|
505
633
|
}
|
|
506
634
|
|
|
635
|
+
/**
|
|
636
|
+
* Atualiza participantes de grupo (add/remove/promote/demote).
|
|
637
|
+
* @param {any} sockOrGroupId
|
|
638
|
+
* @param {string|Array<any>} groupIdOrParticipants
|
|
639
|
+
* @param {Array<any>|string} participantsOrAction
|
|
640
|
+
* @param {string} [actionMaybe]
|
|
641
|
+
* @returns {Promise<any>}
|
|
642
|
+
*/
|
|
507
643
|
export async function updateGroupParticipants(sockOrGroupId, groupIdOrParticipants, participantsOrAction, actionMaybe) {
|
|
508
644
|
const { sock, args } = _resolveSocketAndArgs('groupParticipantsUpdate', [sockOrGroupId, groupIdOrParticipants, participantsOrAction, actionMaybe]);
|
|
509
645
|
const [groupId, participants, action] = args;
|
|
@@ -519,6 +655,13 @@ export async function updateGroupParticipants(sockOrGroupId, groupIdOrParticipan
|
|
|
519
655
|
return _safeGroupApiCall(sock, 'groupParticipantsUpdate', [normalizedGroupId, normalizedParticipants, normalizedAction], `Erro ao ${normalizedAction} participantes no grupo ${normalizedGroupId}`);
|
|
520
656
|
}
|
|
521
657
|
|
|
658
|
+
/**
|
|
659
|
+
* Atualiza assunto do grupo.
|
|
660
|
+
* @param {any} sockOrGroupId
|
|
661
|
+
* @param {string} groupIdOrSubject
|
|
662
|
+
* @param {string} [subjectMaybe]
|
|
663
|
+
* @returns {Promise<any>}
|
|
664
|
+
*/
|
|
522
665
|
export async function updateGroupSubject(sockOrGroupId, groupIdOrSubject, subjectMaybe) {
|
|
523
666
|
const { sock, args } = _resolveSocketAndArgs('groupUpdateSubject', [sockOrGroupId, groupIdOrSubject, subjectMaybe]);
|
|
524
667
|
const [groupId, subject] = args;
|
|
@@ -533,6 +676,13 @@ export async function updateGroupSubject(sockOrGroupId, groupIdOrSubject, subjec
|
|
|
533
676
|
return _safeGroupApiCall(sock, 'groupUpdateSubject', [normalizedGroupId, normalizedSubject], `Erro ao atualizar assunto do grupo ${normalizedGroupId}`);
|
|
534
677
|
}
|
|
535
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Atualiza descrição do grupo.
|
|
681
|
+
* @param {any} sockOrGroupId
|
|
682
|
+
* @param {string} groupIdOrDescription
|
|
683
|
+
* @param {string} [descriptionMaybe]
|
|
684
|
+
* @returns {Promise<any>}
|
|
685
|
+
*/
|
|
536
686
|
export async function updateGroupDescription(sockOrGroupId, groupIdOrDescription, descriptionMaybe) {
|
|
537
687
|
const { sock, args } = _resolveSocketAndArgs('groupUpdateDescription', [sockOrGroupId, groupIdOrDescription, descriptionMaybe]);
|
|
538
688
|
const [groupId, description] = args;
|
|
@@ -545,6 +695,13 @@ export async function updateGroupDescription(sockOrGroupId, groupIdOrDescription
|
|
|
545
695
|
return _safeGroupApiCall(sock, 'groupUpdateDescription', [normalizedGroupId, description], `Erro ao atualizar descrição do grupo ${normalizedGroupId}`);
|
|
546
696
|
}
|
|
547
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Atualiza configuração geral do grupo.
|
|
700
|
+
* @param {any} sockOrGroupId
|
|
701
|
+
* @param {string} groupIdOrSetting
|
|
702
|
+
* @param {string} [settingMaybe]
|
|
703
|
+
* @returns {Promise<any>}
|
|
704
|
+
*/
|
|
548
705
|
export async function updateGroupSettings(sockOrGroupId, groupIdOrSetting, settingMaybe) {
|
|
549
706
|
const { sock, args } = _resolveSocketAndArgs('groupSettingUpdate', [sockOrGroupId, groupIdOrSetting, settingMaybe]);
|
|
550
707
|
const [groupId, setting] = args;
|
|
@@ -559,6 +716,12 @@ export async function updateGroupSettings(sockOrGroupId, groupIdOrSetting, setti
|
|
|
559
716
|
return _safeGroupApiCall(sock, 'groupSettingUpdate', [normalizedGroupId, normalizedSetting], `Erro ao atualizar configurações do grupo ${normalizedGroupId}`);
|
|
560
717
|
}
|
|
561
718
|
|
|
719
|
+
/**
|
|
720
|
+
* Sai de um grupo.
|
|
721
|
+
* @param {any} sockOrGroupId
|
|
722
|
+
* @param {string} [groupIdMaybe]
|
|
723
|
+
* @returns {Promise<any>}
|
|
724
|
+
*/
|
|
562
725
|
export async function leaveGroup(sockOrGroupId, groupIdMaybe) {
|
|
563
726
|
const { sock, args } = _resolveSocketAndArgs('groupLeave', [sockOrGroupId, groupIdMaybe]);
|
|
564
727
|
const [groupId] = args;
|
|
@@ -571,6 +734,12 @@ export async function leaveGroup(sockOrGroupId, groupIdMaybe) {
|
|
|
571
734
|
return _safeGroupApiCall(sock, 'groupLeave', [normalizedGroupId], `Erro ao sair do grupo ${normalizedGroupId}`);
|
|
572
735
|
}
|
|
573
736
|
|
|
737
|
+
/**
|
|
738
|
+
* Obtém código de convite do grupo.
|
|
739
|
+
* @param {any} sockOrGroupId
|
|
740
|
+
* @param {string} [groupIdMaybe]
|
|
741
|
+
* @returns {Promise<any>}
|
|
742
|
+
*/
|
|
574
743
|
export async function getGroupInviteCode(sockOrGroupId, groupIdMaybe) {
|
|
575
744
|
const { sock, args } = _resolveSocketAndArgs('groupInviteCode', [sockOrGroupId, groupIdMaybe]);
|
|
576
745
|
const [groupId] = args;
|
|
@@ -583,6 +752,12 @@ export async function getGroupInviteCode(sockOrGroupId, groupIdMaybe) {
|
|
|
583
752
|
return _safeGroupApiCall(sock, 'groupInviteCode', [normalizedGroupId], `Erro ao obter código de convite do grupo ${normalizedGroupId}`);
|
|
584
753
|
}
|
|
585
754
|
|
|
755
|
+
/**
|
|
756
|
+
* Revoga o código de convite atual do grupo.
|
|
757
|
+
* @param {any} sockOrGroupId
|
|
758
|
+
* @param {string} [groupIdMaybe]
|
|
759
|
+
* @returns {Promise<any>}
|
|
760
|
+
*/
|
|
586
761
|
export async function revokeGroupInviteCode(sockOrGroupId, groupIdMaybe) {
|
|
587
762
|
const { sock, args } = _resolveSocketAndArgs('groupRevokeInvite', [sockOrGroupId, groupIdMaybe]);
|
|
588
763
|
const [groupId] = args;
|
|
@@ -595,6 +770,12 @@ export async function revokeGroupInviteCode(sockOrGroupId, groupIdMaybe) {
|
|
|
595
770
|
return _safeGroupApiCall(sock, 'groupRevokeInvite', [normalizedGroupId], `Erro ao revogar código de convite do grupo ${normalizedGroupId}`);
|
|
596
771
|
}
|
|
597
772
|
|
|
773
|
+
/**
|
|
774
|
+
* Aceita convite de grupo via código.
|
|
775
|
+
* @param {any} sockOrCode
|
|
776
|
+
* @param {string} [codeMaybe]
|
|
777
|
+
* @returns {Promise<any>}
|
|
778
|
+
*/
|
|
598
779
|
export async function acceptGroupInvite(sockOrCode, codeMaybe) {
|
|
599
780
|
const { sock, args } = _resolveSocketAndArgs('groupAcceptInvite', [sockOrCode, codeMaybe]);
|
|
600
781
|
const [code] = args;
|
|
@@ -607,6 +788,12 @@ export async function acceptGroupInvite(sockOrCode, codeMaybe) {
|
|
|
607
788
|
return _safeGroupApiCall(sock, 'groupAcceptInvite', [normalizedCode], 'Erro ao aceitar convite de grupo');
|
|
608
789
|
}
|
|
609
790
|
|
|
791
|
+
/**
|
|
792
|
+
* Obtém metadados de convite de grupo.
|
|
793
|
+
* @param {any} sockOrCode
|
|
794
|
+
* @param {string} [codeMaybe]
|
|
795
|
+
* @returns {Promise<any>}
|
|
796
|
+
*/
|
|
610
797
|
export async function getGroupInfoFromInvite(sockOrCode, codeMaybe) {
|
|
611
798
|
const { sock, args } = _resolveSocketAndArgs('groupGetInviteInfo', [sockOrCode, codeMaybe]);
|
|
612
799
|
const [code] = args;
|
|
@@ -619,6 +806,12 @@ export async function getGroupInfoFromInvite(sockOrCode, codeMaybe) {
|
|
|
619
806
|
return _safeGroupApiCall(sock, 'groupGetInviteInfo', [normalizedCode], 'Erro ao obter informações do convite');
|
|
620
807
|
}
|
|
621
808
|
|
|
809
|
+
/**
|
|
810
|
+
* Obtém metadados completos do grupo.
|
|
811
|
+
* @param {any} sockOrGroupId
|
|
812
|
+
* @param {string} [groupIdMaybe]
|
|
813
|
+
* @returns {Promise<any>}
|
|
814
|
+
*/
|
|
622
815
|
export async function getGroupMetadata(sockOrGroupId, groupIdMaybe) {
|
|
623
816
|
const { sock, args } = _resolveSocketAndArgs('groupMetadata', [sockOrGroupId, groupIdMaybe]);
|
|
624
817
|
const [groupId] = args;
|
|
@@ -631,6 +824,12 @@ export async function getGroupMetadata(sockOrGroupId, groupIdMaybe) {
|
|
|
631
824
|
return _safeGroupApiCall(sock, 'groupMetadata', [normalizedGroupId], `Erro ao obter metadados do grupo ${normalizedGroupId}`);
|
|
632
825
|
}
|
|
633
826
|
|
|
827
|
+
/**
|
|
828
|
+
* Lista solicitações pendentes de entrada no grupo.
|
|
829
|
+
* @param {any} sockOrGroupId
|
|
830
|
+
* @param {string} [groupIdMaybe]
|
|
831
|
+
* @returns {Promise<any>}
|
|
832
|
+
*/
|
|
634
833
|
export async function getGroupRequestParticipantsList(sockOrGroupId, groupIdMaybe) {
|
|
635
834
|
const { sock, args } = _resolveSocketAndArgs('groupRequestParticipantsList', [sockOrGroupId, groupIdMaybe]);
|
|
636
835
|
const [groupId] = args;
|
|
@@ -643,6 +842,14 @@ export async function getGroupRequestParticipantsList(sockOrGroupId, groupIdMayb
|
|
|
643
842
|
return _safeGroupApiCall(sock, 'groupRequestParticipantsList', [normalizedGroupId], `Erro ao listar solicitações de entrada no grupo ${normalizedGroupId}`);
|
|
644
843
|
}
|
|
645
844
|
|
|
845
|
+
/**
|
|
846
|
+
* Atualiza solicitações de entrada no grupo.
|
|
847
|
+
* @param {any} sockOrGroupId
|
|
848
|
+
* @param {string|Array<any>} groupIdOrParticipants
|
|
849
|
+
* @param {Array<any>|string} participantsOrAction
|
|
850
|
+
* @param {string} [actionMaybe]
|
|
851
|
+
* @returns {Promise<any>}
|
|
852
|
+
*/
|
|
646
853
|
export async function updateGroupRequestParticipants(sockOrGroupId, groupIdOrParticipants, participantsOrAction, actionMaybe) {
|
|
647
854
|
const { sock, args } = _resolveSocketAndArgs('groupRequestParticipantsUpdate', [sockOrGroupId, groupIdOrParticipants, participantsOrAction, actionMaybe]);
|
|
648
855
|
const [groupId, participants, action] = args;
|
|
@@ -658,11 +865,23 @@ export async function updateGroupRequestParticipants(sockOrGroupId, groupIdOrPar
|
|
|
658
865
|
return _safeGroupApiCall(sock, 'groupRequestParticipantsUpdate', [normalizedGroupId, normalizedParticipants, normalizedAction], `Erro ao atualizar solicitações de entrada no grupo ${normalizedGroupId}`);
|
|
659
866
|
}
|
|
660
867
|
|
|
868
|
+
/**
|
|
869
|
+
* Busca todos os grupos participantes da conta conectada.
|
|
870
|
+
* @param {any} [sock]
|
|
871
|
+
* @returns {Promise<any>}
|
|
872
|
+
*/
|
|
661
873
|
export async function getAllParticipatingGroups(sock) {
|
|
662
874
|
const socket = _isSocketLike(sock, 'groupFetchAllParticipating') ? sock : null;
|
|
663
875
|
return _safeGroupApiCall(socket, 'groupFetchAllParticipating', [], 'Erro ao obter todos os grupos participantes');
|
|
664
876
|
}
|
|
665
877
|
|
|
878
|
+
/**
|
|
879
|
+
* Ativa/desativa mensagens efêmeras no grupo.
|
|
880
|
+
* @param {any} sockOrGroupId
|
|
881
|
+
* @param {string|number} groupIdOrDuration
|
|
882
|
+
* @param {number} [durationMaybe]
|
|
883
|
+
* @returns {Promise<any>}
|
|
884
|
+
*/
|
|
666
885
|
export async function toggleEphemeral(sockOrGroupId, groupIdOrDuration, durationMaybe) {
|
|
667
886
|
const { sock, args } = _resolveSocketAndArgs('groupToggleEphemeral', [sockOrGroupId, groupIdOrDuration, durationMaybe]);
|
|
668
887
|
const [groupId, duration] = args;
|
|
@@ -677,6 +896,13 @@ export async function toggleEphemeral(sockOrGroupId, groupIdOrDuration, duration
|
|
|
677
896
|
return _safeGroupApiCall(sock, 'groupToggleEphemeral', [normalizedGroupId, normalizedDuration], `Erro ao alternar mensagens efêmeras no grupo ${normalizedGroupId}`);
|
|
678
897
|
}
|
|
679
898
|
|
|
899
|
+
/**
|
|
900
|
+
* Atualiza modo de adição de membros no grupo.
|
|
901
|
+
* @param {any} sockOrGroupId
|
|
902
|
+
* @param {string} groupIdOrMode
|
|
903
|
+
* @param {string} [modeMaybe]
|
|
904
|
+
* @returns {Promise<any>}
|
|
905
|
+
*/
|
|
680
906
|
export async function updateGroupAddMode(sockOrGroupId, groupIdOrMode, modeMaybe) {
|
|
681
907
|
const { sock, args } = _resolveSocketAndArgs('groupMemberAddMode', [sockOrGroupId, groupIdOrMode, modeMaybe]);
|
|
682
908
|
const [groupId, mode] = args;
|