async start(options) {
        var _a, _b;
        // Perform setup
        await withRetries(() => this.init());
        if (this.pollingRunning) {
            debug("Simple long polling already running!");
            return;
        }
        await withRetries(() => this.api.deleteWebhook({
            drop_pending_updates: options === null || options === void 0 ? void 0 : options.drop_pending_updates,
        }));
        // Prevent common misuse that causes memory leak
        this.use = () => {
            throw new Error(`It looks like you are registering more listeners \
on your bot from within other listeners! This means that every time your bot \
handles a message like this one, new listeners will be added. This list grows until \
your machine crashes, so grammY throws this error to tell you that you should \
probably do things a bit differently. If you're unsure how to resolve this problem, \
you can ask in the group chat: https://telegram.me/grammyjs

On the other hand, if you actually know what you're doing and you do need to install \
further middleware while your bot is running, consider installing a composer \
instance on your bot, and in turn augment the composer after the fact. This way, \
you can circumvent this protection against memory leaks.`);
        };
        // Start polling
        debug("Starting simple long polling");
        this.pollingRunning = true;
        this.pollingAbortController = new shim_node_js_1.AbortController();
        const limit = options === null || options === void 0 ? void 0 : options.limit;
        const timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 30; // seconds
        let allowed_updates = options === null || options === void 0 ? void 0 : options.allowed_updates;
        try {
            (_b = options === null || options === void 0 ? void 0 : options.onStart) === null || _b === void 0 ? void 0 : _b.call(options, this.botInfo);
        }
        catch (error) {
            this.pollingRunning = false;
            this.pollingAbortController = undefined;
            throw error;
        }
        const handleErr = async (error) => {
            if (!this.pollingRunning)
                throw error;
            else if (error instanceof error_js_1.GrammyError) {
                debugErr(error.message);
                if (error.error_code === 401) {
                    debugErr("Make sure you are using the bot token you obtained from @BotFather (https://t.me/BotFather).");
                    throw error;
                }
                else if (error.error_code === 409) {
                    debugErr("Consider revoking the bot token if you believe that no other instance is running.");
                    throw error;
                }
            }
            else
                debugErr(error);
            debugErr("Call to `getUpdates` failed, retrying in 3 seconds ...");
            await new Promise((r) => setTimeout(r, 3000));
        };
        while (this.pollingRunning) {
            // fetch updates
            const offset = this.lastTriedUpdateId + 1;
            let updates = undefined;
            do {
                try {
                    updates = await this.api.getUpdates({ offset, limit, timeout, allowed_updates }, this.pollingAbortController.signal);
                }
                catch (error) {
                    await handleErr(error);
                }
            } while (updates === undefined && this.pollingRunning);
            if (updates === undefined)
                break;
            // handle them sequentially (!)
            for (const update of updates) {
                this.lastTriedUpdateId = update.update_id;
                try {
                    await this.handleUpdate(update);
                }
                catch (err) {
                    // should always be true
                    if (err instanceof composer_js_1.BotError) {
                        await this.errorHandler(err);
                    }
                    else {
                        console.error("FATAL: grammY unable to handle:", err);
                        throw err;
                    }
                }
            }
            // Telegram uses the last setting if `allowed_updates` is omitted so
            // we can save same traffic by only sending it in the first request
            allowed_updates = undefined;
        }
        debug("Middleware is done running");
    }
