yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.3k stars 1.5k forks source link

I cannot run the bot on Heroku #991

Closed OmegaM1 closed 2 years ago

OmegaM1 commented 2 years ago

Hi, I have setup my bot on Heroku by using heroku-node-telegram-bot code examples but I am getting below error

 heroku-node-telegram-bot@1.0.3 start
 node index.js

/app/bot.js:7
  bot = new Bot(token);
        ^

TypeError: TelegramBot is not a constructor
    at Object.<anonymous> (/app/bot.js:7:9)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/index.js:1:11)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

Process exited

Is there a way to fix it?

Drakoniwe commented 2 years ago

Add const before "bot"

// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});
OmegaM1 commented 2 years ago

@Drakoniwe Thank you, the pervious problem has been solved But I am receiving a new error which the logs telling that my bot token is not defined

> heroku-node-telegram-bot@1.0.3 start
> node index.js

node-telegram-bot-api deprecated Automatic enabling of cancellation of promises is deprecated.
In the future, you will have to enable it yourself.
See https://github.com/yagop/node-telegram-bot-api/issues/319. node:internal/modules/cjs/loader:1105:14
Bot server started in the production mode
/app/web.js:20
  app.post('/' + bot.token, (req, res) => {
                     ^

TypeError: Cannot read properties of undefined (reading 'token')
    at module.exports (/app/web.js:20:22)
    at Object.<anonymous> (/app/index.js:2:17)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

Process exited

I have already defined my Heroku URL with the bot token so what's the problem

OmegaM1 commented 2 years ago

I found the problem which it was my code I edited "bot.token" to "token" (String variable) and it worked.