Long polling¶
Long polling is a technology of getting updates for cases you do not have some dedicated server or you have no opportunity to receive updates via webhooks. More about this you can read in wiki.
Related topics¶
Long polling in this library¶
There are a lot of ways to include work with long polling:
RequestsExecutor#longPollingFlow
Is the base way to get all updates cold Flow. Remember, that this flow will not be launched automaticallyRequestsExecutor#startGettingOfUpdatesByLongPolling
Old and almost deprecated wayRequestsExecutor#longPolling
Works likestartGettingOfUpdatesByLongPolling
but shorted in a name :)
RequestsExecutor#createAccumulatedUpdatesRetrieverFlow
Works likelongPollingFlow
, but flow inside will return only the updates accumulated at the moment of calls (all new updates will not be passed throw this flow)RequestsExecutor#retrieveAccumulatedUpdates
UsecreateAccumulatedUpdatesRetrieverFlow
to perform all accumulated updatesRequestsExecutor#flushAccumulatedUpdates
Works likeretrieveAccumulatedUpdates
but perform all updates directly in a place of calling
- By yourself with
GetUpdates
request orRequestsExecutor#getUpdates
extension
longPolling¶
longPolling
is a simple way to start getting updates and work with bot:
val bot = telegramBot(token)
bot.longPolling(
textMessages().subscribe(scope) { // here "scope" is a CoroutineScope
println(it) // will be printed each update from chats with messages
}
)
startGettingOfUpdatesByLongPolling¶
The main aim of startGettingOfUpdatesByLongPolling
extension was to provide more simple way to get updates in automatic mode:
val bot = telegramBot(token)
bot.startGettingOfUpdatesByLongPolling(
{
println(it) // will be printed each update from chats with messages
}
)
The other way is to use the most basic startGettingOfUpdatesByLongPolling
extension:
val bot = telegramBot(token)
bot.startGettingOfUpdatesByLongPolling {
println(it) // will be printed each update
}