-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (30 loc) · 981 Bytes
/
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
import 'dotenv/config';
import express from 'express';
import bot from './bot.js';
const app = express();
app.get('/:chatId', async (req, res) => {
const { chatId } = req.params;
const paramList = req.query;
try {
if (Object.keys(paramList).length < 1) {
throw new Error('no parameters');
}
// consruction telegram message
// from query list
let message = '🎉 <b>NEW LEAD</b>\n\n';
for (const [paramName, paramValue] of Object.entries(paramList)) {
message += `<b>${paramName}</b>: ${paramValue}\n`;
}
// send message to telegram
await bot.sendMessage(chatId, message, {
parse_mode: 'HTML',
});
res.status(200).json({ status: true });
} catch (error) {
res.status(500).json({ status: false, error: error.message });
}
});
function startServer() {
return app.listen(process.env.PORT);
}
export default startServer;