Merge branch 'telegram-fix' into 'dev'
Fix telegram notifications See merge request Shinobi-Systems/Shinobi!475node-20
commit
17f535b9ec
|
@ -10,32 +10,64 @@ module.exports = function(s,config,lang,getSnapshot){
|
||||||
const {
|
const {
|
||||||
getEventBasedRecordingUponCompletion,
|
getEventBasedRecordingUponCompletion,
|
||||||
} = require('../events/utils.js')(s,config,lang)
|
} = require('../events/utils.js')(s,config,lang)
|
||||||
|
const {
|
||||||
|
getStreamDirectory
|
||||||
|
} = require('../monitor/utils.js')(s,config,lang)
|
||||||
|
const {
|
||||||
|
ffprobe
|
||||||
|
} = require('../ffmpeg/utils.js')(s,config,lang)
|
||||||
|
|
||||||
//telegram bot
|
//telegram bot
|
||||||
if(config.telegramBot === true){
|
if(config.telegramBot === true){
|
||||||
const TelegramBot = require('node-telegram-bot-api');
|
const TelegramBot = require('node-telegram-bot-api');
|
||||||
try{
|
try{
|
||||||
const sendMessage = async function(sendBody,files,groupKey){
|
const sendMessage = async function(sendBody,attachments,groupKey){
|
||||||
var bot = s.group[groupKey].telegramBot
|
var bot = s.group[groupKey].telegramBot
|
||||||
if(!bot){
|
if(!bot){
|
||||||
s.userLog({ke:groupKey,mid:'$USER'},{type:lang.NotifyErrorText,msg:lang.DiscordNotEnabledText})
|
s.userLog({ke:groupKey,mid:'$USER'},{type:lang.NotifyErrorText,msg:lang.DiscordNotEnabledText})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const chatId = s.group[groupKey].init.telegrambot_channel
|
|
||||||
|
const sendMessageToChat = async function(chatId, files) {
|
||||||
if(bot && bot.sendMessage){
|
if(bot && bot.sendMessage){
|
||||||
try{
|
try{
|
||||||
await bot.sendMessage(chatId, `${sendBody.title}${sendBody.description ? '\n' + sendBody.description : ''}`)
|
await bot.sendMessage(chatId, `${sendBody.title}${sendBody.description ? '\n' + sendBody.description : ''}`)
|
||||||
if(files){
|
if(files){
|
||||||
files.forEach(async (file) => {
|
await Promise.all(files.map(async (file) => {
|
||||||
switch(file.type){
|
switch(file.type){
|
||||||
case'video':
|
case'video':
|
||||||
await bot.sendVideo(chatId, file.attachment)
|
if(file.hasOwnProperty("file_id") === false) {
|
||||||
|
const videoFileInfo = (await ffprobe(file.attachment,file.attachment)).result
|
||||||
|
const duration = Math.floor(videoFileInfo.streams[0].duration)
|
||||||
|
const width = videoFileInfo.streams[0].width
|
||||||
|
const height = videoFileInfo.streams[0].height
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
thumb: file.thumb,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
duration: duration,
|
||||||
|
supports_streaming: true
|
||||||
|
}
|
||||||
|
file.file_id = (await bot.sendVideo(chatId, file.attachment, options)).video.file_id
|
||||||
|
delete file.attachment
|
||||||
|
} else {
|
||||||
|
await bot.sendVideo(chatId, file.file_id)
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case'photo':
|
case'photo':
|
||||||
await bot.sendPhoto(chatId, file.attachment)
|
if(file.hasOwnProperty("file_id") === false) {
|
||||||
|
file.file_id = (await bot.sendPhoto(chatId, file.attachment)).photo[0].file_id
|
||||||
|
delete file.attachment
|
||||||
|
} else {
|
||||||
|
await bot.sendPhoto(chatId, file.file_id)
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
return file
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
return files
|
||||||
}catch(err){
|
}catch(err){
|
||||||
s.debugLog('Telegram Error',err)
|
s.debugLog('Telegram Error',err)
|
||||||
s.userLog({ke:groupKey,mid:'$USER'},{type:lang.NotifyErrorText,msg:err})
|
s.userLog({ke:groupKey,mid:'$USER'},{type:lang.NotifyErrorText,msg:err})
|
||||||
|
@ -50,6 +82,15 @@ module.exports = function(s,config,lang,getSnapshot){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chatIds = s.group[groupKey].init.telegrambot_channel.split(",")
|
||||||
|
const resolvedFiles = await sendMessageToChat(chatIds[0], attachments)
|
||||||
|
|
||||||
|
chatIds.forEach((chatId, index) => {
|
||||||
|
if(index < 1) return
|
||||||
|
sendMessageToChat(chatId, resolvedFiles)
|
||||||
|
});
|
||||||
|
}
|
||||||
const onEventTriggerBeforeFilterForTelegram = function(d,filter){
|
const onEventTriggerBeforeFilterForTelegram = function(d,filter){
|
||||||
filter.telegram = false
|
filter.telegram = false
|
||||||
}
|
}
|
||||||
|
@ -98,13 +139,16 @@ module.exports = function(s,config,lang,getSnapshot){
|
||||||
videoName = siftedVideoFileFromRam.filename
|
videoName = siftedVideoFileFromRam.filename
|
||||||
}
|
}
|
||||||
if(videoPath){
|
if(videoPath){
|
||||||
|
const thumbFile = getStreamDirectory(d) + 'thumb.jpg';
|
||||||
|
fs.writeFileSync(thumbFile, d.screenshotBuffer)
|
||||||
sendMessage({
|
sendMessage({
|
||||||
title: videoName,
|
title: videoName,
|
||||||
},[
|
},[
|
||||||
{
|
{
|
||||||
type: 'video',
|
type: 'video',
|
||||||
attachment: videoPath,
|
attachment: videoPath,
|
||||||
name: videoName
|
name: videoName,
|
||||||
|
thumb: thumbFile
|
||||||
}
|
}
|
||||||
],d.ke)
|
],d.ke)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"node-onvif-events": "^2.0.5",
|
"node-onvif-events": "^2.0.5",
|
||||||
"node-ssh": "^12.0.4",
|
"node-ssh": "^12.0.4",
|
||||||
"node-telegram-bot-api": "^0.58.0",
|
"node-telegram-bot-api": "^0.61.0",
|
||||||
"nodemailer": "^6.7.1",
|
"nodemailer": "^6.7.1",
|
||||||
"pam-diff": "^1.1.0",
|
"pam-diff": "^1.1.0",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
@ -5384,15 +5384,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/node-telegram-bot-api": {
|
"node_modules/node-telegram-bot-api": {
|
||||||
"version": "0.58.0",
|
"version": "0.61.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-telegram-bot-api/-/node-telegram-bot-api-0.58.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-telegram-bot-api/-/node-telegram-bot-api-0.61.0.tgz",
|
||||||
"integrity": "sha512-DmP5wBON9stOiunvUw/NvTb1clMYvj+c3NnSqbPZdVd6hNkNRnM97eqPZIH4UsBJ+4n+XFGpU33dCzjqD1sv3A==",
|
"integrity": "sha512-BZXd8Bh2C5+uBEQuuI3FD7TFJF3alV+6oFQt8CNLx3ldX/hsd+NYyllTX+Y+5X0tG+xtcRQQjbfLgz/4sRvmBQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"array.prototype.findindex": "^2.0.2",
|
"array.prototype.findindex": "^2.0.2",
|
||||||
"bl": "^1.2.3",
|
"bl": "^1.2.3",
|
||||||
"bluebird": "^3.5.1",
|
"debug": "^3.2.7",
|
||||||
"debug": "^3.1.0",
|
|
||||||
"depd": "^1.1.1",
|
|
||||||
"eventemitter3": "^3.0.0",
|
"eventemitter3": "^3.0.0",
|
||||||
"file-type": "^3.9.0",
|
"file-type": "^3.9.0",
|
||||||
"mime": "^1.6.0",
|
"mime": "^1.6.0",
|
||||||
|
@ -12050,15 +12048,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node-telegram-bot-api": {
|
"node-telegram-bot-api": {
|
||||||
"version": "0.58.0",
|
"version": "0.61.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-telegram-bot-api/-/node-telegram-bot-api-0.58.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-telegram-bot-api/-/node-telegram-bot-api-0.61.0.tgz",
|
||||||
"integrity": "sha512-DmP5wBON9stOiunvUw/NvTb1clMYvj+c3NnSqbPZdVd6hNkNRnM97eqPZIH4UsBJ+4n+XFGpU33dCzjqD1sv3A==",
|
"integrity": "sha512-BZXd8Bh2C5+uBEQuuI3FD7TFJF3alV+6oFQt8CNLx3ldX/hsd+NYyllTX+Y+5X0tG+xtcRQQjbfLgz/4sRvmBQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"array.prototype.findindex": "^2.0.2",
|
"array.prototype.findindex": "^2.0.2",
|
||||||
"bl": "^1.2.3",
|
"bl": "^1.2.3",
|
||||||
"bluebird": "^3.5.1",
|
"debug": "^3.2.7",
|
||||||
"debug": "^3.1.0",
|
|
||||||
"depd": "^1.1.1",
|
|
||||||
"eventemitter3": "^3.0.0",
|
"eventemitter3": "^3.0.0",
|
||||||
"file-type": "^3.9.0",
|
"file-type": "^3.9.0",
|
||||||
"mime": "^1.6.0",
|
"mime": "^1.6.0",
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"node-onvif-events": "^2.0.5",
|
"node-onvif-events": "^2.0.5",
|
||||||
"node-ssh": "^12.0.4",
|
"node-ssh": "^12.0.4",
|
||||||
"node-telegram-bot-api": "^0.58.0",
|
"node-telegram-bot-api": "^0.61.0",
|
||||||
"nodemailer": "^6.7.1",
|
"nodemailer": "^6.7.1",
|
||||||
"pam-diff": "^1.1.0",
|
"pam-diff": "^1.1.0",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
|
Loading…
Reference in New Issue