@automagik/omni 2.260910.16 → 2.260910.17
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/commands/events.d.ts +1 -1
- package/dist/commands/events.d.ts.map +1 -1
- package/dist/commands/sources.d.ts +70 -0
- package/dist/commands/sources.d.ts.map +1 -0
- package/dist/commands/webhooks.d.ts +1 -1
- package/dist/commands/webhooks.d.ts.map +1 -1
- package/dist/index.js +2429 -2032
- package/dist/server/index.js +77 -91
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -44884,30 +44884,42 @@ class BaseChannelPlugin {
|
|
|
44884
44884
|
timings,
|
|
44885
44885
|
ingestMode: isHistorySync ? "history-sync" : "realtime"
|
|
44886
44886
|
};
|
|
44887
|
-
|
|
44888
|
-
|
|
44889
|
-
|
|
44890
|
-
|
|
44887
|
+
return this.publishClaimed("message.received", payload, instanceId, {
|
|
44888
|
+
idempotencyKey: `${this.id}:${instanceId}:${payload.externalId}:${payload.content.type}`,
|
|
44889
|
+
externalId: payload.externalId,
|
|
44890
|
+
options
|
|
44891
|
+
});
|
|
44892
|
+
}
|
|
44893
|
+
async publishClaimed(type, payload, instanceId, params) {
|
|
44894
|
+
const { idempotencyKey, externalId, options = {} } = params;
|
|
44895
|
+
if (!this.ingressClaim) {
|
|
44896
|
+
return this.publishEventInternal(type, payload, instanceId, options);
|
|
44897
|
+
}
|
|
44898
|
+
const eventId = await this.ingressClaim.claim({
|
|
44899
|
+
idempotencyKey,
|
|
44900
|
+
instanceId,
|
|
44901
|
+
channelType: this.id,
|
|
44902
|
+
externalId,
|
|
44903
|
+
eventType: type
|
|
44904
|
+
});
|
|
44905
|
+
if (eventId === null) {
|
|
44906
|
+
this.logger.info(`Skipping duplicate inbound ${type} (idempotency key already journaled)`, {
|
|
44891
44907
|
instanceId,
|
|
44892
|
-
|
|
44893
|
-
externalId: payload.externalId
|
|
44908
|
+
idempotencyKey
|
|
44894
44909
|
});
|
|
44895
|
-
|
|
44896
|
-
this.logger.info("Skipping duplicate inbound message (idempotency key already journaled)", {
|
|
44897
|
-
instanceId,
|
|
44898
|
-
idempotencyKey
|
|
44899
|
-
});
|
|
44900
|
-
return generateCorrelationId("evt");
|
|
44901
|
-
}
|
|
44902
|
-
options.publishEventId = eventId;
|
|
44903
|
-
try {
|
|
44904
|
-
return await this.publishEventInternal("message.received", payload, instanceId, options);
|
|
44905
|
-
} catch (error) {
|
|
44906
|
-
await this.ingressClaim.release(eventId).catch(() => {});
|
|
44907
|
-
throw error;
|
|
44908
|
-
}
|
|
44910
|
+
return generateCorrelationId("evt");
|
|
44909
44911
|
}
|
|
44910
|
-
|
|
44912
|
+
try {
|
|
44913
|
+
return await this.publishEventInternal(type, payload, instanceId, { ...options, publishEventId: eventId });
|
|
44914
|
+
} catch (error) {
|
|
44915
|
+
await this.ingressClaim.release(eventId).catch(() => {});
|
|
44916
|
+
throw error;
|
|
44917
|
+
}
|
|
44918
|
+
}
|
|
44919
|
+
reactionClaimParams(kind, instanceId, payload) {
|
|
44920
|
+
const raw = payload.rawPayload?.externalId;
|
|
44921
|
+
const externalId = typeof raw === "string" && raw.length > 0 ? raw : `${payload.messageId}:${payload.from}`;
|
|
44922
|
+
return { idempotencyKey: `${this.id}:${instanceId}:${externalId}:${kind}:${payload.emoji}`, externalId };
|
|
44911
44923
|
}
|
|
44912
44924
|
async emitMessageSent(params) {
|
|
44913
44925
|
const { instanceId, ...payload } = params;
|
|
@@ -44928,11 +44940,11 @@ class BaseChannelPlugin {
|
|
|
44928
44940
|
}
|
|
44929
44941
|
async emitReactionReceived(params) {
|
|
44930
44942
|
const { instanceId, ...payload } = params;
|
|
44931
|
-
await this.
|
|
44943
|
+
await this.publishClaimed("reaction.received", payload, instanceId, this.reactionClaimParams("reaction.received", instanceId, payload));
|
|
44932
44944
|
}
|
|
44933
44945
|
async emitReactionRemoved(params) {
|
|
44934
44946
|
const { instanceId, ...payload } = params;
|
|
44935
|
-
await this.
|
|
44947
|
+
await this.publishClaimed("reaction.removed", payload, instanceId, this.reactionClaimParams("reaction.removed", instanceId, payload));
|
|
44936
44948
|
}
|
|
44937
44949
|
async emitMessagePinned(params) {
|
|
44938
44950
|
const { instanceId, ...payload } = params;
|
|
@@ -251645,7 +251657,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
251645
251657
|
var require_package7 = __commonJS((exports, module) => {
|
|
251646
251658
|
module.exports = {
|
|
251647
251659
|
name: "@omni/api",
|
|
251648
|
-
version: "2.260910.
|
|
251660
|
+
version: "2.260910.17",
|
|
251649
251661
|
private: true,
|
|
251650
251662
|
type: "module",
|
|
251651
251663
|
exports: {
|
|
@@ -363161,7 +363173,7 @@ function createPluginDatabase(db2) {
|
|
|
363161
363173
|
}
|
|
363162
363174
|
function createIngressClaim(db2) {
|
|
363163
363175
|
return {
|
|
363164
|
-
async claim({ idempotencyKey, instanceId, channelType, externalId }) {
|
|
363176
|
+
async claim({ idempotencyKey, instanceId, channelType, externalId, eventType = "message.received" }) {
|
|
363165
363177
|
const id = randomUUID2();
|
|
363166
363178
|
try {
|
|
363167
363179
|
const claimed = await db2.insert(omniEvents).values({
|
|
@@ -363169,7 +363181,7 @@ function createIngressClaim(db2) {
|
|
|
363169
363181
|
externalId,
|
|
363170
363182
|
channel: channelTypes.includes(channelType) ? channelType : "discord",
|
|
363171
363183
|
instanceId,
|
|
363172
|
-
eventType
|
|
363184
|
+
eventType,
|
|
363173
363185
|
direction: "inbound",
|
|
363174
363186
|
status: "received",
|
|
363175
363187
|
idempotencyKey,
|
|
@@ -398350,8 +398362,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
398350
398362
|
const sdb = scopedHandle(db2);
|
|
398351
398363
|
const chatLink = await resolveChatLink(sdb, metadata.instanceId, payload.chatId);
|
|
398352
398364
|
const personId = await resolvePersonId2(sdb, metadata.personId);
|
|
398353
|
-
const
|
|
398354
|
-
...eventIdInsert(event.id),
|
|
398365
|
+
const columns2 = {
|
|
398355
398366
|
externalId: payload.messageId,
|
|
398356
398367
|
channel: mapChannelType(metadata.channelType),
|
|
398357
398368
|
instanceId: metadata.instanceId,
|
|
@@ -398369,7 +398380,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
398369
398380
|
conversationId: null,
|
|
398370
398381
|
...chatLink
|
|
398371
398382
|
};
|
|
398372
|
-
await sdb.insert(omniEvents).values(
|
|
398383
|
+
await sdb.insert(omniEvents).values({ ...eventIdInsert(event.id), ...columns2 }).onConflictDoUpdate({ target: omniEvents.id, set: columns2 });
|
|
398373
398384
|
});
|
|
398374
398385
|
log126.debug(`Persisted ${type}`, { messageId: payload.messageId, emoji: payload.emoji });
|
|
398375
398386
|
} catch (error3) {
|
|
@@ -528518,63 +528529,6 @@ var contentExtractors = [
|
|
|
528518
528529
|
{
|
|
528519
528530
|
check: (m2) => !!m2.messageHistoryBundle,
|
|
528520
528531
|
extract: () => null
|
|
528521
|
-
},
|
|
528522
|
-
{
|
|
528523
|
-
check: (m2) => !!m2.deviceSentMessage,
|
|
528524
|
-
extract: (m2) => {
|
|
528525
|
-
const deviceMsg = m2.deviceSentMessage;
|
|
528526
|
-
const innerMsg = deviceMsg?.message;
|
|
528527
|
-
if (innerMsg) {
|
|
528528
|
-
for (const { check, extract } of contentExtractors.slice(0, -3)) {
|
|
528529
|
-
if (check(innerMsg)) {
|
|
528530
|
-
return extract(innerMsg);
|
|
528531
|
-
}
|
|
528532
|
-
}
|
|
528533
|
-
}
|
|
528534
|
-
return null;
|
|
528535
|
-
}
|
|
528536
|
-
},
|
|
528537
|
-
{
|
|
528538
|
-
check: (m2) => !!m2.editedMessage,
|
|
528539
|
-
extract: (m2) => {
|
|
528540
|
-
const innerMsg = m2.editedMessage?.message;
|
|
528541
|
-
if (innerMsg) {
|
|
528542
|
-
for (const { check, extract } of contentExtractors.slice(0, -1)) {
|
|
528543
|
-
if (check(innerMsg)) {
|
|
528544
|
-
return extract(innerMsg);
|
|
528545
|
-
}
|
|
528546
|
-
}
|
|
528547
|
-
}
|
|
528548
|
-
return null;
|
|
528549
|
-
}
|
|
528550
|
-
},
|
|
528551
|
-
{
|
|
528552
|
-
check: (m2) => !!m2.ephemeralMessage,
|
|
528553
|
-
extract: (m2) => {
|
|
528554
|
-
const innerMsg = m2.ephemeralMessage?.message;
|
|
528555
|
-
if (innerMsg) {
|
|
528556
|
-
for (const { check, extract } of contentExtractors.slice(0, -1)) {
|
|
528557
|
-
if (check(innerMsg)) {
|
|
528558
|
-
return extract(innerMsg);
|
|
528559
|
-
}
|
|
528560
|
-
}
|
|
528561
|
-
}
|
|
528562
|
-
return null;
|
|
528563
|
-
}
|
|
528564
|
-
},
|
|
528565
|
-
{
|
|
528566
|
-
check: (m2) => !!m2.viewOnceMessage,
|
|
528567
|
-
extract: (m2) => {
|
|
528568
|
-
const innerMsg = m2.viewOnceMessage?.message;
|
|
528569
|
-
if (innerMsg) {
|
|
528570
|
-
for (const { check, extract } of contentExtractors.slice(0, -1)) {
|
|
528571
|
-
if (check(innerMsg)) {
|
|
528572
|
-
return extract(innerMsg);
|
|
528573
|
-
}
|
|
528574
|
-
}
|
|
528575
|
-
}
|
|
528576
|
-
return null;
|
|
528577
|
-
}
|
|
528578
528532
|
}
|
|
528579
528533
|
];
|
|
528580
528534
|
var INTERNAL_MESSAGE_TYPES = new Set([
|
|
@@ -528598,10 +528552,33 @@ function extractUnknownContent(message2) {
|
|
|
528598
528552
|
log52.debug("Unknown message type", { keys: messageKeys });
|
|
528599
528553
|
return { type: "unknown" };
|
|
528600
528554
|
}
|
|
528555
|
+
var ENVELOPE_KEYS = [
|
|
528556
|
+
"deviceSentMessage",
|
|
528557
|
+
"ephemeralMessage",
|
|
528558
|
+
"viewOnceMessage",
|
|
528559
|
+
"viewOnceMessageV2",
|
|
528560
|
+
"viewOnceMessageV2Extension",
|
|
528561
|
+
"editedMessage",
|
|
528562
|
+
"documentWithCaptionMessage",
|
|
528563
|
+
"associatedChildMessage",
|
|
528564
|
+
"groupStatusMessage",
|
|
528565
|
+
"groupStatusMessageV2"
|
|
528566
|
+
];
|
|
528567
|
+
function unwrapEnvelopes(message2) {
|
|
528568
|
+
let current = message2;
|
|
528569
|
+
for (let depth = 0;depth < 5; depth++) {
|
|
528570
|
+
const record2 = current;
|
|
528571
|
+
const key = ENVELOPE_KEYS.find((k2) => record2[k2]?.message);
|
|
528572
|
+
if (!key)
|
|
528573
|
+
break;
|
|
528574
|
+
current = record2[key]?.message;
|
|
528575
|
+
}
|
|
528576
|
+
return current;
|
|
528577
|
+
}
|
|
528601
528578
|
function extractContent3(msg) {
|
|
528602
|
-
|
|
528603
|
-
if (!message2)
|
|
528579
|
+
if (!msg.message)
|
|
528604
528580
|
return null;
|
|
528581
|
+
const message2 = unwrapEnvelopes(msg.message);
|
|
528605
528582
|
for (const { check, extract } of contentExtractors) {
|
|
528606
528583
|
if (check(message2)) {
|
|
528607
528584
|
const result = extract(message2);
|
|
@@ -528715,8 +528692,11 @@ async function handleSpecialMessage(plugin10, instanceId, content, externalId, c
|
|
|
528715
528692
|
await plugin10.handleReactionReceived(instanceId, externalId, chatId, senderId, content.emoji || "", content.targetMessageId || "", isFromMe(msg));
|
|
528716
528693
|
return true;
|
|
528717
528694
|
}
|
|
528718
|
-
if (content.type === "edit"
|
|
528719
|
-
|
|
528695
|
+
if (content.type === "edit") {
|
|
528696
|
+
log52.debug("Edit protocol message seen on upsert; awaiting messages.update", {
|
|
528697
|
+
instanceId,
|
|
528698
|
+
targetMessageId: content.targetMessageId
|
|
528699
|
+
});
|
|
528720
528700
|
return true;
|
|
528721
528701
|
}
|
|
528722
528702
|
if (content.type === "delete" && content.targetMessageId) {
|
|
@@ -528890,6 +528870,11 @@ function setupMessageHandlers4(sock, plugin10, instanceId, decryptTracker, dedup
|
|
|
528890
528870
|
if (update.update.status !== undefined && update.update.status !== null) {
|
|
528891
528871
|
await processStatusUpdate(plugin10, instanceId, update.key, update.update.status);
|
|
528892
528872
|
}
|
|
528873
|
+
const newText = extractEditedText(normalizeMessageContent(update.update.message));
|
|
528874
|
+
if (newText) {
|
|
528875
|
+
const { chatId } = resolveChatId(plugin10, instanceId, { key: update.key });
|
|
528876
|
+
await plugin10.handleMessageEdited(instanceId, update.key.id || "", chatId, newText, update.key.fromMe || false);
|
|
528877
|
+
}
|
|
528893
528878
|
}
|
|
528894
528879
|
});
|
|
528895
528880
|
sock.ev.on("messages.delete", async (deletion) => {
|
|
@@ -531791,7 +531776,8 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
531791
531776
|
messageId: targetMessageId,
|
|
531792
531777
|
chatId,
|
|
531793
531778
|
from,
|
|
531794
|
-
emoji: ""
|
|
531779
|
+
emoji: "",
|
|
531780
|
+
rawPayload: { externalId, isFromMe: isFromMe2 }
|
|
531795
531781
|
});
|
|
531796
531782
|
}
|
|
531797
531783
|
}
|