@automagik/omni 2.260609.1 → 2.260609.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/dist/index.js +1 -1
- package/dist/server/index.js +96 -348
- 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.3",
|
|
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.3",
|
|
225249
225249
|
type: "module",
|
|
225250
225250
|
exports: {
|
|
225251
225251
|
".": {
|
|
@@ -335731,6 +335731,23 @@ class MessageService {
|
|
|
335731
335731
|
const [result] = await this.db.select().from(messages2).where(and2(eq(messages2.chatId, chatId), eq(messages2.externalId, externalId))).limit(1);
|
|
335732
335732
|
return result ?? null;
|
|
335733
335733
|
}
|
|
335734
|
+
async findByProviderAlias(chatId, aliases) {
|
|
335735
|
+
const candidates = [
|
|
335736
|
+
...new Set(aliases.filter((alias3) => typeof alias3 === "string" && alias3.length > 0).map((alias3) => alias3.slice(0, 255)))
|
|
335737
|
+
].slice(0, 8);
|
|
335738
|
+
if (candidates.length === 0)
|
|
335739
|
+
return null;
|
|
335740
|
+
const aliasConditions = candidates.flatMap((alias3) => [
|
|
335741
|
+
eq(messages2.externalId, alias3),
|
|
335742
|
+
sql`${messages2.rawPayload}->'gupshupResponse'->>'messageId' = ${alias3}`,
|
|
335743
|
+
sql`${messages2.rawPayload}->'gupshupResponse'->>'gsId' = ${alias3}`,
|
|
335744
|
+
sql`${messages2.rawPayload}->'gupshupResponse'->>'id' = ${alias3}`,
|
|
335745
|
+
sql`${messages2.rawPayload}->'gupshupResponse'->'messageIds' @> ${JSON.stringify([alias3])}::jsonb`,
|
|
335746
|
+
sql`${messages2.rawPayload}->'gupshupProviderAliases' @> ${JSON.stringify([alias3])}::jsonb`
|
|
335747
|
+
]);
|
|
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
|
+
return result ?? null;
|
|
335750
|
+
}
|
|
335734
335751
|
async getByExternalIds(chatId, externalIds) {
|
|
335735
335752
|
if (externalIds.length === 0)
|
|
335736
335753
|
return [];
|
|
@@ -338434,12 +338451,35 @@ function getMessageContentText(msg) {
|
|
|
338434
338451
|
return msg.textContent;
|
|
338435
338452
|
}
|
|
338436
338453
|
}
|
|
338437
|
-
|
|
338454
|
+
function uniqueNonEmpty(values2) {
|
|
338455
|
+
return [...new Set(values2.filter((value) => typeof value === "string" && value.length > 0))];
|
|
338456
|
+
}
|
|
338457
|
+
async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases) {
|
|
338458
|
+
const quoted = await messages4.getByExternalId(chatDbId, replyToId);
|
|
338459
|
+
if (quoted)
|
|
338460
|
+
return quoted;
|
|
338461
|
+
const candidates = uniqueNonEmpty([replyToId, ...aliases]);
|
|
338462
|
+
const aliasLookup = messages4;
|
|
338463
|
+
if (aliasLookup.findByProviderAlias && candidates.length > 0) {
|
|
338464
|
+
const byAlias = await aliasLookup.findByProviderAlias(chatDbId, candidates);
|
|
338465
|
+
if (byAlias)
|
|
338466
|
+
return byAlias;
|
|
338467
|
+
}
|
|
338468
|
+
for (const candidate of candidates) {
|
|
338469
|
+
if (candidate === replyToId)
|
|
338470
|
+
continue;
|
|
338471
|
+
const byExternalId = await messages4.getByExternalId(chatDbId, candidate);
|
|
338472
|
+
if (byExternalId)
|
|
338473
|
+
return byExternalId;
|
|
338474
|
+
}
|
|
338475
|
+
return null;
|
|
338476
|
+
}
|
|
338477
|
+
async function resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases = []) {
|
|
338438
338478
|
try {
|
|
338439
338479
|
const chat2 = await services.chats.findByExternalIdSmart(instanceId, chatId);
|
|
338440
338480
|
if (!chat2)
|
|
338441
338481
|
return null;
|
|
338442
|
-
const quoted = await services.messages
|
|
338482
|
+
const quoted = await lookupQuotedMessage(services.messages, chat2.id, replyToId, providerAliases);
|
|
338443
338483
|
if (!quoted)
|
|
338444
338484
|
return null;
|
|
338445
338485
|
const sender = quoted.senderDisplayName ?? quoted.senderPlatformUserId ?? (quoted.isFromMe ? "You" : "unknown");
|
|
@@ -338504,12 +338544,29 @@ async function collectProcessedMedia(services, instance4, messages4) {
|
|
|
338504
338544
|
}
|
|
338505
338545
|
return results;
|
|
338506
338546
|
}
|
|
338547
|
+
function extractQuotedProviderAliases(rawPayload) {
|
|
338548
|
+
if (!rawPayload)
|
|
338549
|
+
return [];
|
|
338550
|
+
const messageObj = isRecord(rawPayload.messageobj) ? rawPayload.messageobj : undefined;
|
|
338551
|
+
const replyContext = isRecord(messageObj?.replyContext) ? messageObj.replyContext : undefined;
|
|
338552
|
+
const rawMessage = isRecord(messageObj?.raw) ? messageObj.raw : undefined;
|
|
338553
|
+
const rawContext = isRecord(rawMessage?.context) ? rawMessage.context : undefined;
|
|
338554
|
+
const topContext = isRecord(rawPayload.context) ? rawPayload.context : undefined;
|
|
338555
|
+
return uniqueNonEmpty([
|
|
338556
|
+
replyContext?.internalId,
|
|
338557
|
+
rawContext?.gsId,
|
|
338558
|
+
rawContext?.id,
|
|
338559
|
+
topContext?.gsId,
|
|
338560
|
+
topContext?.id
|
|
338561
|
+
]);
|
|
338562
|
+
}
|
|
338507
338563
|
async function prependQuotedContext(services, instanceId, chatId, messages4, entries, messageKeyByIndex) {
|
|
338508
338564
|
for (const [index2, m2] of messages4.entries()) {
|
|
338509
338565
|
const replyToId = m2.payload.replyToId;
|
|
338510
338566
|
if (!replyToId)
|
|
338511
338567
|
continue;
|
|
338512
|
-
const
|
|
338568
|
+
const providerAliases = extractQuotedProviderAliases(m2.payload.rawPayload);
|
|
338569
|
+
const quotedText = await resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases);
|
|
338513
338570
|
if (!quotedText)
|
|
338514
338571
|
continue;
|
|
338515
338572
|
const messageKey = messageKeyByIndex.get(index2);
|
|
@@ -353111,27 +353168,6 @@ async function enrichContactNames(contacts, services, instanceId) {
|
|
|
353111
353168
|
contact.name = dbName;
|
|
353112
353169
|
}
|
|
353113
353170
|
}
|
|
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
|
-
}
|
|
353135
353171
|
function parseDuration(duration) {
|
|
353136
353172
|
const match2 = duration.match(/^(\d+)(s|m|h|d)$/);
|
|
353137
353173
|
if (!match2?.[1] || !match2[2])
|
|
@@ -353171,7 +353207,7 @@ function getCacheKey(instanceId, guildId) {
|
|
|
353171
353207
|
function invalidateGuildCache(instanceId, guildId) {
|
|
353172
353208
|
guildConfigCache.delete(getCacheKey(instanceId, guildId));
|
|
353173
353209
|
}
|
|
353174
|
-
var log108, instancesRoutes, instanceAccess2, listQuerySchema12, agentReplyFilterSchema, createInstanceSchema, updateInstanceSchema, DEFAULT_AGENT_REPLY_FILTER, SENSITIVE_INSTANCE_FIELDS, pairingCodeSchema, connectInstanceSchema, syncRequestSchema, listContactsQuerySchema, listGroupsQuerySchema, checkNumberSchema, updateBioSchema, blockContactSchema,
|
|
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;
|
|
353175
353211
|
var init_instances3 = __esm(() => {
|
|
353176
353212
|
init_dist6();
|
|
353177
353213
|
init_src();
|
|
@@ -354273,30 +354309,6 @@ var init_instances3 = __esm(() => {
|
|
|
354273
354309
|
return c.json({ error: { code: "REMOVE_FAILED", message: message2 } }, 500);
|
|
354274
354310
|
}
|
|
354275
354311
|
});
|
|
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
|
-
});
|
|
354300
354312
|
instancesRoutes.post("/:id/groups", instanceAccess2, zValidator("json", exports_external.object({
|
|
354301
354313
|
subject: exports_external.string().min(1).max(100).describe("Group name/subject"),
|
|
354302
354314
|
participants: exports_external.array(exports_external.string().min(1)).min(1).describe("Phone numbers or JIDs to add")
|
|
@@ -354316,218 +354328,6 @@ var init_instances3 = __esm(() => {
|
|
|
354316
354328
|
const result = await plugin7.groupCreate(id, subject, participants);
|
|
354317
354329
|
return c.json({ data: result }, 201);
|
|
354318
354330
|
});
|
|
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
|
-
});
|
|
354531
354331
|
instancesRoutes.get("/:id/chats/:chatId/invite", instanceAccess2, async (c) => {
|
|
354532
354332
|
const id = c.req.param("id");
|
|
354533
354333
|
const chatId = c.req.param("chatId");
|
|
@@ -366770,6 +366570,34 @@ async function dispatchContent(client, dest, message2) {
|
|
|
366770
366570
|
}
|
|
366771
366571
|
return sendText(client, dest, content.text ?? "[Unsupported content]");
|
|
366772
366572
|
}
|
|
366573
|
+
function extractResponseString(response, key) {
|
|
366574
|
+
const value = response[key];
|
|
366575
|
+
if (typeof value !== "string" || value.length === 0)
|
|
366576
|
+
return;
|
|
366577
|
+
return value.slice(0, 255);
|
|
366578
|
+
}
|
|
366579
|
+
function extractGupshupMessageIds(response) {
|
|
366580
|
+
if (!Array.isArray(response.messageIds))
|
|
366581
|
+
return [];
|
|
366582
|
+
return response.messageIds.filter((value) => typeof value === "string" && value.length > 0).map((value) => value.slice(0, 255));
|
|
366583
|
+
}
|
|
366584
|
+
function extractGupshupProviderAliases(response) {
|
|
366585
|
+
return [
|
|
366586
|
+
extractResponseString(response, "messageId"),
|
|
366587
|
+
extractResponseString(response, "gsId"),
|
|
366588
|
+
extractResponseString(response, "id"),
|
|
366589
|
+
...extractGupshupMessageIds(response)
|
|
366590
|
+
].filter((value, index, values) => typeof value === "string" && values.indexOf(value) === index);
|
|
366591
|
+
}
|
|
366592
|
+
function buildGupshupResponseMetadata(response) {
|
|
366593
|
+
return {
|
|
366594
|
+
status: extractResponseString(response, "status"),
|
|
366595
|
+
messageId: extractResponseString(response, "messageId"),
|
|
366596
|
+
gsId: extractResponseString(response, "gsId"),
|
|
366597
|
+
id: extractResponseString(response, "id"),
|
|
366598
|
+
messageIds: extractGupshupMessageIds(response)
|
|
366599
|
+
};
|
|
366600
|
+
}
|
|
366773
366601
|
|
|
366774
366602
|
class GupshupPlugin extends BaseChannelPlugin {
|
|
366775
366603
|
id = "gupshup";
|
|
@@ -366850,7 +366678,8 @@ class GupshupPlugin extends BaseChannelPlugin {
|
|
|
366850
366678
|
this.captureT10(correlationId);
|
|
366851
366679
|
try {
|
|
366852
366680
|
const response = await dispatchContent(client, dest, message2);
|
|
366853
|
-
const
|
|
366681
|
+
const providerAliases = extractGupshupProviderAliases(response);
|
|
366682
|
+
const messageId = extractResponseString(response, "messageId") ?? crypto.randomUUID();
|
|
366854
366683
|
if (correlationId)
|
|
366855
366684
|
this.captureT11(correlationId);
|
|
366856
366685
|
await this.emitMessageSent({
|
|
@@ -366864,6 +366693,10 @@ class GupshupPlugin extends BaseChannelPlugin {
|
|
|
366864
366693
|
mediaUrl: content.mediaUrl
|
|
366865
366694
|
},
|
|
366866
366695
|
replyToId: message2.replyTo,
|
|
366696
|
+
rawPayload: {
|
|
366697
|
+
gupshupResponse: buildGupshupResponseMetadata(response),
|
|
366698
|
+
gupshupProviderAliases: providerAliases
|
|
366699
|
+
},
|
|
366867
366700
|
senderAgentId: message2.metadata?.senderAgentId
|
|
366868
366701
|
});
|
|
366869
366702
|
return { success: true, messageId, timestamp: Date.now() };
|
|
@@ -482971,12 +482804,6 @@ function toJid(identifier, lidCache) {
|
|
|
482971
482804
|
}
|
|
482972
482805
|
return phoneJid;
|
|
482973
482806
|
}
|
|
482974
|
-
function toGroupJid(groupId) {
|
|
482975
|
-
if (groupId.endsWith(JID_SUFFIX.GROUP)) {
|
|
482976
|
-
return groupId;
|
|
482977
|
-
}
|
|
482978
|
-
return `${groupId}${JID_SUFFIX.GROUP}`;
|
|
482979
|
-
}
|
|
482980
482807
|
function fromJid(jid) {
|
|
482981
482808
|
const isGroup = jid.endsWith(JID_SUFFIX.GROUP);
|
|
482982
482809
|
const isBroadcast = jid.endsWith(JID_SUFFIX.BROADCAST);
|
|
@@ -486592,85 +486419,6 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
486592
486419
|
throw waError;
|
|
486593
486420
|
}
|
|
486594
486421
|
}
|
|
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
|
-
}
|
|
486674
486422
|
async handleQrCode(instanceId, qrCode, expiresAt) {
|
|
486675
486423
|
await this.emitQrCode(instanceId, qrCode, expiresAt);
|
|
486676
486424
|
const config2 = this.instances.get(instanceId)?.config;
|