/**
     * Starts your bot using long polling.
     *
     * > This method returns a `Promise` that will never resolve except if your
     * > bot is stopped. **You don't need to `await` the call to `bot.start`**,
     * > but remember to catch potential errors by calling `bot.catch`.
     * > Otherwise your bot will crash (and stop) if something goes wrong in
     * > your code.
     *
     * This method effectively enters a loop that will repeatedly call
     * `getUpdates` and run your middleware for every received update, allowing
     * your bot to respond to messages.
     *
     * If your bot is already running, this method does nothing.
     *
     * **Note that this starts your bot using a very simple long polling
     * implementation.** `bot.start` should only be used for small bots. While
     * the rest of grammY was built to perform well even under extreme loads,
     * simple long polling is not capable of scaling up in a similar fashion.
     * You should switch over to using `@grammyjs/runner` if you are running a
     * bot with high load.
     *
     * What exactly _high load_ means differs from bot to bot, but as a rule of
     * thumb, simple long polling should not be processing more than ~5K
     * messages every hour. Also, if your bot has long-running operations such
     * as large file transfers that block the middleware from completing, this
     * will impact the responsiveness negatively, so it makes sense to use the
     * `@grammyjs/runner` package even if you receive much fewer messages. If
     * you worry about how much load your bot can handle, check out the grammY
     * [documentation](https://grammy.dev/advanced/scaling.html) about scaling
     * up.
     *
     * @param options Options to use for simple long polling
     */
Starts your bot using long polling.
> This method returns a `Promise` that will never resolve except if your
> bot is stopped.

This method effectively enters a loop that will repeatedly call
`getUpdates` and run your middleware for every received update, allowing
your bot to respond to messages.

If your bot is already running, this method does nothing.

Note that this starts your bot using a very simple long polling
implementation.** `bot.start` should only be used for small bots. While
the rest of grammY was built to perform well even under extreme loads,
simple long polling is not capable of scaling up in a similar fashion.
You should switch over to using `@grammyjs/runner` if you are running a
bot with high load.



@param options Options to use for simple long polling
Starts your bot using long polling . > This method returns a ` Promise ` that will never resolve except if your > bot is stopped . This method effectively enters a loop that will repeatedly call ` getUpdates ` and run your middleware for every received update allowing your bot to respond to messages . If your bot is already running this method does nothing . Note that this starts your bot using a very simple long polling implementation . ** ` bot . start ` should only be used for small bots . While the rest of grammY was built to perform well even under extreme loads simple long polling is not capable of scaling up in a similar fashion . You should switch over to using ` @grammyjs / runner ` if you are running a bot with high load . @param options Options to use for simple long polling
async start(options) {
        var _a, _b;
        await withRetries(() => this.init());
        if (this.pollingRunning) {
            debug("Simple long polling already running!");
            return;
        }
        await withRetries(() => this.api.deleteWebhook({
            drop_pending_updates: options === null || options === void 0 ? void 0 : options.drop_pending_updates,
        }));
        this.use = () => {
            throw new Error(`It looks like you are registering more listeners \
on your bot from within other listeners! This means that every time your bot \
handles a message like this one, new listeners will be added. This list grows until \
your machine crashes, so grammY throws this error to tell you that you should \
probably do things a bit differently. If you're unsure how to resolve this problem, \
you can ask in the group chat: https://telegram.me/grammyjs
On the other hand, if you actually know what you're doing and you do need to install \
further middleware while your bot is running, consider installing a composer \
instance on your bot, and in turn augment the composer after the fact. This way, \
you can circumvent this protection against memory leaks.`);
        };
        debug("Starting simple long polling");
        this.pollingRunning = true;
        this.pollingAbortController = new shim_node_js_1.AbortController();
        const limit = options === null || options === void 0 ? void 0 : options.limit;
        const timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 30; 
        let allowed_updates = options === null || options === void 0 ? void 0 : options.allowed_updates;
        try {
            (_b = options === null || options === void 0 ? void 0 : options.onStart) === null || _b === void 0 ? void 0 : _b.call(options, this.botInfo);
        }
        catch (error) {
            this.pollingRunning = false;
            this.pollingAbortController = undefined;
            throw error;
        }
        const handleErr = async (error) => {
            if (!this.pollingRunning)
                throw error;
            else if (error instanceof error_js_1.GrammyError) {
                debugErr(error.message);
                if (error.error_code === 401) {
                    debugErr("Make sure you are using the bot token you obtained from @BotFather (https://t.me/BotFather).");
                    throw error;
                }
                else if (error.error_code === 409) {
                    debugErr("Consider revoking the bot token if you believe that no other instance is running.");
                    throw error;
                }
            }
            else
                debugErr(error);
            debugErr("Call to `getUpdates` failed, retrying in 3 seconds ...");
            await new Promise((r) => setTimeout(r, 3000));
        };
        while (this.pollingRunning) {
            const offset = this.lastTriedUpdateId + 1;
            let updates = undefined;
            do {
                try {
                    updates = await this.api.getUpdates({ offset, limit, timeout, allowed_updates }, this.pollingAbortController.signal);
                }
                catch (error) {
                    await handleErr(error);
                }
            } while (updates === undefined && this.pollingRunning);
            if (updates === undefined)
                break;
            for (const update of updates) {
                this.lastTriedUpdateId = update.update_id;
                try {
                    await this.handleUpdate(update);
                }
                catch (err) {
                    if (err instanceof composer_js_1.BotError) {
                        await this.errorHandler(err);
                    }
                    else {
                        console.error("FATAL: grammY unable to handle:", err);
                        throw err;
                    }
                }
            }
            allowed_updates = undefined;
        }
        debug("Middleware is done running");
    }
