-
Notifications
You must be signed in to change notification settings - Fork 6
/
telegram.js
44 lines (39 loc) · 1.28 KB
/
telegram.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
require('dotenv').config()
core = require('@actions/core');
const TelegramBot = require('node-telegram-bot-api');
const token = process.env.TG_API;
const UID = process.env.TG_UID;
const bot = new TelegramBot(token, { polling: true });
bot.on('message', async (msg) => {
const chatId = msg.chat.id;
if (!UID || UID != chatId) {
bot.sendMessage(chatId, `UID: ${chatId}`);
}
});
async function sendImg(image,id) {
console.log("Trying to send a card to Telegram");
try {
if (hideId == "All" || hideId == "Message") caption = ""
else caption = `ID: ${id}`
await bot.sendPhoto(UID,image,{caption: caption})
} catch (error) {
console.log(error);
core.setFailed('Error sending file!');
return false
}
return true
// A new method of sending files (for a future update)
var buffer = bufferFile(image);
fileOptions = {
filename: image.split("/")[-1],
contentType: "image/png"
}
// await bot.sendPhoto(UID,buffer,{caption: `ID: ${id}`},fileOptions)
await bot.sendPhoto(UID,buffer,{},fileOptions)
}
function bufferFile(relPath) {
var fs = require('fs');
var path = require('path');
return fs.readFileSync(path.join(__dirname, relPath));
}
module.exports.sendImg = sendImg;