-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (37 loc) · 1.21 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require('dotenv').config()
var express = require('express')
var app = express()
const bodyParser = require('body-parser');
const Handler = require("./classes/Handler");
const secret = process.env.SECRET; //put your secret here
const token = process.env.TOKEN; //put your bot token here
app.use(bodyParser.json());
app.post('/webhook/:secret', function(req, res) {
console.log("Got update");
if(secret === req.params.secret) {
res.send("Ok");
var TelegramBotClient = require('telegram-bot-client');
var client = new TelegramBotClient(token);
var update = new Handler(req.body);
//Update Handling
if (typeof update.msg !== 'undefined') {
const args = update.msg.split(" ");
var command = args[0]
}
if (typeof update.cbdata !== 'undefined') {
console.log(update)
var command = "cb:"+update.cbdata; //so that commands do not get handled as cbdata
}
try {
let commandFile = require(`./commands/${command}.js`);
commandFile.run(update, client);
} catch (err) {
console.log(err);
}
} else {
res.send("Nah");
}
})
const listener = app.listen(process.env.PORT, function() {
console.log('Listening on ' + listener.address().port);
});