Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Telegram组件启动时初始化Bot的问题 #886

Closed
Flock-YT opened this issue Jul 23, 2024 · 2 comments · Fixed by simple-robot/simbot-component-telegram#29
Closed
Assignees
Labels
疑问 一个疑问 组件:Telegram 与 Telegram 组件相关

Comments

@Flock-YT
Copy link

Flock-YT commented Jul 23, 2024

版本号

simbot-component-telegram:v0.0.8

涉及的编程语言

Java

涉及的组件库

Telegram

疑问描述

由于TelegramBot的特性,几乎在每次启动的时候都要执行一些类来初始化机器人例如:

// 获取命令更新器并添加命令 阻塞线程
            bot.commandsBlocking()
                    .getUpdater()
                    .addCommand("start", "开始使用Bot")
                    .addCommand("help", "获取帮助信息")
                    .addCommand("info", "查看Bot信息")
                    .addCommand("111", "111")
                    .updateBlocking();

但是由于Simbot是异步启动在Springboot中使用@PostConstruct注解在启动后自动运行初始化类的时候Bot还没启动完毕,导致拿不到Bot,请问是否考虑提供一个接口,在所有Bot都启动完毕后就会自动执行依赖了这个接口的类

(还是说其实已经有这种东西了,但是我看了一下文档似乎没找到.)

@Flock-YT Flock-YT added the 疑问 一个疑问 label Jul 23, 2024
@ForliyScarlet ForliyScarlet added the 等待确认 等待负责人员的确认 label Jul 23, 2024
@ForteScarlet
Copy link
Member

一般来说应该会有一个XxxBotStartedEvent在bot被启动后推送,不过TG组件似乎尚未实现这个事件

可以考虑在异步中轮询判断,直到有bot了,并且bot.isStarted为true后执行逻辑,然后终止循环

在异步中主要是为了防止长时间阻塞导致其他的副作用

@ForteScarlet ForteScarlet added 组件:Telegram 与 Telegram 组件相关 and removed 等待确认 等待负责人员的确认 labels Jul 23, 2024
@Flock-YT
Copy link
Author

OK了解

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
疑问 一个疑问 组件:Telegram 与 Telegram 组件相关
Projects
None yet
3 participants