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.

Long polling in this library

There are several ways to include work with long polling:

  • With RequestsExecutor#longPolling (Recommended way)
  • With RequestsExecutor#startGettingOfUpdatesByLongPolling (Deprecated)
  • With RequestsExecutor#startGettingFlowsUpdatesByLongPolling (Deprecated)
  • By yourself with GetUpdates request or RequestsExecutor#getUpdates extension


longPolling is a simple way to start getting updates and work with bot:

val bot = telegramBot(token)
  textMessages().subscribe(scope) { // here "scope" is a CoroutineScope
    println(it) // will be printed each update from chats with messages


The main aim of startGettingOfUpdatesByLongPolling extension was to provide more simple way to get updates in automatic mode:

val bot = telegramBot(token)
    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

The most problem here is the it is very low-level way and you should filter messages by yourself with extracting from updates. In case if you want to use more simple way, you are welcome to startGettingFlowsUpdatesByLongPolling topic.


Currently it is the most comfortable and easy way to get updates. Example analog for previous chapter:

val bot = telegramBot(token)
val scope = CoroutineScope(Dispatchers.Default)
bot.startGettingFlowsUpdatesByLongPolling {
  messageFlow.onEach {

Filtering of messages
More info about filtering and working with FlowsUpdatesFilter you can get on page with Updates filters

See also