Während des Starts der Anwendung wird ein Fehler angezeigt: Fehler beim Entfernen des alten Webhooks.
Kollegen, bitte helfen Sie mir.
Die folgenden Informationen werden in den Protokollen angezeigt:
Code: Select all
WARN BotInitializer : ⚠️ Ignoring the webhook error for the Long Polling bot: Error removing old webhook
ERROR BotInitializer : ❌ It was not possible to register the bot even on the second attempt: Error removing old webhook
Ich habe versucht, den Webhook zu löschen, aber es hilft nicht. Der Webhook wurde wie folgt gelöscht:
Code: Select all
https://api.telegram.org/botMY_BOT_TOKEN/deleteWebhook
Code: Select all
// I received the following response
{
"ok": true,
"result": true,
"description": "Webhook is already deleted"
}
Die Version, die ich verwende: Implementierung 'org.telegram:telegrambots-spring-boot-starter:6.9.0'
Vollständige Liste der Abhängigkeiten:
Code: Select all
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-quartz'
implementation 'org.telegram:telegrambots-spring-boot-starter:6.9.0'
implementation 'com.google.http-client:google-http-client-jackson2:1.43.3'
implementation 'com.google.api-client:google-api-client:2.0.0'
// HTTP client
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Code: Select all
@Slf4j
@Component
@RequiredArgsConstructor
public class BotInitializer {
private final TelegramBotService telegramBotService;
@EventListener(ApplicationReadyEvent.class)
public void initializeBot() {
try {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
telegramBotsApi.registerBot(telegramBotService);
log.info("✅ Telegram bot has been successfully registered");
} catch (TelegramApiException e) {
if (e.getMessage().contains("Error removing old webhook")) {
log.warn("⚠️ Ignoring the webhook error for the Long Polling bot: {}", e.getMessage());
// We are trying to register again
try {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
telegramBotsApi.registerBot(telegramBotService);
log.info("✅ Telegram bot registered on the second attempt");
} catch (TelegramApiException ex) {
log.error("❌ It was not possible to register the bot even on the second attempt: {}", ex.getMessage());
}
} else {
log.error("❌ Error when registering the bot: {}", e.getMessage());
}
}
}
}
Code: Select all
@Slf4j
@Service
public class TelegramBotService extends TelegramLongPollingBot {
private final ApplicationEventPublisher eventPublisher;
private final String botToken;
private final String botUsername;
public TelegramBotService(
ApplicationEventPublisher eventPublisher,
@Value("${telegram.bot.token}") String botToken,
@Value("${telegram.bot.username}") String botUsername) {
super(botToken);
this.eventPublisher = eventPublisher;
this.botToken = botToken;
this.botUsername = botUsername;
log.info("TelegramBotService initialized for the bot: {}", botUsername);
}
@Override
public void onUpdateReceived(Update update) {
log.debug("An update has been received: {}", update);
eventPublisher.publishEvent(new TelegramUpdateEvent(this, update));
}
@Override
public String getBotUsername() {
return botUsername;
}
@Override
public String getBotToken() {
return botToken;
}
}
Mobile version