@automagik/omni 2.260910.12 → 2.260910.13
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 +56 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -137198,7 +137198,7 @@ import { fileURLToPath } from "url";
|
|
|
137198
137198
|
// package.json
|
|
137199
137199
|
var package_default = {
|
|
137200
137200
|
name: "@automagik/omni",
|
|
137201
|
-
version: "2.260910.
|
|
137201
|
+
version: "2.260910.13",
|
|
137202
137202
|
repository: {
|
|
137203
137203
|
type: "git",
|
|
137204
137204
|
url: "git+https://github.com/automagik-dev/omni.git",
|
package/dist/server/index.js
CHANGED
|
@@ -251645,7 +251645,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
251645
251645
|
var require_package7 = __commonJS((exports, module) => {
|
|
251646
251646
|
module.exports = {
|
|
251647
251647
|
name: "@omni/api",
|
|
251648
|
-
version: "2.260910.
|
|
251648
|
+
version: "2.260910.13",
|
|
251649
251649
|
private: true,
|
|
251650
251650
|
type: "module",
|
|
251651
251651
|
exports: {
|
|
@@ -363797,6 +363797,19 @@ async function postProcessChat(services, chat2, _chatCreated, chatExternalId, ch
|
|
|
363797
363797
|
function resolveSenderDisplayName(senderName, rawPayload, participantResult) {
|
|
363798
363798
|
return truncate4(senderName ?? rawPayload?.pushName, 255) || participantResult?.participant.displayName || undefined;
|
|
363799
363799
|
}
|
|
363800
|
+
async function resolveQuotedSenderName(services, chatId, quotedMessage) {
|
|
363801
|
+
const pushName = truncate4(quotedMessage?.pushName, 255);
|
|
363802
|
+
if (pushName)
|
|
363803
|
+
return pushName;
|
|
363804
|
+
const participant = quotedMessage?.participant;
|
|
363805
|
+
if (!participant)
|
|
363806
|
+
return;
|
|
363807
|
+
const platformUserId = participant.split("@")[0]?.split(":")[0];
|
|
363808
|
+
if (!platformUserId)
|
|
363809
|
+
return;
|
|
363810
|
+
const existing = await services.chats.findParticipant(chatId, platformUserId);
|
|
363811
|
+
return truncate4(existing?.displayName ?? undefined, 255);
|
|
363812
|
+
}
|
|
363800
363813
|
async function maybeFindOrCreateParticipant(services, chatId, from, rawPayload, personId, platformIdentityId, senderName) {
|
|
363801
363814
|
if (!from)
|
|
363802
363815
|
return;
|
|
@@ -363956,7 +363969,7 @@ async function handleMessageReceived(services, payload, metadata, eventTimestamp
|
|
|
363956
363969
|
mediaLocalPath: rawPayload?.mediaLocalPath,
|
|
363957
363970
|
replyToExternalId: truncate4(payload.replyToId, 255),
|
|
363958
363971
|
quotedText: quotedMessage?.conversation,
|
|
363959
|
-
quotedSenderName:
|
|
363972
|
+
quotedSenderName: await resolveQuotedSenderName(services, chat2.id, quotedMessage),
|
|
363960
363973
|
threadExternalId: truncate4(payload.threadId, 255),
|
|
363961
363974
|
isThreadBroadcast: rawPayload?.isThreadBroadcast === true,
|
|
363962
363975
|
isForwarded: !!(rawPayload?.isForwarded || rawPayload?.forwardingScore),
|
|
@@ -370062,8 +370075,12 @@ class ChatService {
|
|
|
370062
370075
|
}).where(eq(chatParticipants.id, existing.id)).returning();
|
|
370063
370076
|
return updated ?? existing;
|
|
370064
370077
|
}
|
|
370065
|
-
async
|
|
370078
|
+
async findParticipant(chatId, platformUserId) {
|
|
370066
370079
|
const [existing] = await this.db.select().from(chatParticipants).where(and2(eq(chatParticipants.chatId, chatId), eq(chatParticipants.platformUserId, platformUserId))).limit(1);
|
|
370080
|
+
return existing;
|
|
370081
|
+
}
|
|
370082
|
+
async findOrCreateParticipant(chatId, platformUserId, defaults2 = {}) {
|
|
370083
|
+
const existing = await this.findParticipant(chatId, platformUserId);
|
|
370067
370084
|
if (existing) {
|
|
370068
370085
|
const hasNewIdentity = defaults2.personId || defaults2.platformIdentityId;
|
|
370069
370086
|
const missingIdentity = !existing.personId || !existing.platformIdentityId;
|
|
@@ -398043,6 +398060,16 @@ async function resolveChatLink(db2, instanceId, chatId) {
|
|
|
398043
398060
|
return NO_CHAT_LINK;
|
|
398044
398061
|
}
|
|
398045
398062
|
}
|
|
398063
|
+
async function resolveReplyToEventId(db2, instanceId, replyToExternalId) {
|
|
398064
|
+
if (!instanceId || !replyToExternalId)
|
|
398065
|
+
return null;
|
|
398066
|
+
try {
|
|
398067
|
+
const [row] = await db2.select({ id: omniEvents.id }).from(omniEvents).where(and2(eq(omniEvents.instanceId, instanceId), eq(omniEvents.externalId, replyToExternalId))).orderBy(omniEvents.receivedAt).limit(1);
|
|
398068
|
+
return row?.id ?? null;
|
|
398069
|
+
} catch {
|
|
398070
|
+
return null;
|
|
398071
|
+
}
|
|
398072
|
+
}
|
|
398046
398073
|
async function resolvePersonId2(db2, candidate) {
|
|
398047
398074
|
if (typeof candidate !== "string" || !isValidUuid(candidate))
|
|
398048
398075
|
return null;
|
|
@@ -398077,6 +398104,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
398077
398104
|
await runConsumerInTenantContext(db2, event, async () => {
|
|
398078
398105
|
const sdb = scopedHandle(db2);
|
|
398079
398106
|
const chatLink = await resolveChatLink(sdb, metadata.instanceId, payload.chatId);
|
|
398107
|
+
const replyToEventId = await resolveReplyToEventId(sdb, metadata.instanceId, payload.replyToId);
|
|
398080
398108
|
const columns2 = {
|
|
398081
398109
|
externalId: payload.externalId,
|
|
398082
398110
|
channel: mapChannelType(metadata.channelType),
|
|
@@ -398091,6 +398119,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
398091
398119
|
mediaMimeType: payload.content.mimeType,
|
|
398092
398120
|
chatId: payload.chatId,
|
|
398093
398121
|
replyToExternalId: payload.replyToId,
|
|
398122
|
+
replyToEventId,
|
|
398094
398123
|
status: "received",
|
|
398095
398124
|
receivedAt: new Date(event.timestamp),
|
|
398096
398125
|
rawPayload: payload.rawPayload ? deepSanitize(payload.rawPayload) : undefined,
|
|
@@ -398127,6 +398156,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
398127
398156
|
await runConsumerInTenantContext(db2, event, async () => {
|
|
398128
398157
|
const sdb = scopedHandle(db2);
|
|
398129
398158
|
const chatLink = await resolveChatLink(sdb, metadata.instanceId, payload.chatId);
|
|
398159
|
+
const replyToEventId = await resolveReplyToEventId(sdb, metadata.instanceId, payload.replyToId);
|
|
398130
398160
|
const newEvent = {
|
|
398131
398161
|
...eventIdInsert(event.id),
|
|
398132
398162
|
externalId: payload.externalId,
|
|
@@ -398142,6 +398172,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
398142
398172
|
mediaMimeType: payload.content.mimeType,
|
|
398143
398173
|
chatId: payload.chatId,
|
|
398144
398174
|
replyToExternalId: payload.replyToId,
|
|
398175
|
+
replyToEventId,
|
|
398145
398176
|
status: "completed",
|
|
398146
398177
|
receivedAt: new Date(event.timestamp),
|
|
398147
398178
|
processedAt: new Date,
|
|
@@ -528591,6 +528622,19 @@ function getReplyToId2(msg) {
|
|
|
528591
528622
|
const contextInfo = getMessageContextInfo(msg);
|
|
528592
528623
|
return contextInfo?.stanzaId || undefined;
|
|
528593
528624
|
}
|
|
528625
|
+
function extractQuotedContext(msg) {
|
|
528626
|
+
const contextInfo = getMessageContextInfo(msg);
|
|
528627
|
+
if (!contextInfo?.quotedMessage)
|
|
528628
|
+
return;
|
|
528629
|
+
const content = extractContent3({ key: msg.key, message: contextInfo.quotedMessage });
|
|
528630
|
+
const type = content?.type ?? "unknown";
|
|
528631
|
+
return {
|
|
528632
|
+
stanzaId: contextInfo.stanzaId || undefined,
|
|
528633
|
+
participant: contextInfo.participant || undefined,
|
|
528634
|
+
type,
|
|
528635
|
+
conversation: content?.text || content?.caption || `[${type}]`
|
|
528636
|
+
};
|
|
528637
|
+
}
|
|
528594
528638
|
function isFromMe(msg) {
|
|
528595
528639
|
return msg.key.fromMe === true;
|
|
528596
528640
|
}
|
|
@@ -531691,6 +531735,7 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
531691
531735
|
}
|
|
531692
531736
|
} catch {}
|
|
531693
531737
|
}
|
|
531738
|
+
await this.enrichPayloadWithQuotedMessage(extendedPayload, instanceId, chatId, rawMessage);
|
|
531694
531739
|
if (content.poll)
|
|
531695
531740
|
extendedPayload.poll = content.poll;
|
|
531696
531741
|
if (content.pollVotes)
|
|
@@ -532223,6 +532268,7 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
532223
532268
|
if (content.localPath)
|
|
532224
532269
|
rawPayload.mediaLocalPath = content.localPath;
|
|
532225
532270
|
this.enrichPayloadWithChatName(rawPayload, instanceId, chatId);
|
|
532271
|
+
await this.enrichPayloadWithQuotedMessage(rawPayload, instanceId, chatId, msg);
|
|
532226
532272
|
const historySenderName = msg.pushName ?? undefined;
|
|
532227
532273
|
await this.emitMessageReceived({
|
|
532228
532274
|
instanceId,
|
|
@@ -532242,6 +532288,13 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
532242
532288
|
});
|
|
532243
532289
|
}
|
|
532244
532290
|
}
|
|
532291
|
+
async enrichPayloadWithQuotedMessage(rawPayload, instanceId, chatId, msg) {
|
|
532292
|
+
const quoted = extractQuotedContext(msg);
|
|
532293
|
+
if (!quoted)
|
|
532294
|
+
return;
|
|
532295
|
+
const pushName = quoted.participant ? (await this.getContactInfo(instanceId, quoted.participant, chatId))?.name : undefined;
|
|
532296
|
+
rawPayload.quotedMessage = { ...quoted, pushName };
|
|
532297
|
+
}
|
|
532245
532298
|
enrichPayloadWithChatName(payload, instanceId, chatId) {
|
|
532246
532299
|
if (chatId.includes("@g.us")) {
|
|
532247
532300
|
const group = this.groupsCache.get(instanceId)?.get(chatId);
|