【问题标题】:Error when try to connect to telegram bot at spring boot app尝试在 Spring Boot 应用程序中连接到电报机器人时出错
【发布时间】:2019-06-17 20:49:19
【问题描述】:

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

2019-06-17 23:26:33.117 错误 3340 --- [gram Connection] Telegram Bots 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);
    }
}

【问题讨论】:

    标签: java spring maven spring-boot telegram


    【解决方案1】:

    如果访问机器人,请验证一次只有一台服务器。电报机器人地址一次只能由一台服务器访问。如果您在本地有一台服务器,而另一台服务器在另一台服务器上运行,当您尝试在本地连接时它会抛出同样的问题。

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

    【讨论】:

    • 它的常见spring bot应用程序,据我了解,当我启动它时,只有一个本地服务器启动。如果我错了,应用程序如你所说在两台服务器上启动,也许你知道如何解决这个问题并只启动一个?
    猜你喜欢
    • 2021-01-03
    • 1970-01-01
    • 2020-10-13
    • 2018-08-31
    • 2022-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多