2

I need help with this error when working with Telegram API

Error removing old webhook
at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:112)
.....
Caused by: Error deleting webhook: [404] Not Found

I have created a bot with telegram,

Service class:

@Service
public class Test1Api {


    @Autowired
    public Test1Api(@Value("${bot.username:}") String botUserName, @Value("${bot.token:}") String botToken) {
        try {
            TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
            telegramBotsApi.registerBot(new Test1Bot(botUserName, botToken));
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
}

here is the bot class

public class Test1Bot extends TelegramLongPollingBot {

private final String botUserName;
private final String botToken;

public Test1Bot(String botUserName, String botToken) {
    this.botUserName = botUserName;
    this.botToken = botToken;
}


@Override
public String getBotUsername() {
    return botUserName;
}

@Override
public String getBotToken() {
    return botToken;
}

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

When i try to run my code i have an error from telegram attaching here The error from telegram: What can i do to fix it?

Hard Worker
  • 995
  • 11
  • 33

1 Answers1

1

Make sure you provide a good token. You can check it by manually requesting your telegram bot to delete webhook. [POST] https://api.telegram.org/bot<your_token>/deleteWebhook

If everything is alright you should get as a response: { "ok": true, "result": true, "description": "Webhook is already deleted" }

Then you'll be sure that your token is correct but you're providing it wrong. Maybe check your application.properties

However if your response is different (eg. Not Found) - there's problem with your telegram token.

IncogVito
  • 53
  • 7