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

send an asynchronous message #31

Closed
rccardero opened this issue Apr 17, 2023 · 3 comments
Closed

send an asynchronous message #31

rccardero opened this issue Apr 17, 2023 · 3 comments

Comments

@rccardero
Copy link

Is there a method to send a message to the bot to tell the user to wait since the controller hasn't finished executing?

@kshashov
Copy link
Owner

You can get the com.pengrad.telegrambot.TelegramBot instance from parameters and send whatever you want.

To be honest, I don't understand the problem. Maybe there is some kind of example?

@califortovo
Copy link

After analizing issues made some instruction

  1. Create config file and assign TelegramBot instance as a static variable
@Component
public class BotConfig implements TelegramBotGlobalPropertiesConfiguration {
    @Getter
    @Value("${bot.token}")
    private String token;

    public static TelegramBot telegramBot;

    @Override
    public void configure(TelegramBotGlobalProperties.Builder builder) {

        builder.processBot(token, bot -> {
            telegramBot = bot;
            bot.execute(new SendMessage(396325842, "test"));
        });
    }
}
  1. In bot application get bot instance and use it
TelegramBot bot = BotConfig.telegramBot;
bot.execute(new SendMessage(chatId, "message"));

kshashov pushed a commit that referenced this issue Jul 27, 2023
@kshashov
Copy link
Owner

Added this workaround to the readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants