yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.45k stars 1.53k forks source link

I uploaded my code to Heroku but it gives me an error "FatalError: EFATAL: Telegram Bot Token not provided!" #887

Closed Marcuuu closed 2 years ago

Marcuuu commented 3 years ago

I have provided the token over here.

`require('dotenv').config(); const TelegramBot = require('node-telegram-bot-api'); const moment = require('moment');

const token = process.env.TOKEN;

const bot = new TelegramBot(token, { polling: true });`

However, after deploying into Heroku, the logs tells me that I did not provide the token to the bot.

image

omega-u20 commented 3 years ago

Did you set 'Config Vars'

cnfig

or

update line

const token = process.env.TOKEN; 

as

const token = process.env.TOKEN || /*<put your token here>*/; 

In my case this worked

And also when deploying to heroku long polling method won't work as heroku dynos will shutdown when bot is inactive for some period of time

So insted of using long polling , use webhook method

See https://github.com/yagop/node-telegram-bot-api/blob/5cc6629ca02c5160424be4615b281866fb56c027/examples/webhook/heroku.js