@automagik/omni 2.260603.5 → 2.260609.1
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.
|
|
124974
|
+
version: "2.260609.1",
|
|
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.
|
|
225248
|
+
version: "2.260609.1",
|
|
225249
225249
|
type: "module",
|
|
225250
225250
|
exports: {
|
|
225251
225251
|
".": {
|
|
@@ -353111,6 +353111,27 @@ async function enrichContactNames(contacts, services, instanceId) {
|
|
|
353111
353111
|
contact.name = dbName;
|
|
353112
353112
|
}
|
|
353113
353113
|
}
|
|
353114
|
+
async function resolveInstancePlugin(services, channelRegistry2, instanceId) {
|
|
353115
|
+
const instance4 = await services.instances.getById(instanceId);
|
|
353116
|
+
if (!channelRegistry2) {
|
|
353117
|
+
return { ok: false, status: 503, error: { code: "NO_REGISTRY", message: "Channel registry not available" } };
|
|
353118
|
+
}
|
|
353119
|
+
const plugin7 = channelRegistry2.get(instance4.channel);
|
|
353120
|
+
if (!plugin7) {
|
|
353121
|
+
return {
|
|
353122
|
+
ok: false,
|
|
353123
|
+
status: 400,
|
|
353124
|
+
error: { code: "PLUGIN_NOT_FOUND", message: `No plugin for channel: ${instance4.channel}` }
|
|
353125
|
+
};
|
|
353126
|
+
}
|
|
353127
|
+
return { ok: true, plugin: plugin7 };
|
|
353128
|
+
}
|
|
353129
|
+
function participantUpdateResponse(result) {
|
|
353130
|
+
return {
|
|
353131
|
+
...result,
|
|
353132
|
+
changedCount: result.participants.length
|
|
353133
|
+
};
|
|
353134
|
+
}
|
|
353114
353135
|
function parseDuration(duration) {
|
|
353115
353136
|
const match2 = duration.match(/^(\d+)(s|m|h|d)$/);
|
|
353116
353137
|
if (!match2?.[1] || !match2[2])
|
|
@@ -353150,7 +353171,7 @@ function getCacheKey(instanceId, guildId) {
|
|
|
353150
353171
|
function invalidateGuildCache(instanceId, guildId) {
|
|
353151
353172
|
guildConfigCache.delete(getCacheKey(instanceId, guildId));
|
|
353152
353173
|
}
|
|
353153
|
-
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;
|
|
353174
|
+
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;
|
|
353154
353175
|
var init_instances3 = __esm(() => {
|
|
353155
353176
|
init_dist6();
|
|
353156
353177
|
init_src();
|
|
@@ -354252,6 +354273,30 @@ var init_instances3 = __esm(() => {
|
|
|
354252
354273
|
return c.json({ error: { code: "REMOVE_FAILED", message: message2 } }, 500);
|
|
354253
354274
|
}
|
|
354254
354275
|
});
|
|
354276
|
+
groupParticipantActionSchema = exports_external.enum(["add", "remove", "promote", "demote"]);
|
|
354277
|
+
groupSettingSchema = exports_external.enum(["announcement", "not_announcement", "locked", "unlocked"]);
|
|
354278
|
+
groupParticipantsSchema = exports_external.object({
|
|
354279
|
+
participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to mutate")
|
|
354280
|
+
});
|
|
354281
|
+
groupParticipantsPatchSchema = groupParticipantsSchema.extend({
|
|
354282
|
+
action: groupParticipantActionSchema.describe("Participant mutation action")
|
|
354283
|
+
});
|
|
354284
|
+
updateGroupSubjectSchema = exports_external.object({
|
|
354285
|
+
subject: exports_external.string().min(1).max(100).describe("New group name/subject")
|
|
354286
|
+
});
|
|
354287
|
+
updateGroupDescriptionSchema = exports_external.object({
|
|
354288
|
+
description: exports_external.string().max(2048).describe("New group description. Empty string clears the description.")
|
|
354289
|
+
});
|
|
354290
|
+
updateGroupSettingsSchema = exports_external.object({
|
|
354291
|
+
setting: groupSettingSchema.describe("Group setting to apply")
|
|
354292
|
+
});
|
|
354293
|
+
patchGroupSchema = exports_external.object({
|
|
354294
|
+
subject: exports_external.string().min(1).max(100).optional(),
|
|
354295
|
+
description: exports_external.string().max(2048).optional(),
|
|
354296
|
+
setting: groupSettingSchema.optional()
|
|
354297
|
+
}).refine((value) => value.subject !== undefined || value.description !== undefined || value.setting !== undefined, {
|
|
354298
|
+
message: "At least one of subject, description, or setting is required"
|
|
354299
|
+
});
|
|
354255
354300
|
instancesRoutes.post("/:id/groups", instanceAccess2, zValidator("json", exports_external.object({
|
|
354256
354301
|
subject: exports_external.string().min(1).max(100).describe("Group name/subject"),
|
|
354257
354302
|
participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to add")
|
|
@@ -354271,6 +354316,218 @@ var init_instances3 = __esm(() => {
|
|
|
354271
354316
|
const result = await plugin7.groupCreate(id, subject, participants);
|
|
354272
354317
|
return c.json({ data: result }, 201);
|
|
354273
354318
|
});
|
|
354319
|
+
instancesRoutes.post("/:id/groups/:groupJid/participants", instanceAccess2, zValidator("json", groupParticipantsSchema), async (c) => {
|
|
354320
|
+
const id = c.req.param("id");
|
|
354321
|
+
const groupJid = c.req.param("groupJid");
|
|
354322
|
+
const { participants } = c.req.valid("json");
|
|
354323
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354324
|
+
if (!resolved.ok)
|
|
354325
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354326
|
+
if (typeof resolved.plugin.updateGroupParticipants !== "function") {
|
|
354327
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
|
|
354328
|
+
}
|
|
354329
|
+
try {
|
|
354330
|
+
const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, "add");
|
|
354331
|
+
return c.json({ success: true, data: participantUpdateResponse(result) });
|
|
354332
|
+
} catch (error3) {
|
|
354333
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354334
|
+
return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
|
|
354335
|
+
}
|
|
354336
|
+
});
|
|
354337
|
+
instancesRoutes.post("/:id/groups/:groupJid/participants/:action", instanceAccess2, zValidator("json", groupParticipantsSchema), async (c) => {
|
|
354338
|
+
const id = c.req.param("id");
|
|
354339
|
+
const groupJid = c.req.param("groupJid");
|
|
354340
|
+
const parsedAction = groupParticipantActionSchema.safeParse(c.req.param("action"));
|
|
354341
|
+
const { participants } = c.req.valid("json");
|
|
354342
|
+
if (!parsedAction.success) {
|
|
354343
|
+
return c.json({
|
|
354344
|
+
error: {
|
|
354345
|
+
code: "VALIDATION_ERROR",
|
|
354346
|
+
message: "Invalid group participant action. Expected add, remove, promote, or demote."
|
|
354347
|
+
}
|
|
354348
|
+
}, 400);
|
|
354349
|
+
}
|
|
354350
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354351
|
+
if (!resolved.ok)
|
|
354352
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354353
|
+
if (typeof resolved.plugin.updateGroupParticipants !== "function") {
|
|
354354
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
|
|
354355
|
+
}
|
|
354356
|
+
try {
|
|
354357
|
+
const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, parsedAction.data);
|
|
354358
|
+
return c.json({ success: true, data: participantUpdateResponse(result) });
|
|
354359
|
+
} catch (error3) {
|
|
354360
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354361
|
+
return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
|
|
354362
|
+
}
|
|
354363
|
+
});
|
|
354364
|
+
instancesRoutes.patch("/:id/groups/:groupJid/participants", instanceAccess2, zValidator("json", groupParticipantsPatchSchema), async (c) => {
|
|
354365
|
+
const id = c.req.param("id");
|
|
354366
|
+
const groupJid = c.req.param("groupJid");
|
|
354367
|
+
const { action, participants } = c.req.valid("json");
|
|
354368
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354369
|
+
if (!resolved.ok)
|
|
354370
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354371
|
+
if (typeof resolved.plugin.updateGroupParticipants !== "function") {
|
|
354372
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group participant updates" } }, 400);
|
|
354373
|
+
}
|
|
354374
|
+
try {
|
|
354375
|
+
const result = await resolved.plugin.updateGroupParticipants(id, groupJid, participants, action);
|
|
354376
|
+
return c.json({ success: true, data: participantUpdateResponse(result) });
|
|
354377
|
+
} catch (error3) {
|
|
354378
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354379
|
+
return c.json({ error: { code: "GROUP_PARTICIPANTS_UPDATE_FAILED", message: message2 } }, 500);
|
|
354380
|
+
}
|
|
354381
|
+
});
|
|
354382
|
+
instancesRoutes.patch("/:id/groups/:groupJid", instanceAccess2, zValidator("json", patchGroupSchema), async (c) => {
|
|
354383
|
+
const id = c.req.param("id");
|
|
354384
|
+
const groupJid = c.req.param("groupJid");
|
|
354385
|
+
const body = c.req.valid("json");
|
|
354386
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354387
|
+
if (!resolved.ok)
|
|
354388
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354389
|
+
if (body.subject !== undefined && typeof resolved.plugin.updateGroupSubject !== "function") {
|
|
354390
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
|
|
354391
|
+
}
|
|
354392
|
+
if (body.description !== undefined && typeof resolved.plugin.updateGroupDescription !== "function") {
|
|
354393
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
|
|
354394
|
+
}
|
|
354395
|
+
if (body.setting !== undefined && typeof resolved.plugin.updateGroupSettings !== "function") {
|
|
354396
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group settings updates" } }, 400);
|
|
354397
|
+
}
|
|
354398
|
+
try {
|
|
354399
|
+
const updated = [];
|
|
354400
|
+
if (body.subject !== undefined) {
|
|
354401
|
+
await resolved.plugin.updateGroupSubject?.(id, groupJid, body.subject);
|
|
354402
|
+
updated.push("subject");
|
|
354403
|
+
}
|
|
354404
|
+
if (body.description !== undefined) {
|
|
354405
|
+
await resolved.plugin.updateGroupDescription?.(id, groupJid, body.description);
|
|
354406
|
+
updated.push("description");
|
|
354407
|
+
}
|
|
354408
|
+
if (body.setting !== undefined) {
|
|
354409
|
+
await resolved.plugin.updateGroupSettings?.(id, groupJid, body.setting);
|
|
354410
|
+
updated.push("settings");
|
|
354411
|
+
}
|
|
354412
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, updated, ...body } });
|
|
354413
|
+
} catch (error3) {
|
|
354414
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354415
|
+
return c.json({ error: { code: "GROUP_UPDATE_FAILED", message: message2 } }, 500);
|
|
354416
|
+
}
|
|
354417
|
+
});
|
|
354418
|
+
instancesRoutes.put("/:id/groups/:groupJid/subject", instanceAccess2, zValidator("json", updateGroupSubjectSchema), async (c) => {
|
|
354419
|
+
const id = c.req.param("id");
|
|
354420
|
+
const groupJid = c.req.param("groupJid");
|
|
354421
|
+
const { subject } = c.req.valid("json");
|
|
354422
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354423
|
+
if (!resolved.ok)
|
|
354424
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354425
|
+
if (typeof resolved.plugin.updateGroupSubject !== "function") {
|
|
354426
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
|
|
354427
|
+
}
|
|
354428
|
+
try {
|
|
354429
|
+
await resolved.plugin.updateGroupSubject(id, groupJid, subject);
|
|
354430
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, subject, action: "group_subject_updated" } });
|
|
354431
|
+
} catch (error3) {
|
|
354432
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354433
|
+
return c.json({ error: { code: "GROUP_RENAME_FAILED", message: message2 } }, 500);
|
|
354434
|
+
}
|
|
354435
|
+
});
|
|
354436
|
+
instancesRoutes.post("/:id/groups/:groupJid/subject", instanceAccess2, zValidator("json", updateGroupSubjectSchema), async (c) => {
|
|
354437
|
+
const id = c.req.param("id");
|
|
354438
|
+
const groupJid = c.req.param("groupJid");
|
|
354439
|
+
const { subject } = c.req.valid("json");
|
|
354440
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354441
|
+
if (!resolved.ok)
|
|
354442
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354443
|
+
if (typeof resolved.plugin.updateGroupSubject !== "function") {
|
|
354444
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group rename" } }, 400);
|
|
354445
|
+
}
|
|
354446
|
+
try {
|
|
354447
|
+
await resolved.plugin.updateGroupSubject(id, groupJid, subject);
|
|
354448
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, subject, action: "group_subject_updated" } });
|
|
354449
|
+
} catch (error3) {
|
|
354450
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354451
|
+
return c.json({ error: { code: "GROUP_RENAME_FAILED", message: message2 } }, 500);
|
|
354452
|
+
}
|
|
354453
|
+
});
|
|
354454
|
+
instancesRoutes.put("/:id/groups/:groupJid/description", instanceAccess2, zValidator("json", updateGroupDescriptionSchema), async (c) => {
|
|
354455
|
+
const id = c.req.param("id");
|
|
354456
|
+
const groupJid = c.req.param("groupJid");
|
|
354457
|
+
const { description } = c.req.valid("json");
|
|
354458
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354459
|
+
if (!resolved.ok)
|
|
354460
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354461
|
+
if (typeof resolved.plugin.updateGroupDescription !== "function") {
|
|
354462
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
|
|
354463
|
+
}
|
|
354464
|
+
try {
|
|
354465
|
+
await resolved.plugin.updateGroupDescription(id, groupJid, description);
|
|
354466
|
+
return c.json({
|
|
354467
|
+
success: true,
|
|
354468
|
+
data: { instanceId: id, groupJid, description, action: "group_description_updated" }
|
|
354469
|
+
});
|
|
354470
|
+
} catch (error3) {
|
|
354471
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354472
|
+
return c.json({ error: { code: "GROUP_DESCRIPTION_FAILED", message: message2 } }, 500);
|
|
354473
|
+
}
|
|
354474
|
+
});
|
|
354475
|
+
instancesRoutes.post("/:id/groups/:groupJid/description", instanceAccess2, zValidator("json", updateGroupDescriptionSchema), async (c) => {
|
|
354476
|
+
const id = c.req.param("id");
|
|
354477
|
+
const groupJid = c.req.param("groupJid");
|
|
354478
|
+
const { description } = c.req.valid("json");
|
|
354479
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354480
|
+
if (!resolved.ok)
|
|
354481
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354482
|
+
if (typeof resolved.plugin.updateGroupDescription !== "function") {
|
|
354483
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group description updates" } }, 400);
|
|
354484
|
+
}
|
|
354485
|
+
try {
|
|
354486
|
+
await resolved.plugin.updateGroupDescription(id, groupJid, description);
|
|
354487
|
+
return c.json({
|
|
354488
|
+
success: true,
|
|
354489
|
+
data: { instanceId: id, groupJid, description, action: "group_description_updated" }
|
|
354490
|
+
});
|
|
354491
|
+
} catch (error3) {
|
|
354492
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354493
|
+
return c.json({ error: { code: "GROUP_DESCRIPTION_FAILED", message: message2 } }, 500);
|
|
354494
|
+
}
|
|
354495
|
+
});
|
|
354496
|
+
instancesRoutes.post("/:id/groups/:groupJid/settings", instanceAccess2, zValidator("json", updateGroupSettingsSchema), async (c) => {
|
|
354497
|
+
const id = c.req.param("id");
|
|
354498
|
+
const groupJid = c.req.param("groupJid");
|
|
354499
|
+
const { setting } = c.req.valid("json");
|
|
354500
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354501
|
+
if (!resolved.ok)
|
|
354502
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354503
|
+
if (typeof resolved.plugin.updateGroupSettings !== "function") {
|
|
354504
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support group settings updates" } }, 400);
|
|
354505
|
+
}
|
|
354506
|
+
try {
|
|
354507
|
+
await resolved.plugin.updateGroupSettings(id, groupJid, setting);
|
|
354508
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, setting, action: "group_settings_updated" } });
|
|
354509
|
+
} catch (error3) {
|
|
354510
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354511
|
+
return c.json({ error: { code: "GROUP_SETTINGS_FAILED", message: message2 } }, 500);
|
|
354512
|
+
}
|
|
354513
|
+
});
|
|
354514
|
+
instancesRoutes.post("/:id/groups/:groupJid/leave", instanceAccess2, async (c) => {
|
|
354515
|
+
const id = c.req.param("id");
|
|
354516
|
+
const groupJid = c.req.param("groupJid");
|
|
354517
|
+
const resolved = await resolveInstancePlugin(c.get("services"), c.get("channelRegistry"), id);
|
|
354518
|
+
if (!resolved.ok)
|
|
354519
|
+
return c.json({ error: resolved.error }, resolved.status);
|
|
354520
|
+
if (typeof resolved.plugin.leaveGroup !== "function") {
|
|
354521
|
+
return c.json({ error: { code: "NOT_SUPPORTED", message: "Plugin does not support leaving groups" } }, 400);
|
|
354522
|
+
}
|
|
354523
|
+
try {
|
|
354524
|
+
await resolved.plugin.leaveGroup(id, groupJid);
|
|
354525
|
+
return c.json({ success: true, data: { instanceId: id, groupJid, left: true } });
|
|
354526
|
+
} catch (error3) {
|
|
354527
|
+
const message2 = error3 instanceof Error ? error3.message : "Unknown error";
|
|
354528
|
+
return c.json({ error: { code: "GROUP_LEAVE_FAILED", message: message2 } }, 500);
|
|
354529
|
+
}
|
|
354530
|
+
});
|
|
354274
354531
|
instancesRoutes.get("/:id/chats/:chatId/invite", instanceAccess2, async (c) => {
|
|
354275
354532
|
const id = c.req.param("id");
|
|
354276
354533
|
const chatId = c.req.param("chatId");
|
|
@@ -482714,6 +482971,12 @@ function toJid(identifier, lidCache) {
|
|
|
482714
482971
|
}
|
|
482715
482972
|
return phoneJid;
|
|
482716
482973
|
}
|
|
482974
|
+
function toGroupJid(groupId) {
|
|
482975
|
+
if (groupId.endsWith(JID_SUFFIX.GROUP)) {
|
|
482976
|
+
return groupId;
|
|
482977
|
+
}
|
|
482978
|
+
return `${groupId}${JID_SUFFIX.GROUP}`;
|
|
482979
|
+
}
|
|
482717
482980
|
function fromJid(jid) {
|
|
482718
482981
|
const isGroup = jid.endsWith(JID_SUFFIX.GROUP);
|
|
482719
482982
|
const isBroadcast = jid.endsWith(JID_SUFFIX.BROADCAST);
|
|
@@ -486329,6 +486592,85 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
486329
486592
|
throw waError;
|
|
486330
486593
|
}
|
|
486331
486594
|
}
|
|
486595
|
+
async updateGroupParticipants(instanceId, groupJid, participants, action) {
|
|
486596
|
+
await this.humanDelay(instanceId);
|
|
486597
|
+
const sock = this.getSocket(instanceId);
|
|
486598
|
+
const jid = toGroupJid(groupJid);
|
|
486599
|
+
const participantJids = participants.map((participant) => toJid(participant));
|
|
486600
|
+
try {
|
|
486601
|
+
const result = await sock.groupParticipantsUpdate(jid, participantJids, action);
|
|
486602
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486603
|
+
this.logger.info("Group participants updated", {
|
|
486604
|
+
instanceId,
|
|
486605
|
+
groupJid: jid,
|
|
486606
|
+
action,
|
|
486607
|
+
participantCount: participantJids.length
|
|
486608
|
+
});
|
|
486609
|
+
return {
|
|
486610
|
+
groupJid: jid,
|
|
486611
|
+
action,
|
|
486612
|
+
participants: result.map((participant) => ({
|
|
486613
|
+
jid: participant.jid,
|
|
486614
|
+
status: participant.status
|
|
486615
|
+
}))
|
|
486616
|
+
};
|
|
486617
|
+
} catch (error) {
|
|
486618
|
+
const waError = mapBaileysError(error);
|
|
486619
|
+
throw waError;
|
|
486620
|
+
}
|
|
486621
|
+
}
|
|
486622
|
+
async updateGroupSubject(instanceId, groupJid, subject) {
|
|
486623
|
+
await this.humanDelay(instanceId);
|
|
486624
|
+
const sock = this.getSocket(instanceId);
|
|
486625
|
+
const jid = toGroupJid(groupJid);
|
|
486626
|
+
try {
|
|
486627
|
+
await sock.groupUpdateSubject(jid, subject);
|
|
486628
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486629
|
+
this.logger.info("Group subject updated", { instanceId, groupJid: jid });
|
|
486630
|
+
} catch (error) {
|
|
486631
|
+
const waError = mapBaileysError(error);
|
|
486632
|
+
throw waError;
|
|
486633
|
+
}
|
|
486634
|
+
}
|
|
486635
|
+
async updateGroupDescription(instanceId, groupJid, description) {
|
|
486636
|
+
await this.humanDelay(instanceId);
|
|
486637
|
+
const sock = this.getSocket(instanceId);
|
|
486638
|
+
const jid = toGroupJid(groupJid);
|
|
486639
|
+
try {
|
|
486640
|
+
await sock.groupUpdateDescription(jid, description);
|
|
486641
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486642
|
+
this.logger.info("Group description updated", { instanceId, groupJid: jid, cleared: !description });
|
|
486643
|
+
} catch (error) {
|
|
486644
|
+
const waError = mapBaileysError(error);
|
|
486645
|
+
throw waError;
|
|
486646
|
+
}
|
|
486647
|
+
}
|
|
486648
|
+
async updateGroupSettings(instanceId, groupJid, setting) {
|
|
486649
|
+
await this.humanDelay(instanceId);
|
|
486650
|
+
const sock = this.getSocket(instanceId);
|
|
486651
|
+
const jid = toGroupJid(groupJid);
|
|
486652
|
+
try {
|
|
486653
|
+
await sock.groupSettingUpdate(jid, setting);
|
|
486654
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486655
|
+
this.logger.info("Group settings updated", { instanceId, groupJid: jid, setting });
|
|
486656
|
+
} catch (error) {
|
|
486657
|
+
const waError = mapBaileysError(error);
|
|
486658
|
+
throw waError;
|
|
486659
|
+
}
|
|
486660
|
+
}
|
|
486661
|
+
async leaveGroup(instanceId, groupJid) {
|
|
486662
|
+
await this.humanDelay(instanceId);
|
|
486663
|
+
const sock = this.getSocket(instanceId);
|
|
486664
|
+
const jid = toGroupJid(groupJid);
|
|
486665
|
+
try {
|
|
486666
|
+
await sock.groupLeave(jid);
|
|
486667
|
+
this.invalidateGroupMetadataCache(instanceId, jid);
|
|
486668
|
+
this.logger.info("Left group", { instanceId, groupJid: jid });
|
|
486669
|
+
} catch (error) {
|
|
486670
|
+
const waError = mapBaileysError(error);
|
|
486671
|
+
throw waError;
|
|
486672
|
+
}
|
|
486673
|
+
}
|
|
486332
486674
|
async handleQrCode(instanceId, qrCode, expiresAt) {
|
|
486333
486675
|
await this.emitQrCode(instanceId, qrCode, expiresAt);
|
|
486334
486676
|
const config2 = this.instances.get(instanceId)?.config;
|