teleproto - v1.230.0
    Preparing search index...

    Class ClientUpdates

    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: true registrations 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 the updateShortMessage containers, which are not part of the Update union; the chain expands them, so "newMessage" sees them too.

    Each update carries a state object for middleware to leave things in. context exposes chatId, chat, getChat(), inputChat and client without changing TL fields or the second argument, next(). chat uses attached entities; only getChat() may fetch a missing chat. Throws go to catch, or to the client's error handler.

    client.addEventHandler keeps working and runs before this chain; a StopPropagation there ends that loop only.

    client.updates.use(async (update, next) => {
    const started = Date.now();
    await next();
    console.log(`${update.className} handled in ${Date.now() - started}ms`);
    });

    client.updates.on("newChannelMessage", (update) => {
    console.log(update.message.id);
    }, { chats: ["durov"] });

    client.updates.on(new NewMessage({ pattern: /^/start/ }), (event) =>
    event.message.reply({ message: "hi" }));

    const stop = client.updates.watch("obitoscasino", (update) =>
    console.log(update.message.id));
    Index
    • get authorizationError(): Error | undefined

      Permanent authorization error that suspended polling; cleared after successful authorization.

      Returns Error | undefined

    • 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.

      Type Parameters

      Parameters

      Returns Unsubscribe

      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.

      Type Parameters

      • T = any

      Parameters

      Returns Unsubscribe

      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 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.

      Parameters

      • chats: EntityLike | EntityLike[]

        Chats to listen to: usernames, ids or entities.

      • Optionalhandler:
            | UpdateMiddleware<UpdateOf<"newMessage" | "newChannelMessage">>
            | UpdateMiddleware<UpdateOf<"newMessage" | "newChannelMessage">>[]

        Optional handler; without it only the subscription is kept.

      • Optionaloptions: WatchOptions & { events?: undefined }

        Which updates to handle, see WatchOptions.

      Returns Unsubscribe

      A function that stops watching and removes the handler.

      const stop = client.updates.watch(
      ["obitoscasino", "toporlive"],
      (update) => console.log(update.message.id),
      );
      stop();
    • 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.

      Type Parameters

      Parameters

      Returns Unsubscribe

      A function that stops watching and removes the handler.

      const stop = client.updates.watch(
      ["obitoscasino", "toporlive"],
      (update) => console.log(update.message.id),
      );
      stop();
    • 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.

      Type Parameters

      • T = any

      Parameters

      Returns Unsubscribe

      A function that stops watching and removes the handler.

      const stop = client.updates.watch(
      ["obitoscasino", "toporlive"],
      (update) => console.log(update.message.id),
      );
      stop();