Skip to content

alllex/telegram-bot-kit

Repository files navigation

Telegram Bot API in Kotlin

Maven Central License: MIT Gradle build

Idiomatic, fluent and type-safe Kotlin bindings for Telegram Bot API.

val poller = TelegramBotApiPoller(TelegramBotApiClient(botApiToken))
poller.start(TelegramBotUpdateListener(
    onMessage = { message ->
        message.reply(
            text = "Hello, *${message.from?.firstName ?: "stranger"}*!",
            parseMode = ParseMode.MARKDOWN,
            replyMarkup = inlineKeyboard {
                buttonLink("Telegram", "https://telegram.org")
                row {
                    button("Bot", "bot")
                    button("API", "api")
                }
            }
        )
    },
    onCallbackQuery = { callbackQuery ->
        when (callbackQuery.data) {
            "bot" -> callbackQuery.answer("🤖")
            "api" -> callbackQuery.answer("🚀")
            else -> callbackQuery.answer("🤷")
        }
    }
))

Usage

Using with Gradle for JVM projects
dependencies {
    implementation("me.alllex.telegram.botkit:tbot-api-jvm:0.5.0")
}
Using with Maven for JVM projects
<dependency>
  <groupId>me.alllex.telegram.botkit</groupId>
  <artifactId>tbot-api-jvm</artifactId>
  <version>0.5.0</version>
</dependency>

Compatibility

The bindings are generated directly from the source-of-truth Bot API spec.

Telegram Bot API tbot-api library
7.3 0.5.0
6.9 0.4.0
tbot-api library Requirement
0.4.0+ Kotlin 1.9.0+, JVM 8+

Developing

Updating API to a new version of Telegram Bot API

./gradlew :buildSrc:updateApiSpec --no-configuration-cache
./gradlew generateTelegramBotApi
./gradlew apiDump
./gradlew check

Roadmap

Alpha

  • Error handling

Beta

  • Cleaner package structure
  • Strict library member visibility
  • Forward compatibility: published versions of the library should not break with new API versions (union types and enums)
  • Support for integration tests bots

License

Distributed under the MIT License. See LICENSE for more information.