forked from 2pai/instastory-monitor-telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatcher.js
34 lines (31 loc) · 1.24 KB
/
dispatcher.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
require('dotenv').config()
const {
loadData,
updateData,
} = require('./util')
const TelegramBot = require('node-telegram-bot-api');
const token = process.env.TOKEN_TELEGRAM;
const bot = new TelegramBot(token);
const chatID = process.env.CHAT_ID;
const metadataStory = loadData("./metadata-story.json");
metadataStory
.map(story => {
if (story.send) return
if (story.mediaType == 1) { // Image
bot.sendPhoto(chatID, story.url)
.then((data) => {
console.log("Success send " + story.id + " to " + data.chat.title + " (" + data.chat.id + ")")
updateData("./metadata-story.json", story.id, true)
}).catch((error) => {
console.log("failed to send: " + story.id)
})
} else if (story.mediaType == 2) { // Videos
bot.sendVideo(chatID, story.url)
.then((data) => {
console.log("Success send " + story.id + " to " + data.chat.title + " (" + data.chat.id + ")")
updateData("./metadata-story.json", story.id, true)
}).catch((error) => {
console.log("failed to send: " + story.id)
})
}
})