diff --git a/packages/client/src/methods/_init.ts b/packages/client/src/methods/_init.ts index 77ca3824..0116084d 100644 --- a/packages/client/src/methods/_init.ts +++ b/packages/client/src/methods/_init.ts @@ -58,6 +58,14 @@ interface TelegramClientOptions extends Omit { - Conversation.handleUpdate(this, update) + if (Conversation.handleUpdate(this, update) && skipConversationUpdates) return + this.emit('update', update) this.emit(update.name, update.data) }, diff --git a/packages/client/src/types/conversation.ts b/packages/client/src/types/conversation.ts index c28a603b..d001a7a5 100644 --- a/packages/client/src/types/conversation.ts +++ b/packages/client/src/types/conversation.ts @@ -71,9 +71,15 @@ export class Conversation { return (client as any)[CONVERSATION_SYMBOL] as ConversationsState } - static handleUpdate(client: BaseTelegramClient, update: ParsedUpdate): void { + /** + * Pass the update to the conversation manager and all registered + * conversations on this client. + * + * @returns `true` if the update was handled by some conversation + */ + static handleUpdate(client: BaseTelegramClient, update: ParsedUpdate): boolean { const state = Conversation._getState(client) - if (!state?.hasConversations) return + if (!state?.hasConversations) return false let chatId @@ -86,25 +92,30 @@ export class Conversation { chatId = update.data.chatId break default: - return + return false } const conv = state.pendingConversations.get(chatId) - if (!conv) return + if (!conv) return false for (const c of conv) { switch (update.name) { case 'new_message': c._onNewMessage(update.data) - break + + return true case 'edit_message': c._onEditMessage(update.data) - break + + return true case 'history_read': c._onHistoryRead(update.data) - break + + return true } } + + return false } /**