Permanent authorization error that suspended polling; cleared after successful authorization.
Registered chain handlers followed by independent subscriptions.
Shared polling load and per-channel request timing; returns a detached snapshot.
A copy of the local update state: pts, qts, date and seq.
Ids of channels registered for polling by watch, including pending initialization.
Installs the handler for anything thrown inside the chain.
Fetches everything missed since the last known state.
Removes a middleware or handler from the chain.
Handles updates of the given raw names, or the events of a builder.
A raw name gives the original update typed as its schema class; a
builder gives that builder's event object, as addEventHandler does. An
array of handlers runs in order, each deciding with next() whether the
rest of them run.
Raw update names, or an event builder.
One handler or an ordered array of them.
Optionaloptions: OnOptions
Chat and predicate filters, see OnOptions.
A function that removes the handler.
client.updates.on("newChannelMessage", (update) => console.log(update.message.id));
client.updates.on(["newMessage", "newChannelMessage"], handler);
client.updates.on("botCallbackQuery", [checkAuth, handleClick]);
client.updates.on("newChannelMessage", handler, { chats: ["durov"] });
client.updates.on(new NewMessage({}), (event) => event.message.reply({ message: "hi" }));
Handles updates of the given raw names, or the events of a builder.
A raw name gives the original update typed as its schema class; a
builder gives that builder's event object, as addEventHandler does. An
array of handlers runs in order, each deciding with next() whether the
rest of them run.
One handler or an ordered array of them.
Optionaloptions: OnOptions
Chat and predicate filters, see OnOptions.
A function that removes the handler.
client.updates.on("newChannelMessage", (update) => console.log(update.message.id));
client.updates.on(["newMessage", "newChannelMessage"], handler);
client.updates.on("botCallbackQuery", [checkAuth, handleClick]);
client.updates.on("newChannelMessage", handler, { chats: ["durov"] });
client.updates.on(new NewMessage({}), (event) => event.message.reply({ message: "hi" }));
Adds a middleware to the end of the chain. It sees every update, so this is the place for logging, timing or authentication.
see UpdateMiddleware.
A function that removes it.
Handles updates from the given chats and polls channel differences.
Registration is synchronous and may precede start(). Channels resume
from their saved pts after reconnect; unsubscribing releases their polling slot.
All channels share channelPollRequestInterval and channelPollConcurrency,
including channel initialization and difference pages. More channels increase
delay; server timeouts are minimum intervals, not delivery deadlines.
Without a server timeout, polling uses channelPollInterval (1000 ms by default).
Flood waits pause the shared budget. Inspect polling for queue delays.
Delayed polling may interrupt passive delivery from channels you have not joined;
differences resume while server history is available. No channel-count cap is imposed.
Expired history yields a recent snapshot, not every missed event.
Messages recovered from differences use synthetic updates with pts = ptsCount = 0.
Read update.context.chat or await update.context.getChat() for the source chat.
Chat information is absent for updates without a peer.
Permanent authorization failures suspend polling and reach catch once.
Polling resumes after login or a successful updates.getState call; see authorizationError.
Chats to listen to: usernames, ids or entities.
Optionalhandler: Optional handler; without it only the subscription is kept.
Optionaloptions: WatchOptions & { events?: undefined }
Which updates to handle, see WatchOptions.
A function that stops watching and removes the handler.
Handles updates from the given chats and polls channel differences.
Registration is synchronous and may precede start(). Channels resume
from their saved pts after reconnect; unsubscribing releases their polling slot.
All channels share channelPollRequestInterval and channelPollConcurrency,
including channel initialization and difference pages. More channels increase
delay; server timeouts are minimum intervals, not delivery deadlines.
Without a server timeout, polling uses channelPollInterval (1000 ms by default).
Flood waits pause the shared budget. Inspect polling for queue delays.
Delayed polling may interrupt passive delivery from channels you have not joined;
differences resume while server history is available. No channel-count cap is imposed.
Expired history yields a recent snapshot, not every missed event.
Messages recovered from differences use synthetic updates with pts = ptsCount = 0.
Read update.context.chat or await update.context.getChat() for the source chat.
Chat information is absent for updates without a peer.
Permanent authorization failures suspend polling and reach catch once.
Polling resumes after login or a successful updates.getState call; see authorizationError.
Chats to listen to: usernames, ids or entities.
Optional handler; without it only the subscription is kept.
Which updates to handle, see WatchOptions.
A function that stops watching and removes the handler.
Handles updates from the given chats and polls channel differences.
Registration is synchronous and may precede start(). Channels resume
from their saved pts after reconnect; unsubscribing releases their polling slot.
All channels share channelPollRequestInterval and channelPollConcurrency,
including channel initialization and difference pages. More channels increase
delay; server timeouts are minimum intervals, not delivery deadlines.
Without a server timeout, polling uses channelPollInterval (1000 ms by default).
Flood waits pause the shared budget. Inspect polling for queue delays.
Delayed polling may interrupt passive delivery from channels you have not joined;
differences resume while server history is available. No channel-count cap is imposed.
Expired history yields a recent snapshot, not every missed event.
Messages recovered from differences use synthetic updates with pts = ptsCount = 0.
Read update.context.chat or await update.context.getChat() for the source chat.
Chat information is absent for updates without a peer.
Permanent authorization failures suspend polling and reach catch once.
Polling resumes after login or a successful updates.getState call; see authorizationError.
Chats to listen to: usernames, ids or entities.
Optionalhandler: UpdateMiddleware<T> | UpdateMiddleware<T>[]
Optional handler; without it only the subscription is kept.
Optionaloptions: WatchOptions
Which updates to handle, see WatchOptions.
A function that stops watching and removes the handler.
The update pipeline of a client, reachable as
client.updates.Handlers form one chain:
next()passes the update on, returning without it consumes the update. on matches first, by raw schema name or by an event builder; watch also polls channel differences for the chats it is given.independent: trueregistrations run alongside this chain and cannot consume each other's updates.A raw name gives the original
Api.TypeUpdate, a builder gives its event object. Direct and small-group messages arrive as theupdateShortMessagecontainers, which are not part of theUpdateunion; the chain expands them, so"newMessage"sees them too.Each update carries a
stateobject for middleware to leave things in.contextexposeschatId,chat,getChat(),inputChatandclientwithout changing TL fields or the second argument,next().chatuses attached entities; onlygetChat()may fetch a missing chat. Throws go to catch, or to the client's error handler.client.addEventHandlerkeeps working and runs before this chain; aStopPropagationthere ends that loop only.Example