jTelegram / jTelegramBotAPI

Java Telegram Bot API Wrapper
https://jtelegram.github.io/jTelegramBotAPI/
MIT License
20 stars 12 forks source link

Add kTelegram for Kotlin Support #53

Closed mkotb closed 4 years ago

mkotb commented 4 years ago

This PR adds support for first-class support for Kotlin into jTelegram as kTelegram with coroutines, extension functions, and a simplified API:


fun main(args: Array<String>) = runBlocking {
    val registry = TelegramBotRegistry.builder()
            .updateProvider(PollingUpdateProvider.builder().build())
            .build()

    val bot = registry.registerBot(args[0])

    println("${bot.botInfo.username} has started!")

    bot.commandRegistry.registerCommand("start", suspendCommand { event, _ ->
        try {
            event.replyWith(textBuilder {
                bold("Welcome to my example bot!"); newLines(2)

                +"I love showing off my formatting skills"; newLine()

                italics("Like "); link("this", "https://google.com/"); newLine()

                +"I can also escape your name: "; escaped(event.message.sender.firstName)
            })

            event.replyWith("I can also reply directly to your message", true)

            println("Yay we did it!")
        } catch (e: TelegramException) {
            println("Oh no, we failed! Let's complain :(")
            e.printStackTrace()
        }
    })
}```