Hi!
I try to set up Telegram webhook.
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);
});
I checked the status 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"
}
}
Could You please help me understand what is wrong?
1 Like
Yonle
May 10, 2021, 11:46pm
2
Seems like glitch is blocking to non-User-agent
Request, So it caused a error like this.
1 Like
Can you show us what you POSTed to telegram?
I sent webhook to TG → bot.setWebHook([url]/bot${process.env.TG_BOT_TOKEN}
);
then type message in chat with bot like → “/start”
TG sends respond to [url]/bot${process.env.TG_BOT_TOKEN} which is rejected by glitch.com
I found out that TG sends this:
{
update_id: 619208564,
message: {
message_id: 1353,
from: {
id: 70964655,
is_bot: false,
first_name: ‘Jeff’,
username: ‘[TGname]’,
language_code: ‘en’
},
chat: {
id: -567510185,
title: ‘[botname]’,
type: ‘group’,
all_members_are_administrators: true
},
date: 1620723557,
text: ‘/start’,
entities: [ [Object] ]
}
}
1 Like
wh0
May 11, 2021, 5:47pm
5
Could you try receiving a webhook somewhere other than Glitch and check if Telegram sets a User-Agent header?
1 Like
Yonle
May 13, 2021, 1:18am
6
It would work. Maybe Telegram didn’t have User-agent
header, So the result is 403 due to ping block
system
Closed
November 9, 2021, 1:19am
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.