0

I'm building a node Telegram bot using node-telegram-bot-api which is amazing so far.
However, I want to listen to messages constantly sent to my bot, so I'm using:

bot.on('message', (msg) => {
    const Hi = "hi";
    if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
        bot.sendMessage(msg.chat.id,"Hello dear user");
    } 
});

This runs but then gets to the end of the scripts and closes the node app.
Is there a way of keeping it alive without polling?

Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56
  • Have you tried configuring a server, like [express](https://expressjs.com), or using some CLI tools, like [Forever](https://github.com/foreversd/forever)? – Bandantonio Jun 04 '20 at 21:39

1 Answers1

1

First Install pm2 with this Command:

npm install pm2 -g

Then Run Your Project

pm2 start app.js // or index.js
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103