中文 | English
Telegram组件 是一个 Kotlin 多平台 的 Telegram Bot API SDK实现库, 也是 Simple Robot 标准API下实现的组件库,异步高效、Java友好!
序列化和网络请求相关分别基于 Kotlin serialization 和 Ktor.
序列化和网络请求相关分别基于 Kotlin serialization 和 Ktor.
- 手册: Simple Robot 应用手册 及其中的 Telegram组件 部分。
- API文档: 文档引导站点 中 Telegram 的 KDoc站点
- 社群: 与我们和其他开发者愉快地交流!
参考手册的 Telegram组件 部分。
simbot core
suspend fun main() {
val app = launchSimpleApplication {
useTelegram() // install Telegram Component
}
// subscribe to events
app.listeners {
// subscribe to ChatGroupMessageEvent
listen<ChatGroupMessageEvent> { event ->
// process event...
event.reply("Hello!")
event.reply(At(event.authorId) + "Where are you?".toText())
// Required an result
EventResult.empty()
}
// subscribe to ChatGroupMessageEvent
process<TelegramPrivateMessageEvent> { event ->
// process event...
event.content().send("Welcome, " + At(event.member().id))
// Without result in `process<T>`
}
}
// register bots
app.telegramBots {
// register a bot via token
val bot = register(token = "botaaabbb.123123444") {
// Config...
// The source stdlib bot config
botConfiguration {
apiClientConfigurer {
engine {
// A proxy?
proxy = ProxyBuilder.http("http://127.0.0.1:7790")
}
}
// Enable longPolling?
longPolling = LongPolling(
limit = 100,
timeout = 10.minutes.inWholeSeconds.toInt(),
allowedUpdates = setOf(UpdateValues.MESSAGE_NAME),
// Enable retry?
retry = LongPolling.Retry()
)
}
}
// start the bot
bot.start()
}
app.join()
}
simbot Spring Boot starter
@SpringBootApplication
@EnableSimbot // enable
class App
fun main(args: Array<String>) {
runApplication<App>(*args)
}
@Component
class MyHandles {
@Listener // subscribe to ChatGroupMemberIncreaseEvent
suspend fun handleMemberIncrease(event: ChatGroupMemberIncreaseEvent) {
// ...
}
@Filter("Hello.*")
@Listener // subscribe to ChatGroupMessageEvent
suspend fun handleGroupMessage(event: ChatGroupMessageEvent) {
event.reply("Hello!")
}
}
The configuration file *.bot.json
Comments are not supported. Remember to clean them up when you use them.
{
"component": "simbot.telegram",
"ticket": {
"token": "Your FULL Bot Token, e.g. Bot123456789:aaaabbbbcccc"
},
// config and its properties are optional and default to `null`.
"config": {
"server": null,
"proxy": null,
"longPolling": null
}
}
{
"component": "simbot.telegram",
"ticket": {
"token": "Your FULL Bot Token, e.g. Bot123456789:aaaabbbbcccc"
},
// config and its properties are optional and default to `null`.
"config": {
"server": null,
"proxy": null,
// config the `longPolling` to subscribe evnets
"longPolling": {
"limit": 100
}
}
}
前往 贡献指南 了解更多!
我们欢迎并期望着您的 反馈 或 协助, 感谢您的贡献与支持!
simbot-component-telegram
使用 LGPLv3
许可证开源。
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.