为什么 Node js 电报机器人放置在 Heroku 上并给出 403 答案

问题描述 投票:0回答:2

我编写电报机器人并使用 Telegraf 库。 我把我的机器人放在 Heroku 上。 我这样设置网络钩子:

app.telegram.setWebhook(`${URL}/bot${BOT_TOKEN}`);
app.startWebhook(`/bot${BOT_TOKEN}`, null, PORT);

但是在 Heroku 日志中我看到

at=info method=POST path="/bot" host=my-app.herokuapp.com request_id=a8f99998-5e9b-4fe4-9af6-9ac56e492ae3 fwd="149.154.167.206" dyno=web.1 connect=3ms service=4ms status=403 bytes=101 protocol=https

getWebhookInfo() 也会记录

last_error_message: 'Wrong response from the webhook: 403 Forbidden
。 使用邮递员尝试来自 telegram webhook 指南的测试示例也会返回 403

解决方案:我通过在我的脚本中添加 Express 来解决这个问题,就像这个示例

node.js heroku telegram-bot telegraf telegram-webhook
2个回答
0
投票

如果您的机器人无法访问他想要访问的内容,则通常会发生

403 forbidden
错误代码。例如,您使用
user_id
而不是 chat_id 调用 sendmessage 函数,或者您的机器人无权访问聊天(被踢/禁止)。

由于您的代码有点少,我的答案可能不是 100% 准确。

编辑:这是错误的官方电报错误文档的链接。也许这会对您有额外的帮助。


0
投票

我面临着同样的问题:如果您正确设置了其他所有内容,我认为这是更相关的答案:Telegram 403 Error

© www.soinside.com 2019 - 2024. All rights reserved.