-
Notifications
You must be signed in to change notification settings - Fork 100
/
Polling.scala
38 lines (33 loc) · 1.09 KB
/
Polling.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.bot4s.telegram.api
import com.bot4s.telegram.methods.GetUpdates
import com.bot4s.telegram.models.Update
import slogging.StrictLogging
import scala.concurrent.duration.{Duration, _}
/** Provides updates by (long) polling Telegram servers.
*
* See [[https://en.wikipedia.org/wiki/Push_technology#Long_polling wiki]].
*
* It relies on the underlying HTTP client which should support a timeout
* allowing the connection to idle for a duration of at least 'pollingTimeout'.
*/
private[telegram] trait Polling[F[_]] extends BotBase[F] with StrictLogging {
/**
* Long-polling timeout in seconds.
*
* Specifies the amount of time the connection will be idle/waiting if there are no updates.
*/
def pollingTimeout: Duration = 30.seconds
/**
* The polling method, overload for custom behavior, e.g. back-off, retries...
*
* @param offset
*/
def pollingGetUpdates(offset: Option[Long]): F[Seq[Update]] =
request(
GetUpdates(
offset,
timeout = Some(pollingTimeout.toSeconds.toInt),
allowedUpdates = allowedUpdates
)
)
}