При запуске приложения появляется ошибка: "Ошибка удаления старого вебхука"JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 При запуске приложения появляется ошибка: "Ошибка удаления старого вебхука"

Сообщение Anonymous »

Пишу своего Telegram-бота, но не могу его запустить.

При запуске приложения отображается ошибка: Ошибка удаления старого вебхука.

Коллеги, помогите.
В логах отображается следующая информация:
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

Честно говоря, я уже не знаю, что делать. Я проверял свой токен Telegram-бота, он работает правильно.
Я пробовал удалить вебхук, но это не помогает. Вебхук был удален следующим образом:
https://api.telegram.org/botMY_BOT_TOKEN/deleteWebhook

// I received the following response
{
"ok": true,
"result": true,
"description": "Webhook is already deleted"
}

Я использую Spring Boot + Java. В качестве компоновщика проекта я использую Gradle.
Используемая мной версия: реализация 'org.telegram:telegrambots-spring-boot-starter:6.9.0'
Полный список зависимостей:
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'
}

@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());
}
}
}

}

@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;
}
}


Подробнее здесь: https://stackoverflow.com/questions/798 ... ld-webhook
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»