kotlin-telegram-bot/kotlin-telegram-bot
关于
🤖 使用 Kotlin 编写的 Telegram Bot API 封装库
其他项目实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- -1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Kotlin Telegram Bot
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'
}
Upgrading from 6.x
The current line (10.x) is up to date with Bot API 10.0 and includes the breaking changes Telegram introduced between 6.3 and 10.0. If you're coming from 6.2.0 or earlier, read docs/MIGRATION_10.md before bumping — most code will keep compiling, but getChat now returns ChatFullInfo (not Chat), the legacy reply / forward / preview parameters have richer replacements, and the duplicate entities.SuccessfulPayment was removed.
Detailed documentation
Core
- Getting updates — polling, webhooks, allowed update types.
- Webhooks —
webhook { }DSL,secretToken, manualprocessUpdate. - Error handling —
TelegramBotResultandtelegramError { }. - Logging.
- File uploads —
TelegramFile.ByFile/ByByteArray/ByInputStream/ByUrl/ByFileId.
Chat and messages
- Chat and ChatFullInfo — the 7.3 split.
- Reply parameters — quoting, cross-chat replies.
- Link preview options — custom URL, size, position.
- Forum topics — create / edit / close / delete; General topic.
- Reactions — set, delete, paid reactions.
Built-in content
Telegram Stars and monetisation
- Telegram Stars — invoices, refunds, transactions.
- Paid media —
sendPaidMedia, purchases. - Gifts — sending and managing.
Business bots
- Business connection — connecting, sending on behalf, account management.
- Stories —
postStory,editStory,deleteStory, clickable areas.
Contributing
- Fork and clone the repo
- Run
./gradlew ktlintFormat - Run
./gradlew buildto see if tests, ktlint and abi checks pass. - Commit and push your changes
- 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.
探索相关项目
加载中…