@automagik/omni 2.260609.4 → 2.260609.5
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/dist/index.js +1 -1
- package/dist/server/index.js +344 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -124971,7 +124971,7 @@ import { fileURLToPath } from "url";
|
|
|
124971
124971
|
// package.json
|
|
124972
124972
|
var package_default = {
|
|
124973
124973
|
name: "@automagik/omni",
|
|
124974
|
-
version: "2.260609.
|
|
124974
|
+
version: "2.260609.5",
|
|
124975
124975
|
description: "LLM-optimized CLI for Omni",
|
|
124976
124976
|
type: "module",
|
|
124977
124977
|
bin: {
|
package/dist/server/index.js
CHANGED
|
@@ -225245,7 +225245,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
225245
225245
|
var require_package7 = __commonJS((exports, module) => {
|
|
225246
225246
|
module.exports = {
|
|
225247
225247
|
name: "@omni/api",
|
|
225248
|
-
version: "2.260609.
|
|
225248
|
+
version: "2.260609.5",
|
|
225249
225249
|
type: "module",
|
|
225250
225250
|
exports: {
|
|
225251
225251
|
".": {
|
|
@@ -353209,6 +353209,27 @@ async function enrichContactNames(contacts, services, instanceId) {
|
|
|
353209
353209
|
contact.name = dbName;
|
|
353210
353210
|
}
|
|
353211
353211
|
}
|
|
353212
|
+
async function resolveInstancePlugin(services, channelRegistry2, instanceId) {
|
|
353213
|
+
const instance4 = await services.instances.getById(instanceId);
|
|
353214
|
+
if (!channelRegistry2) {
|
|
353215
|
+
return { ok: false, status: 503, error: { code: "NO_REGISTRY", message: "Channel registry not available" } };
|
|
353216
|
+
}
|
|
353217
|
+
const plugin7 = channelRegistry2.get(instance4.channel);
|
|
353218
|
+
if (!plugin7) {
|
|
353219
|
+
return {
|
|
353220
|
+
ok: false,
|
|
353221
|
+
status: 400,
|
|
353222
|
+
error: { code: "PLUGIN_NOT_FOUND", message: `No plugin for channel: ${instance4.channel}` }
|
|
353223
|
+
};
|
|
353224
|
+
}
|
|
353225
|
+
return { ok: true, plugin: plugin7 };
|
|
353226
|
+
}
|
|
353227
|
+
function participantUpdateResponse(result) {
|
|
353228
|
+
return {
|
|
353229
|
+
...result,
|
|
353230
|
+
changedCount: result.participants.length
|
|
353231
|
+
};
|
|
353232
|
+
}
|
|
353212
353233
|
function parseDuration(duration) {
|
|
353213
353234
|
const match2 = duration.match(/^(\d+)(s|m|h|d)$/);
|
|
353214
353235
|
if (!match2?.[1] || !match2[2])
|
|
@@ -353248,7 +353269,7 @@ function getCacheKey(instanceId, guildId) {
|
|
|
353248
353269
|
function invalidateGuildCache(instanceId, guildId) {
|
|
353249
353270
|
guildConfigCache.delete(getCacheKey(instanceId, guildId));
|
|
353250
353271
|
}
|
|
353251
|
-
var log108, instancesRoutes, instanceAccess2, listQuerySchema12, agentReplyFilterSchema, createInstanceSchema, updateInstanceSchema, DEFAULT_AGENT_REPLY_FILTER, SENSITIVE_INSTANCE_FIELDS, pairingCodeSchema, connectInstanceSchema, syncRequestSchema, listContactsQuerySchema, listGroupsQuerySchema, checkNumberSchema, updateBioSchema, blockContactSchema, resyncSchema, replaySchema, pairingActionSchema, guildConfigOverrideSchema, guildConfigCache, GUILD_CONFIG_TTL, presenceSchema;
|
|
353272
|
+
var log108, instancesRoutes, instanceAccess2, listQuerySchema12, agentReplyFilterSchema, createInstanceSchema, updateInstanceSchema, DEFAULT_AGENT_REPLY_FILTER, SENSITIVE_INSTANCE_FIELDS, pairingCodeSchema, connectInstanceSchema, syncRequestSchema, listContactsQuerySchema, listGroupsQuerySchema, checkNumberSchema, updateBioSchema, blockContactSchema, groupParticipantActionSchema, groupSettingSchema, groupParticipantsSchema, groupParticipantsPatchSchema, updateGroupSubjectSchema, updateGroupDescriptionSchema, updateGroupSettingsSchema, patchGroupSchema, resyncSchema, replaySchema, pairingActionSchema, guildConfigOverrideSchema, guildConfigCache, GUILD_CONFIG_TTL, presenceSchema;
|
|
353252
353273
|
var init_instances3 = __esm(() => {
|
|
353253
353274
|
init_dist6();
|
|
353254
353275
|
init_src();
|
|
@@ -354350,6 +354371,30 @@ var init_instances3 = __esm(() => {
|
|
|
354350
354371
|
return c.json({ error: { code: "REMOVE_FAILED", message: message2 } }, 500);
|
|
354351
354372
|
}
|
|
354352
354373
|
});
|
|
354374
|
+
groupParticipantActionSchema = exports_external.enum(["add", "remove", "promote", "demote"]);
|
|
354375
|
+
groupSettingSchema = exports_external.enum(["announcement", "not_announcement", "locked", "unlocked"]);
|
|
354376
|
+
groupParticipantsSchema = exports_external.object({
|
|
354377
|
+
participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to mutate")
|
|
354378
|
+
});
|
|
354379
|
+
groupParticipantsPatchSchema = groupParticipantsSchema.extend({
|
|
354380
|
+
action: groupParticipantActionSchema.describe("Participant mutation action")
|
|
354381
|
+
});
|
|
354382
|
+
updateGroupSubjectSchema = exports_external.object({
|
|
354383
|
+
subject: exports_external.string().min(1).max(100).describe("New group name/subject")
|
|
354384
|
+
});
|
|
354385
|
+
updateGroupDescriptionSchema = exports_external.object({
|
|
354386
|
+
description: exports_external.string().max(2048).describe("New group description. Empty string clears the description.")
|
|
354387
|
+
});
|
|
354388
|
+
updateGroupSettingsSchema = exports_external.object({
|
|
354389
|
+
setting: groupSettingSchema.describe("Group setting to apply")
|
|
354390
|
+
});
|
|
354391
|
+
patchGroupSchema = exports_external.object({
|
|
354392
|
+
subject: exports_external.string().min(1).max(100).optional(),
|
|
354393
|
+
description: exports_external.string().max(2048).optional(),
|
|
354394
|
+
setting: groupSettingSchema.optional()
|
|
354395
|
+
}).refine((value) => value.subject !== undefined || value.description !== undefined || value.setting !== undefined, {
|
|
354396
|
+
message: "At least one of subject, description, or setting is required"
|
|
354397
|
+
});
|
|
354353
354398
|
instancesRoutes.post("/:id/groups", instanceAccess2, zValidator("json", exports_external.object({
|
|
354354
354399
|
subject: exports_external.string().min(1).max(100).describe("Group name/subject"),
|
|
354355
354400
|
participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to add")
|
|
@@ -354369,6 +354414,218 @@ var init_instances3 = __esm(() => {
|
|
|
354369
354414
|
const result = await plugin7.groupCreate(id, subject, participants);
|
|
354370
354415
|
return c.json({ data: result }, 201);
|
|
354371
354416
|
});
|
|
354417
|
+
instancesRoutes.post("/:id/groups/:groupJid/participants", instanceAccess2, zValidator("json", groupParticipantsSchema), async (c) => {
|
|
354418
|
+
const id = c.req.param("id");
|
|
354419
|
+
const groupJid = c.req.param("groupJid");
|
|
354420
|
+
const { participants } = c.req.valid("json");
|
|
354421
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354422
|
+
if (!resolved.ok)
|
|
354423
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354424
|
+
if (typeof resolved.plugin.updateGroupParticipants !== "function") {
|
|
354425
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
|
|
354426
|
+
}
|
|
354427
|
+
try {
|
|
354428
|
+
const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, "add");
|
|
354429
|
+
return c.json({ success: true, data: participantUpdateResponse(result) });
|
|
354430
|
+
} catch (error3) {
|
|
354431
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354432
|
+
return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
|
|
354433
|
+
}
|
|
354434
|
+
});
|
|
354435
|
+
instancesRoutes.post("/:id/groups/:groupJid/participants/:action", instanceAccess2, zValidator("json", groupParticipantsSchema), async (c) => {
|
|
354436
|
+
const id = c.req.param("id");
|
|
354437
|
+
const groupJid = c.req.param("groupJid");
|
|
354438
|
+
const parsedAction = groupParticipantActionSchema.safeParse(c.req.param("action"));
|
|
354439
|
+
const { participants } = c.req.valid("json");
|
|
354440
|
+
if (!parsedAction.success) {
|
|
354441
|
+
return c.json({
|
|
354442
|
+
error: {
|
|
354443
|
+
code: "VALIDATION_ERROR",
|
|
354444
|
+
message: "Invalid group participant action. Expected add, remove, promote, or demote."
|
|
354445
|
+
}
|
|
354446
|
+
}, 400);
|
|
354447
|
+
}
|
|
354448
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354449
|
+
if (!resolved.ok)
|
|
354450
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354451
|
+
if (typeof resolved.plugin.updateGroupParticipants !== "function") {
|
|
354452
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
|
|
354453
|
+
}
|
|
354454
|
+
try {
|
|
354455
|
+
const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, parsedAction.data);
|
|
354456
|
+
return c.json({ success: true, data: participantUpdateResponse(result) });
|
|
354457
|
+
} catch (error3) {
|
|
354458
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354459
|
+
return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
|
|
354460
|
+
}
|
|
354461
|
+
});
|
|
354462
|
+
instancesRoutes.patch("/:id/groups/:groupJid/participants", instanceAccess2, zValidator("json", groupParticipantsPatchSchema), async (c) => {
|
|
354463
|
+
const id = c.req.param("id");
|
|
354464
|
+
const groupJid = c.req.param("groupJid");
|
|
354465
|
+
const { action, participants } = c.req.valid("json");
|
|
354466
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354467
|
+
if (!resolved.ok)
|
|
354468
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354469
|
+
if (typeof resolved.plugin.updateGroupParticipants !== "function") {
|
|
354470
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
|
|
354471
|
+
}
|
|
354472
|
+
try {
|
|
354473
|
+
const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, action);
|
|
354474
|
+
return c.json({ success: true, data: participantUpdateResponse(result) });
|
|
354475
|
+
} catch (error3) {
|
|
354476
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354477
|
+
return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
|
|
354478
|
+
}
|
|
354479
|
+
});
|
|
354480
|
+
instancesRoutes.patch("/:id/groups/:groupJid", instanceAccess2, zValidator("json", patchGroupSchema), async (c) => {
|
|
354481
|
+
const id = c.req.param("id");
|
|
354482
|
+
const groupJid = c.req.param("groupJid");
|
|
354483
|
+
const body = c.req.valid("json");
|
|
354484
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354485
|
+
if (!resolved.ok)
|
|
354486
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354487
|
+
if (body.subject !== undefined && typeof resolved.plugin.updateGroupSubject !== "function") {
|
|
354488
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
|
|
354489
|
+
}
|
|
354490
|
+
if (body.description !== undefined && typeof resolved.plugin.updateGroupDescription !== "function") {
|
|
354491
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
|
|
354492
|
+
}
|
|
354493
|
+
if (body.setting !== undefined && typeof resolved.plugin.updateGroupSettings !== "function") {
|
|
354494
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group settings updates" } }, 400);
|
|
354495
|
+
}
|
|
354496
|
+
try {
|
|
354497
|
+
const updated = [];
|
|
354498
|
+
if (body.subject !== undefined) {
|
|
354499
|
+
await resolved.plugin.updateGroupSubject?.(id, groupJid, body.subject);
|
|
354500
|
+
updated.push("subject");
|
|
354501
|
+
}
|
|
354502
|
+
if (body.description !== undefined) {
|
|
354503
|
+
await resolved.plugin.updateGroupDescription?.(id, groupJid, body.description);
|
|
354504
|
+
updated.push("description");
|
|
354505
|
+
}
|
|
354506
|
+
if (body.setting !== undefined) {
|
|
354507
|
+
await resolved.plugin.updateGroupSettings?.(id, groupJid, body.setting);
|
|
354508
|
+
updated.push("settings");
|
|
354509
|
+
}
|
|
354510
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, updated, ...body } });
|
|
354511
|
+
} catch (error3) {
|
|
354512
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354513
|
+
return c.json({ error: { code: "GROUP_UPDATE_FAILED", message: message2 } }, 500);
|
|
354514
|
+
}
|
|
354515
|
+
});
|
|
354516
|
+
instancesRoutes.put("/:id/groups/:groupJid/subject", instanceAccess2, zValidator("json", updateGroupSubjectSchema), async (c) => {
|
|
354517
|
+
const id = c.req.param("id");
|
|
354518
|
+
const groupJid = c.req.param("groupJid");
|
|
354519
|
+
const { subject } = c.req.valid("json");
|
|
354520
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354521
|
+
if (!resolved.ok)
|
|
354522
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354523
|
+
if (typeof resolved.plugin.updateGroupSubject !== "function") {
|
|
354524
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
|
|
354525
|
+
}
|
|
354526
|
+
try {
|
|
354527
|
+
await resolved.plugin.updateGroupSubject(id, groupJid, subject);
|
|
354528
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, subject, action: "group_subject_updated" } });
|
|
354529
|
+
} catch (error3) {
|
|
354530
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354531
|
+
return c.json({ error: { code: "GROUP_RENAME_FAILED", message: message2 } }, 500);
|
|
354532
|
+
}
|
|
354533
|
+
});
|
|
354534
|
+
instancesRoutes.post("/:id/groups/:groupJid/subject", instanceAccess2, zValidator("json", updateGroupSubjectSchema), async (c) => {
|
|
354535
|
+
const id = c.req.param("id");
|
|
354536
|
+
const groupJid = c.req.param("groupJid");
|
|
354537
|
+
const { subject } = c.req.valid("json");
|
|
354538
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354539
|
+
if (!resolved.ok)
|
|
354540
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354541
|
+
if (typeof resolved.plugin.updateGroupSubject !== "function") {
|
|
354542
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
|
|
354543
|
+
}
|
|
354544
|
+
try {
|
|
354545
|
+
await resolved.plugin.updateGroupSubject(id, groupJid, subject);
|
|
354546
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, subject, action: "group_subject_updated" } });
|
|
354547
|
+
} catch (error3) {
|
|
354548
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354549
|
+
return c.json({ error: { code: "GROUP_RENAME_FAILED", message: message2 } }, 500);
|
|
354550
|
+
}
|
|
354551
|
+
});
|
|
354552
|
+
instancesRoutes.put("/:id/groups/:groupJid/description", instanceAccess2, zValidator("json", updateGroupDescriptionSchema), async (c) => {
|
|
354553
|
+
const id = c.req.param("id");
|
|
354554
|
+
const groupJid = c.req.param("groupJid");
|
|
354555
|
+
const { description } = c.req.valid("json");
|
|
354556
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354557
|
+
if (!resolved.ok)
|
|
354558
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354559
|
+
if (typeof resolved.plugin.updateGroupDescription !== "function") {
|
|
354560
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
|
|
354561
|
+
}
|
|
354562
|
+
try {
|
|
354563
|
+
await resolved.plugin.updateGroupDescription(id, groupJid, description);
|
|
354564
|
+
return c.json({
|
|
354565
|
+
success: true,
|
|
354566
|
+
data: { instanceId: id, groupJid, description, action: "group_description_updated" }
|
|
354567
|
+
});
|
|
354568
|
+
} catch (error3) {
|
|
354569
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354570
|
+
return c.json({ error: { code: "GROUP_DESCRIPTION_FAILED", message: message2 } }, 500);
|
|
354571
|
+
}
|
|
354572
|
+
});
|
|
354573
|
+
instancesRoutes.post("/:id/groups/:groupJid/description", instanceAccess2, zValidator("json", updateGroupDescriptionSchema), async (c) => {
|
|
354574
|
+
const id = c.req.param("id");
|
|
354575
|
+
const groupJid = c.req.param("groupJid");
|
|
354576
|
+
const { description } = c.req.valid("json");
|
|
354577
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354578
|
+
if (!resolved.ok)
|
|
354579
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354580
|
+
if (typeof resolved.plugin.updateGroupDescription !== "function") {
|
|
354581
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
|
|
354582
|
+
}
|
|
354583
|
+
try {
|
|
354584
|
+
await resolved.plugin.updateGroupDescription(id, groupJid, description);
|
|
354585
|
+
return c.json({
|
|
354586
|
+
success: true,
|
|
354587
|
+
data: { instanceId: id, groupJid, description, action: "group_description_updated" }
|
|
354588
|
+
});
|
|
354589
|
+
} catch (error3) {
|
|
354590
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354591
|
+
return c.json({ error: { code: "GROUP_DESCRIPTION_FAILED", message: message2 } }, 500);
|
|
354592
|
+
}
|
|
354593
|
+
});
|
|
354594
|
+
instancesRoutes.post("/:id/groups/:groupJid/settings", instanceAccess2, zValidator("json", updateGroupSettingsSchema), async (c) => {
|
|
354595
|
+
const id = c.req.param("id");
|
|
354596
|
+
const groupJid = c.req.param("groupJid");
|
|
354597
|
+
const { setting } = c.req.valid("json");
|
|
354598
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354599
|
+
if (!resolved.ok)
|
|
354600
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354601
|
+
if (typeof resolved.plugin.updateGroupSettings !== "function") {
|
|
354602
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group settings updates" } }, 400);
|
|
354603
|
+
}
|
|
354604
|
+
try {
|
|
354605
|
+
await resolved.plugin.updateGroupSettings(id, groupJid, setting);
|
|
354606
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, setting, action: "group_settings_updated" } });
|
|
354607
|
+
} catch (error3) {
|
|
354608
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354609
|
+
return c.json({ error: { code: "GROUP_SETTINGS_FAILED", message: message2 } }, 500);
|
|
354610
|
+
}
|
|
354611
|
+
});
|
|
354612
|
+
instancesRoutes.post("/:id/groups/:groupJid/leave", instanceAccess2, async (c) => {
|
|
354613
|
+
const id = c.req.param("id");
|
|
354614
|
+
const groupJid = c.req.param("groupJid");
|
|
354615
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354616
|
+
if (!resolved.ok)
|
|
354617
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354618
|
+
if (typeof resolved.plugin.leaveGroup !== "function") {
|
|
354619
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support leaving groups" } }, 400);
|
|
354620
|
+
}
|
|
354621
|
+
try {
|
|
354622
|
+
await resolved.plugin.leaveGroup(id, groupJid);
|
|
354623
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, left: true } });
|
|
354624
|
+
} catch (error3) {
|
|
354625
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354626
|
+
return c.json({ error: { code: "GROUP_LEAVE_FAILED", message: message2 } }, 500);
|
|
354627
|
+
}
|
|
354628
|
+
});
|
|
354372
354629
|
instancesRoutes.get("/:id/chats/:chatId/invite", instanceAccess2, async (c) => {
|
|
354373
354630
|
const id = c.req.param("id");
|
|
354374
354631
|
const chatId = c.req.param("chatId");
|
|
@@ -482845,6 +483102,12 @@ function toJid(identifier, lidCache) {
|
|
|
482845
483102
|
}
|
|
482846
483103
|
return phoneJid;
|
|
482847
483104
|
}
|
|
483105
|
+
function toGroupJid(groupId) {
|
|
483106
|
+
if (groupId.endsWith(JID_SUFFIX.GROUP)) {
|
|
483107
|
+
return groupId;
|
|
483108
|
+
}
|
|
483109
|
+
return `${groupId}${JID_SUFFIX.GROUP}`;
|
|
483110
|
+
}
|
|
482848
483111
|
function fromJid(jid) {
|
|
482849
483112
|
const isGroup = jid.endsWith(JID_SUFFIX.GROUP);
|
|
482850
483113
|
const isBroadcast = jid.endsWith(JID_SUFFIX.BROADCAST);
|
|
@@ -486460,6 +486723,85 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
486460
486723
|
throw waError;
|
|
486461
486724
|
}
|
|
486462
486725
|
}
|
|
486726
|
+
async updateGroupParticipants(instanceId, groupJid, participants, action) {
|
|
486727
|
+
await this.humanDelay(instanceId);
|
|
486728
|
+
const sock = this.getSocket(instanceId);
|
|
486729
|
+
const jid = toGroupJid(groupJid);
|
|
486730
|
+
const participantJids = participants.map((participant) => toJid(participant));
|
|
486731
|
+
try {
|
|
486732
|
+
const result = await sock.groupParticipantsUpdate(jid, participantJids, action);
|
|
486733
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486734
|
+
this.logger.info("Group participants updated", {
|
|
486735
|
+
instanceId,
|
|
486736
|
+
groupJid: jid,
|
|
486737
|
+
action,
|
|
486738
|
+
participantCount: participantJids.length
|
|
486739
|
+
});
|
|
486740
|
+
return {
|
|
486741
|
+
groupJid: jid,
|
|
486742
|
+
action,
|
|
486743
|
+
participants: result.map((participant) => ({
|
|
486744
|
+
jid: participant.jid,
|
|
486745
|
+
status: participant.status
|
|
486746
|
+
}))
|
|
486747
|
+
};
|
|
486748
|
+
} catch (error) {
|
|
486749
|
+
const waError = mapBaileysError(error);
|
|
486750
|
+
throw waError;
|
|
486751
|
+
}
|
|
486752
|
+
}
|
|
486753
|
+
async updateGroupSubject(instanceId, groupJid, subject) {
|
|
486754
|
+
await this.humanDelay(instanceId);
|
|
486755
|
+
const sock = this.getSocket(instanceId);
|
|
486756
|
+
const jid = toGroupJid(groupJid);
|
|
486757
|
+
try {
|
|
486758
|
+
await sock.groupUpdateSubject(jid, subject);
|
|
486759
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486760
|
+
this.logger.info("Group subject updated", { instanceId, groupJid: jid });
|
|
486761
|
+
} catch (error) {
|
|
486762
|
+
const waError = mapBaileysError(error);
|
|
486763
|
+
throw waError;
|
|
486764
|
+
}
|
|
486765
|
+
}
|
|
486766
|
+
async updateGroupDescription(instanceId, groupJid, description) {
|
|
486767
|
+
await this.humanDelay(instanceId);
|
|
486768
|
+
const sock = this.getSocket(instanceId);
|
|
486769
|
+
const jid = toGroupJid(groupJid);
|
|
486770
|
+
try {
|
|
486771
|
+
await sock.groupUpdateDescription(jid, description);
|
|
486772
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486773
|
+
this.logger.info("Group description updated", { instanceId, groupJid: jid, cleared: !description });
|
|
486774
|
+
} catch (error) {
|
|
486775
|
+
const waError = mapBaileysError(error);
|
|
486776
|
+
throw waError;
|
|
486777
|
+
}
|
|
486778
|
+
}
|
|
486779
|
+
async updateGroupSettings(instanceId, groupJid, setting) {
|
|
486780
|
+
await this.humanDelay(instanceId);
|
|
486781
|
+
const sock = this.getSocket(instanceId);
|
|
486782
|
+
const jid = toGroupJid(groupJid);
|
|
486783
|
+
try {
|
|
486784
|
+
await sock.groupSettingUpdate(jid, setting);
|
|
486785
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486786
|
+
this.logger.info("Group settings updated", { instanceId, groupJid: jid, setting });
|
|
486787
|
+
} catch (error) {
|
|
486788
|
+
const waError = mapBaileysError(error);
|
|
486789
|
+
throw waError;
|
|
486790
|
+
}
|
|
486791
|
+
}
|
|
486792
|
+
async leaveGroup(instanceId, groupJid) {
|
|
486793
|
+
await this.humanDelay(instanceId);
|
|
486794
|
+
const sock = this.getSocket(instanceId);
|
|
486795
|
+
const jid = toGroupJid(groupJid);
|
|
486796
|
+
try {
|
|
486797
|
+
await sock.groupLeave(jid);
|
|
486798
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486799
|
+
this.logger.info("Left group", { instanceId, groupJid: jid });
|
|
486800
|
+
} catch (error) {
|
|
486801
|
+
const waError = mapBaileysError(error);
|
|
486802
|
+
throw waError;
|
|
486803
|
+
}
|
|
486804
|
+
}
|
|
486463
486805
|
async handleQrCode(instanceId, qrCode, expiresAt) {
|
|
486464
486806
|
await this.emitQrCode(instanceId, qrCode, expiresAt);
|
|
486465
486807
|
const config2 = this.instances.get(instanceId)?.config;
|