@automagik/omni 2.260907.4 → 2.260907.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 +3 -1
- package/dist/server/index.js +111 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11260,6 +11260,8 @@ var init_types3 = __esm(() => {
|
|
|
11260
11260
|
"message.delivered",
|
|
11261
11261
|
"message.read",
|
|
11262
11262
|
"message.failed",
|
|
11263
|
+
"message.pinned",
|
|
11264
|
+
"message.unpinned",
|
|
11263
11265
|
"message.button_click",
|
|
11264
11266
|
"message.poll",
|
|
11265
11267
|
"message.poll_vote",
|
|
@@ -136390,7 +136392,7 @@ import { fileURLToPath } from "url";
|
|
|
136390
136392
|
// package.json
|
|
136391
136393
|
var package_default = {
|
|
136392
136394
|
name: "@automagik/omni",
|
|
136393
|
-
version: "2.260907.
|
|
136395
|
+
version: "2.260907.5",
|
|
136394
136396
|
repository: {
|
|
136395
136397
|
type: "git",
|
|
136396
136398
|
url: "git+https://github.com/automagik-dev/omni.git",
|
package/dist/server/index.js
CHANGED
|
@@ -139,6 +139,8 @@ var init_types2 = __esm(() => {
|
|
|
139
139
|
"message.delivered",
|
|
140
140
|
"message.read",
|
|
141
141
|
"message.failed",
|
|
142
|
+
"message.pinned",
|
|
143
|
+
"message.unpinned",
|
|
142
144
|
"message.button_click",
|
|
143
145
|
"message.poll",
|
|
144
146
|
"message.poll_vote",
|
|
@@ -44631,6 +44633,14 @@ class BaseChannelPlugin {
|
|
|
44631
44633
|
const { instanceId, ...payload } = params;
|
|
44632
44634
|
await this.publishEventInternal("reaction.removed", payload, instanceId);
|
|
44633
44635
|
}
|
|
44636
|
+
async emitMessagePinned(params) {
|
|
44637
|
+
const { instanceId, ...payload } = params;
|
|
44638
|
+
await this.publishEventInternal("message.pinned", payload, instanceId);
|
|
44639
|
+
}
|
|
44640
|
+
async emitMessageUnpinned(params) {
|
|
44641
|
+
const { instanceId, ...payload } = params;
|
|
44642
|
+
await this.publishEventInternal("message.unpinned", payload, instanceId);
|
|
44643
|
+
}
|
|
44634
44644
|
async emitButtonClick(params) {
|
|
44635
44645
|
const { instanceId, ...payload } = params;
|
|
44636
44646
|
await this.publishEventInternal("message.button_click", payload, instanceId);
|
|
@@ -250957,7 +250967,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
250957
250967
|
var require_package7 = __commonJS((exports, module) => {
|
|
250958
250968
|
module.exports = {
|
|
250959
250969
|
name: "@omni/api",
|
|
250960
|
-
version: "2.260907.
|
|
250970
|
+
version: "2.260907.5",
|
|
250961
250971
|
private: true,
|
|
250962
250972
|
type: "module",
|
|
250963
250973
|
exports: {
|
|
@@ -352230,6 +352240,23 @@ async function linkReplyTarget(services, chatId, messageId, replyToExternalId) {
|
|
|
352230
352240
|
});
|
|
352231
352241
|
}
|
|
352232
352242
|
}
|
|
352243
|
+
async function linkThreadRoot(services, chatId, messageId, messageExternalId, threadExternalId, repliedAt) {
|
|
352244
|
+
if (!threadExternalId || threadExternalId === messageExternalId)
|
|
352245
|
+
return;
|
|
352246
|
+
try {
|
|
352247
|
+
const rootMessageId = await services.messages.resolveReplyToMessage(chatId, threadExternalId);
|
|
352248
|
+
if (!rootMessageId)
|
|
352249
|
+
return;
|
|
352250
|
+
await services.messages.setThreadRoot(messageId, rootMessageId);
|
|
352251
|
+
await services.messages.recordThreadReply(rootMessageId, repliedAt);
|
|
352252
|
+
} catch (error3) {
|
|
352253
|
+
log90.debug("Could not link thread root", {
|
|
352254
|
+
chatId,
|
|
352255
|
+
threadExternalId,
|
|
352256
|
+
error: error3 instanceof Error ? error3.message : String(error3)
|
|
352257
|
+
});
|
|
352258
|
+
}
|
|
352259
|
+
}
|
|
352233
352260
|
async function handleMessageReceived(services, payload, metadata, eventTimestamp, trustedTenantId, identity) {
|
|
352234
352261
|
const channel5 = metadata.channelType ?? "whatsapp";
|
|
352235
352262
|
const isHistorySync = metadata.ingestMode === "history-sync";
|
|
@@ -352282,6 +352309,7 @@ async function handleMessageReceived(services, payload, metadata, eventTimestamp
|
|
|
352282
352309
|
if (created) {
|
|
352283
352310
|
log90.debug("Created message", { externalId: payload.externalId, chatId: chat2.id });
|
|
352284
352311
|
await linkReplyTarget(services, chat2.id, message2.id, payload.replyToId);
|
|
352312
|
+
await linkThreadRoot(services, chat2.id, message2.id, messageExternalId, truncate4(payload.threadId, 255), platformTimestamp ?? new Date(eventTimestamp));
|
|
352285
352313
|
}
|
|
352286
352314
|
await maybeRecordParticipantActivity(services, chat2.id, payload.from);
|
|
352287
352315
|
maybeUpdateRecency(services, metadata.instanceId, chat2.id, rawPayload, payload, platformTimestamp ?? new Date(eventTimestamp), trustedTenantId);
|
|
@@ -352306,6 +352334,29 @@ function logMessageReceivedError(payload, error3) {
|
|
|
352306
352334
|
longFields: Object.keys(longFields).length > 0 ? longFields : undefined
|
|
352307
352335
|
});
|
|
352308
352336
|
}
|
|
352337
|
+
async function handleMessagePinState(services, event, pinned) {
|
|
352338
|
+
const payload = event.payload;
|
|
352339
|
+
const metadata = event.metadata;
|
|
352340
|
+
if (!metadata.instanceId)
|
|
352341
|
+
return;
|
|
352342
|
+
const instanceId = metadata.instanceId;
|
|
352343
|
+
try {
|
|
352344
|
+
await runConsumerInTenantContext(services.db, event, async () => {
|
|
352345
|
+
const chat2 = await services.chats.findByExternalIdSmart(instanceId, payload.chatId);
|
|
352346
|
+
if (!chat2) {
|
|
352347
|
+
log90.debug("Chat not found for pin update", { chatId: payload.chatId });
|
|
352348
|
+
return;
|
|
352349
|
+
}
|
|
352350
|
+
await services.messages.setPinned(chat2.id, payload.messageId, pinned, payload.from);
|
|
352351
|
+
log90.debug("Updated message pin state", { chatId: chat2.id, messageId: payload.messageId, pinned });
|
|
352352
|
+
});
|
|
352353
|
+
} catch (error3) {
|
|
352354
|
+
log90.error("Failed to update pin state", {
|
|
352355
|
+
messageId: payload.messageId,
|
|
352356
|
+
error: String(error3)
|
|
352357
|
+
});
|
|
352358
|
+
}
|
|
352359
|
+
}
|
|
352309
352360
|
async function setupMessagePersistence(eventBus, services) {
|
|
352310
352361
|
try {
|
|
352311
352362
|
await eventBus.subscribe("message.received", async (event) => {
|
|
@@ -352382,6 +352433,9 @@ async function setupMessagePersistence(eventBus, services) {
|
|
|
352382
352433
|
replyToExternalId: truncate4(payload.replyToId, 255),
|
|
352383
352434
|
threadExternalId: truncate4(payload.threadId, 255)
|
|
352384
352435
|
});
|
|
352436
|
+
if (created2) {
|
|
352437
|
+
await linkThreadRoot(services, chat3.id, message3.id, messageExternalId, truncate4(payload.threadId, 255), new Date(event.timestamp));
|
|
352438
|
+
}
|
|
352385
352439
|
return { chat: chat3, message: message3, created: created2 };
|
|
352386
352440
|
});
|
|
352387
352441
|
if (created) {
|
|
@@ -352484,6 +352538,22 @@ async function setupMessagePersistence(eventBus, services) {
|
|
|
352484
352538
|
startFrom: "first",
|
|
352485
352539
|
concurrency: 10
|
|
352486
352540
|
});
|
|
352541
|
+
await eventBus.subscribe("message.pinned", (event) => handleMessagePinState(services, event, true), {
|
|
352542
|
+
durable: "message-persistence-pinned",
|
|
352543
|
+
queue: "message-persistence",
|
|
352544
|
+
maxRetries: 2,
|
|
352545
|
+
retryDelayMs: 500,
|
|
352546
|
+
startFrom: "first",
|
|
352547
|
+
concurrency: 10
|
|
352548
|
+
});
|
|
352549
|
+
await eventBus.subscribe("message.unpinned", (event) => handleMessagePinState(services, event, false), {
|
|
352550
|
+
durable: "message-persistence-unpinned",
|
|
352551
|
+
queue: "message-persistence",
|
|
352552
|
+
maxRetries: 2,
|
|
352553
|
+
retryDelayMs: 500,
|
|
352554
|
+
startFrom: "first",
|
|
352555
|
+
concurrency: 10
|
|
352556
|
+
});
|
|
352487
352557
|
await eventBus.subscribe("instance.connected", async (event) => {
|
|
352488
352558
|
const payload = event.payload;
|
|
352489
352559
|
const instanceId = payload.instanceId;
|
|
@@ -360570,6 +360640,16 @@ class MessageService {
|
|
|
360570
360640
|
async updateReplyToReference(id, replyToMessageId) {
|
|
360571
360641
|
await this.db.update(messages2).set({ replyToMessageId, updatedAt: new Date }).where(eq(messages2.id, id));
|
|
360572
360642
|
}
|
|
360643
|
+
async setThreadRoot(id, threadRootMessageId) {
|
|
360644
|
+
await this.db.update(messages2).set({ threadRootMessageId, updatedAt: new Date }).where(eq(messages2.id, id));
|
|
360645
|
+
}
|
|
360646
|
+
async recordThreadReply(rootMessageId, repliedAt) {
|
|
360647
|
+
await this.db.update(messages2).set({
|
|
360648
|
+
replyCount: sql`${messages2.replyCount} + 1`,
|
|
360649
|
+
latestReplyAt: sql`GREATEST(COALESCE(${messages2.latestReplyAt}, ${repliedAt}), ${repliedAt})`,
|
|
360650
|
+
updatedAt: new Date
|
|
360651
|
+
}).where(eq(messages2.id, rootMessageId));
|
|
360652
|
+
}
|
|
360573
360653
|
}
|
|
360574
360654
|
var MEDIA_BADGES2;
|
|
360575
360655
|
var init_messages3 = __esm(() => {
|
|
@@ -397274,6 +397354,27 @@ function setupMessageHandlers2(app, instanceId, botUserId, callbacks, dmPolicyCo
|
|
|
397274
397354
|
logger5.info("Message handlers registered", { instanceId });
|
|
397275
397355
|
}
|
|
397276
397356
|
|
|
397357
|
+
// ../channel-slack/src/handlers/pins.ts
|
|
397358
|
+
function setupPinHandlers(app, instanceId, callbacks, logger5) {
|
|
397359
|
+
const handlePinEvent = (action) => async ({ event }) => {
|
|
397360
|
+
const evt = event;
|
|
397361
|
+
const item = evt.item;
|
|
397362
|
+
if (!item || item.type !== "message")
|
|
397363
|
+
return;
|
|
397364
|
+
const message2 = item.message;
|
|
397365
|
+
const channelId = item.channel ?? evt.channel_id ?? "";
|
|
397366
|
+
const messageTs = message2?.ts ?? "";
|
|
397367
|
+
if (!channelId || !messageTs)
|
|
397368
|
+
return;
|
|
397369
|
+
const userId = evt.user;
|
|
397370
|
+
logger5.debug(action === "pin" ? "Pin added" : "Pin removed", { instanceId, channelId, messageTs, userId });
|
|
397371
|
+
await callbacks.onPin(instanceId, messageTs, channelId, userId, action);
|
|
397372
|
+
};
|
|
397373
|
+
app.event("pin_added", handlePinEvent("pin"));
|
|
397374
|
+
app.event("pin_removed", handlePinEvent("unpin"));
|
|
397375
|
+
logger5.info("Pin handlers registered", { instanceId });
|
|
397376
|
+
}
|
|
397377
|
+
|
|
397277
397378
|
// ../channel-slack/src/handlers/reactions.ts
|
|
397278
397379
|
function setupReactionHandlers2(app, instanceId, botUserId, callbacks, logger5) {
|
|
397279
397380
|
const resolveBotUserId = () => typeof botUserId === "function" ? botUserId() : botUserId;
|
|
@@ -398962,6 +399063,15 @@ class SlackPlugin extends BaseChannelPlugin {
|
|
|
398962
399063
|
await this.handleReactionReceived(instId, messageId, chatId, userId, emoji, action);
|
|
398963
399064
|
}
|
|
398964
399065
|
}, this.logger);
|
|
399066
|
+
setupPinHandlers(connection.app, instanceId, {
|
|
399067
|
+
onPin: async (instId, messageId, chatId, userId, action) => {
|
|
399068
|
+
if (action === "pin") {
|
|
399069
|
+
await this.emitMessagePinned({ instanceId: instId, messageId, chatId, from: userId });
|
|
399070
|
+
} else {
|
|
399071
|
+
await this.emitMessageUnpinned({ instanceId: instId, messageId, chatId, from: userId });
|
|
399072
|
+
}
|
|
399073
|
+
}
|
|
399074
|
+
}, this.logger);
|
|
398965
399075
|
setupAgentSessionHandlers(connection.app, instanceId, {
|
|
398966
399076
|
onSessionStopped: async (instId, args) => {
|
|
398967
399077
|
await this.handleAgentSessionStopped(instId, connection, args);
|