Coder Social home page Coder Social logo

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() {
    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()
}

Examples

Take a look at the examples folder.

There are several samples:

  • A simple echo bot
  • A more complex sample with commands, filter, reply markup keyboard and more
  • A sample getting updates through Telegram's webhook using a Netty server
  • An example bot sending polls and listening to poll answers

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.kotlin-telegram-bot.kotlin-telegram-bot:telegram:x.y.z'
}

Detailed documentation

  1. Getting updates
  2. Polls
  3. Dice
  4. Logging
  5. Games

Contributing

  1. Fork and clone the repo
  2. Run ./gradlew ktlintFormat
  3. Run ./gradlew build to see if tests, ktlint and abi checks 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.

Kotlin Telegram Bot's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.