Skip to content

Commit

Permalink
# First fucntional mockup
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenam committed Feb 8, 2019
1 parent 7b6f1d7 commit 0d3b549
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ npm-debug.log
.env
.DS_Storepack
package-lock.json
config.json
config.json
userj.json
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
},
"homepage": "https://github.com/tttest25/node_telegram#readme",
"dependencies": {
"express": "^4.16.4"
"express": "^4.16.4",
"telegraf": "^3.26.0"
},
"devDependencies": {
"nodemon": "^1.18.9"
},
"nodemonConfig": {
"ignore": ["test/*", "docs/*"],
"ignore": [
"test/*",
"docs/*",
"users.json"
],
"delay": "2500"
}
}
41 changes: 36 additions & 5 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const session = require('telegraf/session')
const Markup = require('telegraf/markup')
const { reply } = Telegraf


const configObj = require('../config.json');

const environment = process.env.NODE_ENV || 'development';
Expand All @@ -26,7 +25,13 @@ global.gConfig = finalConfig;
console.log(`global.gConfig: ${JSON.stringify(global.gConfig, undefined, global.gConfig.json_indentation)}`);


const util = require('./helpers/util');
const dataService = require('./helpers/dataService');

dataService.loadUsers();

const bot = new Telegraf(process.env.BOT_TOKEN || global.gConfig.bot_token )
util.setBot(bot);

// // Register session middleware
bot.use(session())
Expand All @@ -44,11 +49,26 @@ bot.catch((err) => {
console.error('Error', err)
})


bot.start((ctx) => ctx.reply('Welcome'))
bot.command('start', ctx => {
util.logMsg(ctx);
dataService.registerUser(ctx);
//dataService.setCounter(ctx.chat.id, '0', 0);
var m = "Hello, I'm your AGP bot, please ask admin to add you to group";
ctx.reply(m);
util.logOutMsg(ctx, m);
setTimeout(() => {
ctx.reply(0);
util.logOutMsg(ctx, 0)
}, 50); //workaround to send this message definitely as second message
});
//bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on('sticker', (ctx) => ctx.reply('👍'))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
bot.hears('hi', (ctx) => ctx.reply('Hey there!'))
bot.hears('log', (ctx) => {
ctx.reply('See log!');
util.logMsg(ctx);
})
bot.launch()


Expand All @@ -60,8 +80,19 @@ const HOST = global.gConfig.host;
const app = express();
app.get('/', (req, res) => {
res.send('Hello 4 world\n');
util.sendToAdmin('test send to admin');
});


process.on('unhandledRejection', (e) => {
console.log(e);
// sendToAdmin(`Unhandled Rejection! ${e.message}`);
});

process.on('uncaughtException', (e) => {
console.log(e);
// sendToAdmin(`Uncaught Exception! ${e.message}`);
});

app.listen(PORT, HOST);
console.log(`Running 3 on http://${HOST}:${PORT}`);
console.log(`-> Running 3 on http://${HOST}:${PORT}`);

0 comments on commit 0d3b549

Please sign in to comment.