Skip to content

Commit

Permalink
feat: run bot if launched from file
Browse files Browse the repository at this point in the history
  • Loading branch information
ilbertt committed Jul 23, 2021
1 parent 366525f commit 9e9b084
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,25 @@ bot.on('text', async (ctx) => {
return await ctx.replyWithMarkdown(message);
});

bot.catch((err, ctx) => {
return ctx.reply(`Ooops, encountered an error for ${ctx.updateType}`, err);
});

// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));

module.exports.setBotToken = (token) => {
const setBotToken = (token) => {
bot.telegram.token = token;
};

if (require.main === module) {
const dotenv = require('dotenv');
dotenv.config();

setBotToken(process.env.BOT_TOKEN);
bot.launch();
}

module.exports.setBotToken = setBotToken;
module.exports.infiniteCloudBot = bot;
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "MIT",
"private": false,
"dependencies": {
"dotenv": "^10.0.0",
"node-fetch": "^2.6.1",
"request": "^2.88.2",
"telegraf": "^4.3.0",
Expand Down

0 comments on commit 9e9b084

Please sign in to comment.