My telegram bot working perfectly on local machine but when I deploy it to heroku it become unresponsive and dynos are also set to npm start even when I declared start script in package.json.Here is the log file:-
2022-06-04T15:45:02.232005+00:00 app[web.1]: at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:547:31) 2022-06-04T15:45:02.232006+00:00 app[web.1]: at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:604:18) 2022-06-04T15:45:02.232006+00:00 app[web.1]: at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:649:10) 2022-06-04T15:45:02.232006+00:00 app[web.1]: at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:729:18) 2022-06-04T15:45:02.232006+00:00 app[web.1]: at _drainQueueStep (/app/node_modules/bluebird/js/release/async.js:93:12) 2022-06-04T15:45:02.232007+00:00 app[web.1]: at _drainQueue (/app/node_modules/bluebird/js/release/async.js:86:9) 2022-06-04T15:45:02.232007+00:00 app[web.1]: at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:102:5) 2022-06-04T15:45:02.232008+00:00 app[web.1]: at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/bluebird/js/release/async.js:15:14) 2022-06-04T15:45:02.232011+00:00 app[web.1]: at processImmediate (node:internal/timers:466:21) 2022-06-04T15:45:02.521059+00:00 heroku[web.1]: State changed from starting to up
edit- The code is shared below, I followed a tutorial to make my own telegram bot
const TelegramBot = require('node-telegram-bot-api');
const axios = require('axios');
// This file would be created soon
require('dotenv').config();
const token = "token is here";
let bot;
if (process.env.NODE_ENV === 'production') {
bot = new TelegramBot(token);
bot.setWebHook(process.env.HEROKU_URL + bot.token);
} else {
bot = new TelegramBot(token, { polling: true });
}
bot.onText(/\/word (.+)/, (msg, match) => {
const chatId = msg.chat.id;
const word = match[1];
bot.sendMessage(chatId, "NO");
});
const express = require('express')
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.listen(process.env.PORT);
app.post('/' + bot.token, (req, res) => {
bot.processUpdate(req.body);
res.sendStatus(200);
});