telegram-bot-kit
telegram-bot-kit copied to clipboard
Idiomatic, fluent and type-safe Kotlin bindings for Telegram Bot API
Telegram Bot API in Kotlin
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.4.0")
}
Using with Maven for JVM projects
<dependency>
<groupId>me.alllex.telegram.botkit</groupId>
<artifactId>tbot-api-jvm</artifactId>
<version>0.4.0</version>
</dependency>
Compatibility
The bindings are generated directly from the source-of-truth Bot API spec.
| Telegram Bot API | tbot-api library |
|---|---|
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.