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
|
||||
const token = '6150769224:AAGhBagPEi23QtBJl65YNuwEBBXwHguDV0E';
|
||||
|
||||
const messageIDs = [1034133487]
|
||||
|
||||
// Create a bot that uses 'polling' to fetch new updates
|
||||
const bot = new TelegramBot(token, { polling: true });
|
||||
|
||||
bot.setMyCommands([
|
||||
{ command: '/chatid', description: 'Zeigt deine Chat ID' },
|
||||
])
|
||||
|
||||
bot.on('message', (msg) => {
|
||||
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 __dirname = path.dirname(__filename);
|
||||
@@ -46,15 +73,22 @@ app.use(express.json());
|
||||
|
||||
app.post('/', async (req, res) => {
|
||||
console.log("[INFO] Received print request");
|
||||
let value = {}
|
||||
try {
|
||||
schema.validate(req.body);
|
||||
} catch (err) {
|
||||
value = await schema.validateAsync(req.body, { allowUnknown: true });
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR]", err);
|
||||
sendMessage("[ERROR] Validation Error (Drucker Service): " + err, messageIDs)
|
||||
return res.status(403).send(err);
|
||||
}
|
||||
await main(req.body).catch(
|
||||
|
||||
|
||||
await main(value).catch(
|
||||
(err) => {
|
||||
console.log(err);
|
||||
sendMessage("[ERROR] Internal Server Error (Drucker Service): " + err, messageIDs)
|
||||
|
||||
return res.status(500).send(err);
|
||||
}
|
||||
);
|
||||
@@ -1663,6 +1697,7 @@ async function main(data = testData) {
|
||||
console.log("PDF created, printing now")
|
||||
console.log(cacheFolder + data.foreign_id + ".pdf")
|
||||
await printFile(filePath, 2)
|
||||
|
||||
}
|
||||
|
||||
app.listen(2000, () => {
|
||||
|
||||
Reference in New Issue
Block a user