### Initialize BotApi with http4s Client Source: https://github.com/apimorphism/telegramium/blob/master/README.md Create an instance of BotApi using http4s BlazeClientBuilder. This is required to execute API requests. ```scala BlazeClientBuilder[F].resource.use { httpClient => implicit val api: Api[F] = BotApi(httpClient, baseUrl = s"https://api.telegram.org/bot$token") val bot = new MyLongPollBot() bot.start() } ``` -------------------------------- ### Create Telegram Keyboards with Smart Constructors Source: https://github.com/apimorphism/telegramium/blob/master/README.md Use these smart constructors for creating reply and inline keyboards. Ensure you import `telegramium.bots.high.keyboards._`. ```scala val button: KeyboardButton = KeyboardButtons.text("Hello, world!") val keyboard: ReplyKeyboardMarkup = ReplyKeyboardMarkups.singleButton(button) val inlineButton: InlineKeyboardButton = InlineKeyboardButtons.callbackData(text = "Press me", callbackData = "button_pressed") val inlineKeyboard: InlineKeyboardMarkup = InlineKeyboardMarkups.singleButton(inlineButton) ``` -------------------------------- ### Import Telegramium High-Level APIs Source: https://github.com/apimorphism/telegramium/blob/master/README.md Import necessary implicits and high-level bot APIs for use in your project. ```scala import telegramium.bots.high._ import telegramium.bots.high.implicits._ ``` -------------------------------- ### Add Telegramium Dependencies Source: https://github.com/apimorphism/telegramium/blob/master/README.md Add these lines to your build.sbt to include the core and high-level libraries. ```scala libraryDependencies += "io.github.apimorphism" %% "telegramium-core" % "" libraryDependencies += "io.github.apimorphism" %% "telegramium-high" % "" ``` -------------------------------- ### Implement Webhook Bot Source: https://github.com/apimorphism/telegramium/blob/master/README.md Extend WebhookBot for webhook-based updates. Define onMessage to process incoming messages and send responses. ```scala class MyWebhookBot[F[_]: Async](url: String, path: String)( implicit api: Api[F] ) extends WebhookBot[F](api, url, path) { override def onMessage(msg: Message): F[Unit] = sendMessage(chatId = ChatIntId(msg.chat.id), text = "Hello, world!").exec.void } ``` -------------------------------- ### Compose Multiple Webhook Bots Source: https://github.com/apimorphism/telegramium/blob/master/README.md Combine multiple WebhookBot instances into a single Http4s server to handle webhook registration and incoming requests for all bots. ```scala val api1: Api[IO] = BotApi(http, baseUrl = s"https://api.telegram.org/bot$bot_token1") val api2: Api[IO] = BotApi(http, baseUrl = s"https://api.telegram.org/bot$bot_token1") val bot1: MyWebhookbot = new MyWebhookbot[IO](api1, "ServerVisibleFromOutside", s"/$bot_token1") val bot2: MyWebhookbot = new MyWebhookbot[IO](api2, "ServerVisibleFromOutside", s"/$bot_token2") WebhookBot.compose[IO]( List(bot1, bot2), 8080, "127.0.0.1" //optional, localhost as default ).useForever.runSyncUnsafe() ``` -------------------------------- ### Perform Request When Sending Webhook Reply Source: https://github.com/apimorphism/telegramium/blob/master/README.md Override onMessageReply to return a Method that will be executed after sending the webhook reply. Useful for chained actions. ```scala override def onMessageReply(msg: Message): F[Option[Method[_]]] = Sync[F].pure(Some(sendMessage(chatId = ChatIntId(msg.chat.id), text = "Hello, world!"))) ``` -------------------------------- ### Compose Styled Messages with Message Entities Source: https://github.com/apimorphism/telegramium/blob/master/README.md Utilize `MessageEntities` to construct messages with various formatting like bold, italics, links, and mentions. This utility class handles offset and length calculations for the Telegram API. Import `telegramium.bots.high.messageentities.*`. ```scala import telegramium.bots.high.messageentities.* val msgEntities = MessageEntities() .bold("Hello, ") .mention("@user") .plain("! Welcome to our ") .textLink("website", "https://example.com") .lineBreak() .plain("Enjoy your stay.") Methods.sendMessage( chatId, // Hello, @user! Welcome to our website\nEnjoy your stay. text = msgEntities.toPlainText(), // List(BoldMessageEntity(0, 7), MentionMessageEntity(7, 5), TextLinkMessageEntity(29, 7, "https://example.com")) entities = msgEntities.toTelegramEntities() ) ``` -------------------------------- ### Implement Long Polling Bot Source: https://github.com/apimorphism/telegramium/blob/master/README.md Extend LongPollBot to handle incoming messages. Override onMessage to define bot logic, like sending a reply. ```scala class MyLongPollBot[F[_]: Async: Parallel]()(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 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.