# Long polling - InMo Docs
Single documentation place for all Insanus Mokrassar libraries
Author: Ovsiannikov Aleksei

Skip to content

# 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

- Updates filters

## 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 automatically
  - `RequestsExecutor#startGettingOfUpdatesByLongPolling` Old and almost deprecated way
  - `RequestsExecutor#longPolling` Works like `startGettingOfUpdatesByLongPolling` but shorted in a name :)
- `RequestsExecutor#createAccumulatedUpdatesRetrieverFlow` Works like `longPollingFlow`, 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` Use `createAccumulatedUpdatesRetrieverFlow` to perform all accumulated updates
  - `RequestsExecutor#flushAccumulatedUpdates` Works like `retrieveAccumulatedUpdates` but perform all updates directly in a place of calling
- By yourself with `GetUpdates` request or `RequestsExecutor#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
    }

## See also

- Webhooks
- Updates filters