Telegram webhook doesn’t work. Wrong response from the webhook: 403 Forbidden

1.3k Views Asked by At

I try to set up Telegram webhook to server which is located at glitch.com. I have such code:

const express = require("express");
const app = express();

const TelegramBot = require('node-telegram-bot-api')
const bot = new TelegramBot(process.env.TG_BOT_TOKEN);
bot.setWebHook(`[url]/bot${process.env.TG_BOT_TOKEN}`);

app.use(express.json())

app.post(`/bot${process.env.TG_BOT_TOKEN}`, (req, res) => {
  console.log('it works')
  res.sendStatus(200);  
});

const listener = app.listen(process.env.PORT, () => {
  console.log("Your app is listening on port " + listener.address().port);
});

It looks for me as it will work, but it doesn't. Same code You can find in manuals as examples to set up webhooks.

I checked the status of message at https://api.telegram.org/bot[TOKEN]/getWebhookinfo

{
    "ok": true,
    "result": {
        "url": "[url]/bot[TOKEN]",
        "has_custom_certificate": false,
        "pending_update_count": 2,
        "last_error_date": 1620634795,
        "last_error_message": "Wrong response from the webhook: 403 Forbidden",
        "max_connections": 40,
        "ip_address": "34.230.134.23"
    }
}

Also, if I send post-request [url]/bot[TOKEN] by postman it returns status 200 OK.

Could You please help me understand what is wrong?

0

There are 0 best solutions below