feat(main): telegram
This commit is contained in:
43
index.js
43
index.js
@@ -11,14 +11,41 @@ import TelegramBot from 'node-telegram-bot-api';
|
|||||||
// replace the value below with the Telegram token you receive from @BotFather
|
// replace the value below with the Telegram token you receive from @BotFather
|
||||||
const token = '6150769224:AAGhBagPEi23QtBJl65YNuwEBBXwHguDV0E';
|
const token = '6150769224:AAGhBagPEi23QtBJl65YNuwEBBXwHguDV0E';
|
||||||
|
|
||||||
|
const messageIDs = [1034133487]
|
||||||
|
|
||||||
// Create a bot that uses 'polling' to fetch new updates
|
// Create a bot that uses 'polling' to fetch new updates
|
||||||
const bot = new TelegramBot(token, { polling: true });
|
const bot = new TelegramBot(token, { polling: true });
|
||||||
|
|
||||||
|
bot.setMyCommands([
|
||||||
|
{ command: '/chatid', description: 'Zeigt deine Chat ID' },
|
||||||
|
])
|
||||||
|
|
||||||
bot.on('message', (msg) => {
|
bot.on('message', (msg) => {
|
||||||
const chatId = msg.chat.id;
|
const chatId = msg.chat.id;
|
||||||
msg.reply_to_message("Your Chat ID is: " + chatId);
|
|
||||||
|
switch (msg.text) {
|
||||||
|
case '/chatid':
|
||||||
|
bot.sendMessage(chatId, 'Deine Chat ID ist: ' + chatId);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function sendMessage(msg, idList) {
|
||||||
|
idList.forEach((id) => {
|
||||||
|
bot.sendMessage(id, msg);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// setInterval(() => {
|
||||||
|
// messageIDs.forEach((id) => {
|
||||||
|
// bot.set(id, new Date().toLocaleString());
|
||||||
|
// })
|
||||||
|
// }, 3 * 60 * 1000)
|
||||||
|
|
||||||
|
sendMessage("[INFO]: Drucker Service wird gestartet", messageIDs)
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
@@ -46,15 +73,22 @@ app.use(express.json());
|
|||||||
|
|
||||||
app.post('/', async (req, res) => {
|
app.post('/', async (req, res) => {
|
||||||
console.log("[INFO] Received print request");
|
console.log("[INFO] Received print request");
|
||||||
|
let value = {}
|
||||||
try {
|
try {
|
||||||
schema.validate(req.body);
|
value = await schema.validateAsync(req.body, { allowUnknown: true });
|
||||||
} catch (err) {
|
}
|
||||||
|
catch (err) {
|
||||||
console.log("[ERROR]", err);
|
console.log("[ERROR]", err);
|
||||||
|
sendMessage("[ERROR] Validation Error (Drucker Service): " + err, messageIDs)
|
||||||
return res.status(403).send(err);
|
return res.status(403).send(err);
|
||||||
}
|
}
|
||||||
await main(req.body).catch(
|
|
||||||
|
|
||||||
|
await main(value).catch(
|
||||||
(err) => {
|
(err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
sendMessage("[ERROR] Internal Server Error (Drucker Service): " + err, messageIDs)
|
||||||
|
|
||||||
return res.status(500).send(err);
|
return res.status(500).send(err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -1663,6 +1697,7 @@ async function main(data = testData) {
|
|||||||
console.log("PDF created, printing now")
|
console.log("PDF created, printing now")
|
||||||
console.log(cacheFolder + data.foreign_id + ".pdf")
|
console.log(cacheFolder + data.foreign_id + ".pdf")
|
||||||
await printFile(filePath, 2)
|
await printFile(filePath, 2)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.listen(2000, () => {
|
app.listen(2000, () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user