Skip to content
πŸ€– A wrapper for the Telegram Bot API written in Kotlin
Kotlin
Branch: master
Clone or download
Latest commit 614930d Sep 16, 2019

README.md

Kotlin Telegram Bot

Build Status Release ktlint

A wrapper for the Telegram Bot API written in Kotlin.

Usage

Creating a bot instance is really simple:

fun main(args: Array<String>) {
    val bot = bot {
        token = "YOUR_API_KEY"
    }
}

Now lets poll telegram API and route all text updates:

fun main(args: Array<String>) {
    val bot = bot {
        token = "YOUR_API_KEY"
        dispatch {
            text { bot, update ->
                val text = update.message?.text ?: "Hello, World!"
                bot.sendMessage(chatId = update.message!!.chat.id, text = text)
            }
        }
    }
    bot.startPolling()
}

Want to route commands?:

fun main(args: Array<String>) {
    val bot = bot {
        token = "YOUR_API_KEY"
        dispatch {
            command("start") { bot, update->
                val result = bot.sendMessage(chatId = update.message!!.chat.id, text = "Hi there!")
                result.fold({
                    // do something here with the response
                },{
                    // do something with the error 
                })
            }
        }
    }
    bot.startPolling()
}

Examples

Take a look at the examples folder.

There is a simple echo bot and a more complex one with commands, filters, reply markup keyboard and more.

Download

  • Add the JitPack repository to your root build.gradle file:
repositories {
    maven { url "https://jitpack.io" }
}
  • Add the code to your module's build.gradle file:
dependencies {
    implementation 'io.github.seik.kotlin-telegram-bot:telegram:x.y.z'
}

Contributing

  1. Fork and clone the repo
  2. Run ./gradlew ktlintFormat
  3. Run ./gradlew check to see if tests and ktlint pass.
  4. Commit and push your changes
  5. Submit a pull request to get your changes reviewed

Thanks

  • Big part of the architecture of this project is inspired by python-telegram-bot, check it out!
  • Some awesome kotlin ninja techniques were grabbed from Fuel.

License

Kotlin Telegram Bot is under the Apache 2.0 license. See the LICENSE for more information.

You can’t perform that action at this time.