fix: OUT messages no longer create unread status + handle Telegram read receipts
Only inbound (IN) messages determine hasUnread in getContacts(). Telegram read_business_message events are now parsed and processed to auto-mark contacts as read for the entire team. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,7 @@ function pickEventType(update: JsonObject): string {
|
||||
if (update.edited_business_message) return "edited_business_message";
|
||||
if (update.business_connection) return "business_connection";
|
||||
if (update.deleted_business_messages) return "deleted_business_messages";
|
||||
if (update.read_business_message) return "read_business_message";
|
||||
if (update.message) return "message";
|
||||
if (update.edited_message) return "edited_message";
|
||||
return "unknown";
|
||||
@@ -148,9 +149,42 @@ function makeFallbackEventId(raw: unknown) {
|
||||
|
||||
export function parseTelegramBusinessUpdate(raw: unknown): OmniInboundEnvelopeV1 {
|
||||
const update = asObject(raw);
|
||||
const message = pickMessage(update);
|
||||
const receivedAt = new Date().toISOString();
|
||||
|
||||
// Handle read_business_message separately — different payload structure
|
||||
const readEvent = asObject(update.read_business_message);
|
||||
if (Object.keys(readEvent).length > 0) {
|
||||
const readChat = asObject(readEvent.chat);
|
||||
const threadExternalId = normalizeId(readChat.id);
|
||||
const businessConnectionId = normalizeString(readEvent.business_connection_id);
|
||||
const updateId = update.update_id;
|
||||
const providerEventId =
|
||||
(updateId != null && requireString(updateId, "")) || makeFallbackEventId(raw);
|
||||
const occurredAt = isoFromUnix(readEvent.date) ?? receivedAt;
|
||||
|
||||
return {
|
||||
version: 1,
|
||||
idempotencyKey: ["telegram_business", providerEventId, "read"].join(":"),
|
||||
provider: "telegram_business",
|
||||
channel: "TELEGRAM",
|
||||
direction: "IN",
|
||||
providerEventId,
|
||||
providerMessageId: null,
|
||||
eventType: "read_business_message",
|
||||
occurredAt,
|
||||
receivedAt,
|
||||
payloadRaw: raw,
|
||||
payloadNormalized: {
|
||||
threadExternalId,
|
||||
contactExternalId: threadExternalId,
|
||||
text: null,
|
||||
businessConnectionId,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const message = pickMessage(update);
|
||||
|
||||
const updateId = update.update_id;
|
||||
const messageId = message.message_id;
|
||||
const businessConnection = asObject(update.business_connection);
|
||||
|
||||
Reference in New Issue
Block a user