Telegramium-2.49.0
Telegramium 2.49.0 released.
It supports all methods and entities of Telegram Bot API v4.9.
This MAJOR release introduces significant breaking changes.
Notable changes
- The
Methods
fabric was added. You don't need to create*Req
objects by hand now. - You can perform a request to the Bot API while sending an answer to the webhook.
- All Update types are supported.
An excerpt from the documentation:
How to use
Create the dependency by adding the following lines to your build.sbt:
libraryDependencies += "io.github.apimorphism" %% "telegramium-core" % "2.49.0"
libraryDependencies += "io.github.apimorphism" %% "telegramium-high" % "2.49.0"
Imports:
import telegramium.bots.high._
import telegramium.bots.high.implicits._
Use the Methods
fabric to create requests. You will need an instance of the BotApi
class to execute them:
BlazeClientBuilder[F](ExecutionContext.global).resource.use { httpClient =>
implicit val api: Api[F] = BotApi(http, baseUrl = s"https://api.telegram.org/bot$token")
val bot = new MyLongPollBot()
bot.start()
}
Long polling
class MyLongPollBot[F[_]: Sync: Timer]()(implicit api: Api[F]) extends LongPollBot[F](api) {
override def onMessage(msg: Message): F[Unit] =
Methods.sendMessage(chatId = ChatIntId(msg.chat.id), text = "Hello, world!").exec.void
}
LongPollBot
and WebhookBot
extend the Methods
trait so you can call sendMessage
directly.
Webhooks
class MyWebhookBot[F[_]: ConcurrentEffect: ContextShift: Timer](port: Int, url: String, path: String)(
implicit api: Api[F]
) extends WebhookBot[F](api, port, url, path) {
override def onMessage(msg: Message): F[Unit] =
sendMessage(chatId = ChatIntId(msg.chat.id), text = "Hello, world!").exec.void
}
You can also perform a request to the Bot API while sending an answer to the webhook:
override def onMessageReply(msg: Message): F[Option[Method[_]]] =
Sync[F].pure(Some(sendMessage(chatId = ChatIntId(msg.chat.id), text = "Hello, world!")))