async start ( options ) { var _a , _b ; await withRetries ( ( ) => this . init ( ) ) ; if ( this . pollingRunning ) { debug ( "Simple long polling already running!" ) ; return ; } await withRetries ( ( ) => this . api . deleteWebhook ( { drop_pending_updates : options === null || options === void 0 ? void 0 : options . drop_pending_updates , } ) ) ; this . use = ( ) => { throw new Error ( ` \
 \
 \
 \
 \
 \
 \
 \
 ` ) ; } ; debug ( "Starting simple long polling" ) ; this . pollingRunning = true ; this . pollingAbortController = new shim_node_js_1 . AbortController ( ) ; const limit = options === null || options === void 0 ? void 0 : options . limit ; const timeout = ( _a = options === null || options === void 0 ? void 0 : options . timeout ) !== null && _a !== void 0 ? _a : 30 ; let allowed_updates = options === null || options === void 0 ? void 0 : options . allowed_updates ; try { ( _b = options === null || options === void 0 ? void 0 : options . onStart ) === null || _b === void 0 ? void 0 : _b . call ( options , this . botInfo ) ; } catch ( error ) { this . pollingRunning = false ; this . pollingAbortController = undefined ; throw error ; } const handleErr = async ( error ) => { if ( ! this . pollingRunning ) throw error ; else if ( error instanceof error_js_1 . GrammyError ) { debugErr ( error . message ) ; if ( error . error_code === 401 ) { debugErr ( "Make sure you are using the bot token you obtained from @BotFather (https://t.me/BotFather)." ) ; throw error ; } else if ( error . error_code === 409 ) { debugErr ( "Consider revoking the bot token if you believe that no other instance is running." ) ; throw error ; } } else debugErr ( error ) ; debugErr ( "Call to `getUpdates` failed, retrying in 3 seconds ..." ) ; await new Promise ( ( r ) => setTimeout ( r , 3000 ) ) ; } ; while ( this . pollingRunning ) { const offset = this . lastTriedUpdateId + 1 ; let updates = undefined ; do { try { updates = await this . api . getUpdates ( { offset , limit , timeout , allowed_updates } , this . pollingAbortController . signal ) ; } catch ( error ) { await handleErr ( error ) ; } } while ( updates === undefined && this . pollingRunning ) ; if ( updates === undefined ) break ; for ( const update of updates ) { this . lastTriedUpdateId = update . update_id ; try { await this . handleUpdate ( update ) ; } catch ( err ) { if ( err instanceof composer_js_1 . BotError ) { await this . errorHandler ( err ) ; } else { console . error ( "FATAL: grammY unable to handle:" , err ) ; throw err ; } } } allowed_updates = undefined ; } debug ( "Middleware is done running" ) ; }
Starts your bot using long polling.
Starts your bot using long polling .
// Perform setup // Prevent common misuse that causes memory leak // Start polling // seconds // fetch updates // handle them sequentially (!) // should always be true // Telegram uses the last setting if `allowed_updates` is omitted so // we can save same traffic by only sending it in the first request