-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (40 loc) · 1.5 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
41
42
43
44
45
46
47
// Some beutiful explanations are in /utils/worker.js
const express = require('express');
const axios = require('axios');
const worker = require('./utils/worker');
const url = 'https://api.telegram.org/bot';
const apiToken = '<your token>';
const app = express();
app.use(express.json());
const sendMessage = (res, chatId, message) => {
axios.post(`${url}${apiToken}/sendMessage`,
{
chat_id: chatId,
text: message
}
).then((response) => {
res.status(200).json(response);
}).catch((error) => {
res.send(error);
});
}
app.post('/', (req, res) => {
const chatId = req.body.message.chat.id;
let message = req.body.message.text;
if (message === '/start' | message === '/help') {
sendMessage(res, chatId, 'Usage:\n/absenin username password\n\nNOTE: Untuk alasan keamanan, username dan password tidak akan disimpan pada database.');
} else if (message.search('/absenin') !== -1) {
message = message.split(' ');
if (message.length !== 3) {
sendMessage(res, chatId, 'Isi username sama passwordnya goblok!');
} else {
sendMessage(res, chatId, 'Mencoba Login...');
worker.getActivites(res, chatId, message[1], message[2]);
}
} else {
sendMessage(res, chatId, 'Perintah tidak ditemukan!\nGunakan perintah /absenin untuk absen.\nContoh: /absenin 1029383928 inipassword90');
}
});
app.listen(8080, () => {
console.log('App listening on port 8080');
});