尝试在Spring Boot应用程序连接到Telegram Bot时出错

时间:2019-06-17 20:49:19

标签: java spring maven spring-boot telegram

我无法解决我的Spring Boot应用程序中的问题,在那里我尝试创建自己的Telegram机器人。 创建Spring容器并启动应用后,我在日志中看到相同的错误:     Error logs

  

2019-06-17 23:26:33.117错误3340 --- [gram Connection]电报机器人Api:BOTSESSION

Bot Impl

public TelegramBot(BotProperties botProperties) {
    this.botProperties = botProperties;
}

@PostConstruct
public void init() {
    TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
    try {
        telegramBotsApi.registerBot(new TelegramBot(botProperties));
        logger.info("bot successfully register");
    } catch (TelegramApiException e) {
        logger.error(e.getMessage(), e);
    }
}

@Override
public void onUpdateReceived(Update update) {
    if (update.hasMessage()) {
        System.out.println(update.getMessage().getText());
    }
}

@Override
public String getBotUsername() {
    return botProperties.getBotName();
}

@Override
public String getBotToken() {
    return botProperties.getBotToken();
}
}

主类:

public class TelegramApplication {
    public static void main(String[] args) {
        ApiContextInitializer.init();
        SpringApplication.run(TelegramApplication.class, args);
    }
}

1 个答案:

答案 0 :(得分:0)

如果要访问bot,一次只能验证一台服务器。电报漫游器地址一次只能由一台服务器访问。如果您在本地有一个服务器,而一台服务器在另一台服务器上运行,则在尝试将其连接到本地时会抛出相同的信息。

如果您使用devtools重建代码而不重新启动,请尝试停止应用程序并重新启动它。它应该可以工作。