longPollingFlow

fun TelegramBot.longPollingFlow(exceptionsHandler: ExceptionHandler<Unit>? = null, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000, getUpdatesRequestCreator: (sinceUpdate: UpdateId?) -> GetUpdates): Flow<Update>

Starts a long polling flow to receive updates continuously from the Telegram Bot API.

This method retrieves updates from the bot, processes them, and emits them as a flow of Update objects. It allows handling of updates with features like automatic webhook disabling, timeout exception skipping, and media group handling with debounce time.

Return

A Flow of Update objects that represents the continuous stream of updates received.

Parameters

exceptionsHandler

Optional exception handler to manage exceptions that occur during the polling process.

autoDisableWebhooks

Specifies whether to automatically disable existing webhooks before starting the long polling flow (default: true).

autoSkipTimeoutExceptions

Defines if timeout-related exceptions should automatically be skipped during the polling (default: true).

mediaGroupsDebounceTimeMillis

The debounce time in milliseconds for processing media group updates. If set to null, media group handling is disabled (default: 1000L).

getUpdatesRequestCreator

A function that creates a GetUpdates request for retrieving updates. This function accepts the identifier of the most recent update as an input and returns the new request.


fun TelegramBot.longPollingFlow(timeoutSeconds: Seconds = 30, exceptionsHandler: ExceptionHandler<Unit>? = null, allowedUpdates: List<String>? = ALL_UPDATES_LIST, autoDisableWebhooks: Boolean = true, autoSkipTimeoutExceptions: Boolean = true, mediaGroupsDebounceTimeMillis: Long? = 1000): Flow<Update>

Initiates a long polling flow for receiving updates continuously from the Telegram Bot API. This method provides a customized way to handle the retrieval of updates with options to configure timeouts, update types, exception handling, and media group processing.

Return

A Flow that emits Update objects representing the updates fetched from the Telegram Bot API.

Parameters

timeoutSeconds

The maximum time in seconds for the server to wait for available updates before responding (default: 30).

exceptionsHandler

An optional exception handler for managing exceptions that occur during the long polling process. If not provided, exceptions will pass through unhandled.

allowedUpdates

A list of the update types to retrieve. By default, retrieves all possible update types as defined in ALL_UPDATES_LIST.

autoDisableWebhooks

Whether the current webhook should be disabled automatically before starting the long polling flow (default: true).

autoSkipTimeoutExceptions

Determines if timeout-related exceptions should be automatically skipped during the polling process (default: true).

mediaGroupsDebounceTimeMillis

The debounce time in milliseconds for processing updates containing media groups. If set to null, media group handling is disabled (default: 1000L).