🤖 A wrapper for the Telegram Bot API written in Kotlin
A wrapper for the Telegram Bot API written in Kotlin.
Creating a bot instance is really simple:
fun main() {
val bot = bot {
token = "YOUR_API_KEY"
}
}
Now lets poll telegram API and route all text updates:
fun main() {
val bot = bot {
token = "YOUR_API_KEY"
dispatch {
text {
bot.sendMessage(ChatId.fromId(message.chat.id), text = text)
}
}
}
bot.startPolling()
}
Want to route commands?:
fun main() {
val bot = bot {
token = "YOUR_API_KEY"
dispatch {
command("start") {
val result = bot.sendMessage(chatId = ChatId.fromId(message.chat.id), text = "Hi there!")
result.fold({
// do something here with the response
},{
// do something with the error
})
}
}
}
bot.startPolling()
}
Take a look at the examples folder.
There are several samples:
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:x.y.z'
}
./gradlew ktlintFormat
./gradlew build
to see if tests, ktlint and abi checks pass.Kotlin Telegram Bot is under the Apache 2.0 license. See the LICENSE for more information.