@automagik/omni 2.260609.3 → 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 +390 -7
- 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
|
".": {
|
|
@@ -335748,6 +335748,28 @@ class MessageService {
|
|
|
335748
335748
|
const [result] = await this.db.select().from(messages2).where(and2(eq(messages2.chatId, chatId), eq(messages2.isFromMe, true), or2(...aliasConditions))).orderBy(desc(messages2.platformTimestamp)).limit(1);
|
|
335749
335749
|
return result ?? null;
|
|
335750
335750
|
}
|
|
335751
|
+
async findRecentOutboundBefore(chatId, before, inboundText) {
|
|
335752
|
+
const upperBound = new Date(before.getTime() + 2000);
|
|
335753
|
+
const rows = await this.db.select().from(messages2).where(and2(eq(messages2.chatId, chatId), eq(messages2.isFromMe, true), lte(messages2.platformTimestamp, upperBound), sql`${messages2.deletedAt} IS NULL`)).orderBy(desc(messages2.platformTimestamp)).limit(8);
|
|
335754
|
+
if (rows.length === 0)
|
|
335755
|
+
return null;
|
|
335756
|
+
const hint = (inboundText ?? "").toLocaleLowerCase("pt-BR");
|
|
335757
|
+
const wantsPlanLikeTarget = /\b(esse|essa|este|esta|op[c\u00E7][a\u00E3]o|plano|quero|gostei)\b/i.test(hint);
|
|
335758
|
+
if (!wantsPlanLikeTarget)
|
|
335759
|
+
return rows[0] ?? null;
|
|
335760
|
+
const score = (message2) => {
|
|
335761
|
+
const text3 = (message2.textContent ?? "").toLocaleLowerCase("pt-BR");
|
|
335762
|
+
let value = 0;
|
|
335763
|
+
if (/op[c\u00E7][a\u00E3]o|plano/.test(text3))
|
|
335764
|
+
value += 4;
|
|
335765
|
+
if (/r\$|mensal|coparticipa|enfermaria|apartamento|ambulatorial|notrelife|hapvida/.test(text3))
|
|
335766
|
+
value += 3;
|
|
335767
|
+
if (/\?\s*$/.test(text3) && !/r\$/.test(text3))
|
|
335768
|
+
value -= 2;
|
|
335769
|
+
return value;
|
|
335770
|
+
};
|
|
335771
|
+
return rows.map((message2) => ({ message: message2, score: score(message2) })).sort((a, b3) => b3.score - a.score || b3.message.platformTimestamp.getTime() - a.message.platformTimestamp.getTime())[0]?.message ?? null;
|
|
335772
|
+
}
|
|
335751
335773
|
async getByExternalIds(chatId, externalIds) {
|
|
335752
335774
|
if (externalIds.length === 0)
|
|
335753
335775
|
return [];
|
|
@@ -338454,7 +338476,7 @@ function getMessageContentText(msg) {
|
|
|
338454
338476
|
function uniqueNonEmpty(values2) {
|
|
338455
338477
|
return [...new Set(values2.filter((value) => typeof value === "string" && value.length > 0))];
|
|
338456
338478
|
}
|
|
338457
|
-
async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases) {
|
|
338479
|
+
async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases, options = {}) {
|
|
338458
338480
|
const quoted = await messages4.getByExternalId(chatDbId, replyToId);
|
|
338459
338481
|
if (quoted)
|
|
338460
338482
|
return quoted;
|
|
@@ -338472,14 +338494,19 @@ async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases) {
|
|
|
338472
338494
|
if (byExternalId)
|
|
338473
338495
|
return byExternalId;
|
|
338474
338496
|
}
|
|
338497
|
+
if (options.inboundAt && aliasLookup.findRecentOutboundBefore) {
|
|
338498
|
+
const fallback = await aliasLookup.findRecentOutboundBefore(chatDbId, options.inboundAt, options.inboundText);
|
|
338499
|
+
if (fallback)
|
|
338500
|
+
return fallback;
|
|
338501
|
+
}
|
|
338475
338502
|
return null;
|
|
338476
338503
|
}
|
|
338477
|
-
async function resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases = []) {
|
|
338504
|
+
async function resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases = [], options = {}) {
|
|
338478
338505
|
try {
|
|
338479
338506
|
const chat2 = await services.chats.findByExternalIdSmart(instanceId, chatId);
|
|
338480
338507
|
if (!chat2)
|
|
338481
338508
|
return null;
|
|
338482
|
-
const quoted = await lookupQuotedMessage(services.messages, chat2.id, replyToId, providerAliases);
|
|
338509
|
+
const quoted = await lookupQuotedMessage(services.messages, chat2.id, replyToId, providerAliases, options);
|
|
338483
338510
|
if (!quoted)
|
|
338484
338511
|
return null;
|
|
338485
338512
|
const sender = quoted.senderDisplayName ?? quoted.senderPlatformUserId ?? (quoted.isFromMe ? "You" : "unknown");
|
|
@@ -338560,13 +338587,27 @@ function extractQuotedProviderAliases(rawPayload) {
|
|
|
338560
338587
|
topContext?.id
|
|
338561
338588
|
]);
|
|
338562
338589
|
}
|
|
338590
|
+
function extractInboundPlatformDate(rawPayload) {
|
|
338591
|
+
if (!rawPayload)
|
|
338592
|
+
return;
|
|
338593
|
+
const messageObj = isRecord(rawPayload.messageobj) ? rawPayload.messageobj : undefined;
|
|
338594
|
+
const timestamp3 = messageObj?.timestamp;
|
|
338595
|
+
if (typeof timestamp3 === "number" && Number.isFinite(timestamp3) && timestamp3 > 0) {
|
|
338596
|
+
return new Date(timestamp3 * 1000);
|
|
338597
|
+
}
|
|
338598
|
+
return;
|
|
338599
|
+
}
|
|
338563
338600
|
async function prependQuotedContext(services, instanceId, chatId, messages4, entries, messageKeyByIndex) {
|
|
338564
338601
|
for (const [index2, m2] of messages4.entries()) {
|
|
338565
338602
|
const replyToId = m2.payload.replyToId;
|
|
338566
338603
|
if (!replyToId)
|
|
338567
338604
|
continue;
|
|
338568
|
-
const
|
|
338569
|
-
const
|
|
338605
|
+
const rawPayload = m2.payload.rawPayload;
|
|
338606
|
+
const providerAliases = extractQuotedProviderAliases(rawPayload);
|
|
338607
|
+
const quotedText = await resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases, {
|
|
338608
|
+
inboundAt: extractInboundPlatformDate(rawPayload),
|
|
338609
|
+
inboundText: m2.payload.content?.text
|
|
338610
|
+
});
|
|
338570
338611
|
if (!quotedText)
|
|
338571
338612
|
continue;
|
|
338572
338613
|
const messageKey = messageKeyByIndex.get(index2);
|
|
@@ -353168,6 +353209,27 @@ async function enrichContactNames(contacts, services, instanceId) {
|
|
|
353168
353209
|
contact.name = dbName;
|
|
353169
353210
|
}
|
|
353170
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
|
+
}
|
|
353171
353233
|
function parseDuration(duration) {
|
|
353172
353234
|
const match2 = duration.match(/^(\d+)(s|m|h|d)$/);
|
|
353173
353235
|
if (!match2?.[1] || !match2[2])
|
|
@@ -353207,7 +353269,7 @@ function getCacheKey(instanceId, guildId) {
|
|
|
353207
353269
|
function invalidateGuildCache(instanceId, guildId) {
|
|
353208
353270
|
guildConfigCache.delete(getCacheKey(instanceId, guildId));
|
|
353209
353271
|
}
|
|
353210
|
-
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;
|
|
353211
353273
|
var init_instances3 = __esm(() => {
|
|
353212
353274
|
init_dist6();
|
|
353213
353275
|
init_src();
|
|
@@ -354309,6 +354371,30 @@ var init_instances3 = __esm(() => {
|
|
|
354309
354371
|
return c.json({ error: { code: "REMOVE_FAILED", message: message2 } }, 500);
|
|
354310
354372
|
}
|
|
354311
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
|
+
});
|
|
354312
354398
|
instancesRoutes.post("/:id/groups", instanceAccess2, zValidator("json", exports_external.object({
|
|
354313
354399
|
subject: exports_external.string().min(1).max(100).describe("Group name/subject"),
|
|
354314
354400
|
participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to add")
|
|
@@ -354328,6 +354414,218 @@ var init_instances3 = __esm(() => {
|
|
|
354328
354414
|
const result = await plugin7.groupCreate(id, subject, participants);
|
|
354329
354415
|
return c.json({ data: result }, 201);
|
|
354330
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
|
+
});
|
|
354331
354629
|
instancesRoutes.get("/:id/chats/:chatId/invite", instanceAccess2, async (c) => {
|
|
354332
354630
|
const id = c.req.param("id");
|
|
354333
354631
|
const chatId = c.req.param("chatId");
|
|
@@ -482804,6 +483102,12 @@ function toJid(identifier, lidCache) {
|
|
|
482804
483102
|
}
|
|
482805
483103
|
return phoneJid;
|
|
482806
483104
|
}
|
|
483105
|
+
function toGroupJid(groupId) {
|
|
483106
|
+
if (groupId.endsWith(JID_SUFFIX.GROUP)) {
|
|
483107
|
+
return groupId;
|
|
483108
|
+
}
|
|
483109
|
+
return `${groupId}${JID_SUFFIX.GROUP}`;
|
|
483110
|
+
}
|
|
482807
483111
|
function fromJid(jid) {
|
|
482808
483112
|
const isGroup = jid.endsWith(JID_SUFFIX.GROUP);
|
|
482809
483113
|
const isBroadcast = jid.endsWith(JID_SUFFIX.BROADCAST);
|
|
@@ -486419,6 +486723,85 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
486419
486723
|
throw waError;
|
|
486420
486724
|
}
|
|
486421
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
|
+
}
|
|
486422
486805
|
async handleQrCode(instanceId, qrCode, expiresAt) {
|
|
486423
486806
|
await this.emitQrCode(instanceId, qrCode, expiresAt);
|
|
486424
486807
|
const config2 = this.instances.get(instanceId)?.config;
|