forked from codefresh-contrib/telegram-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (27 loc) · 883 Bytes
/
index.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
const BotController = require('./bot/bot.controller');
const config = require('./config');
const userEnv = {
images: process.env.TELEGRAM_IMAGES,
text: process.env.TELEGRAM_MESSAGE,
onlyStatus: !!process.env.TELEGRAM_STATUS,
};
const botController = new BotController(config.accessToken);
const main = async () => {
config.to.split(',')
.map(async uid => {
if (userEnv.onlyStatus) {
await botController.sendStatus(uid);
}
else {
await botController.sendTemplateMessage(uid, userEnv.text, {
...(userEnv.images ? { images: userEnv.images.split(',') } : {}),
});
}
});
};
main()
.then(() => console.log('message successfully sanded'))
.catch(e => {
console.log(e);
})
.finally(() => botController.stopBot());