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#longPollingFlowIs the base way to get all updates cold Flow. Remember, that this flow will not be launched automaticallyRequestsExecutor#startGettingOfUpdatesByLongPollingOld and almost deprecated wayRequestsExecutor#longPollingWorks likestartGettingOfUpdatesByLongPollingbut shorted in a name :)
RequestsExecutor#createAccumulatedUpdatesRetrieverFlowWorks 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#retrieveAccumulatedUpdatesUsecreateAccumulatedUpdatesRetrieverFlowto perform all accumulated updatesRequestsExecutor#flushAccumulatedUpdatesWorks likeretrieveAccumulatedUpdatesbut perform all updates directly in a place of calling
- By yourself with
GetUpdatesrequest orRequestsExecutor#getUpdatesextension
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
}