0

I write telegram bot and use Telegraf library. I placed my bot on Heroku. I set up webhooks this way:

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

But in Heroku logs I see 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() also log last_error_message: 'Wrong response from the webhook: 403 Forbidden. Trying test example from telegram webhook guide with postman also return 403

SOLUTION: I solved it by addition Express to my script like in this example

ada
  • 666
  • 6
  • 11

1 Answers1

0

The 403 forbidden error code mostly happens if your bot has no access to what he´s trying to reach. An example could be that you called the sendmessage function with a user_id and not a chat_id or that your bot has no access to the chat (kicked/ banned).

As you were a little short on code, my answer could turn out to be not 100% accurate.

Edit: Here is a link to the official telegram error documentation of the error. Maybe that could be of additional help for you.

creyD
  • 1,972
  • 3
  • 26
  • 55
  • I use chat_id everywhere. And with polling (locally) my bot works. Also it's not completely clear for me - I think error from the side when telegram try to send me json, not when I try to write to user... – ada May 23 '17 at 08:38
  • Did you ever try to host your script on another website then your heroku site? Alternatively take a look [here](https://en.wikipedia.org/wiki/HTTP_403) – creyD May 23 '17 at 08:51
  • So it is the heroku configuration which causes the error. As I suppose that you can´t change that config, you need to find yourself another host I guess. – creyD May 23 '17 at 10:48
  • @AdaraHv Did you try to use another server/ host? – creyD May 24 '17 at 11:39
  • I've aready updated my question: "solved it by addition Express to my script" – ada May 25 '17 at 12:01