• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

kotlin-telegram-bot/kotlin-telegram-bot:

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

kotlin-telegram-bot/kotlin-telegram-bot

开源软件地址(OpenSource Url):

https://github.com/kotlin-telegram-bot/kotlin-telegram-bot

开源编程语言(OpenSource Language):

Kotlin 100.0%

开源软件介绍(OpenSource Introduction):

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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap