From 29dcec2810c30bf6335b1508a234d7570c111291 Mon Sep 17 00:00:00 2001 From: Moe Date: Fri, 25 Aug 2023 21:27:59 -0700 Subject: [PATCH] better notifications for telegram, matrix, and pushover --- libs/notifications/matrix.js | 9 ++++++--- libs/notifications/pushover.js | 12 +++++++----- libs/notifications/telegram.js | 10 ++++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libs/notifications/matrix.js b/libs/notifications/matrix.js index 81e23cd7..9222c6d0 100644 --- a/libs/notifications/matrix.js +++ b/libs/notifications/matrix.js @@ -2,6 +2,7 @@ const fs = require("fs") const fetch = require("node-fetch") module.exports = function(s,config,lang,getSnapshot){ const { + getObjectTagNotifyText, getEventBasedRecordingUponCompletion, } = require('../events/utils.js')(s,config,lang) //matrix bot @@ -76,6 +77,7 @@ module.exports = function(s,config,lang,getSnapshot){ // d = event object const isEnabled = filter.matrixBot || monitorConfig.details.detector_matrixbot === '1' || monitorConfig.details.notify_matrix === '1' if(s.group[d.ke].matrixBot && isEnabled && !s.group[d.ke].activeMonitors[d.id].detector_matrixbot){ + const notifyText = getObjectTagNotifyText(d) var detector_matrixbot_timeout if(!monitorConfig.details.detector_matrixbot_timeout||monitorConfig.details.detector_matrixbot_timeout===''){ detector_matrixbot_timeout = 1000 * 60 * 10; @@ -88,9 +90,8 @@ module.exports = function(s,config,lang,getSnapshot){ },detector_matrixbot_timeout) await getSnapshot(d,monitorConfig) if(d.screenshotBuffer){ - const imageEventText = `${lang.Event} ${d.screenshotName} ${d.currentTimestamp}` sendMessage({ - text: imageEventText, + text: notifyText, },[ { buffer: d.screenshotBuffer, @@ -119,7 +120,9 @@ module.exports = function(s,config,lang,getSnapshot){ videoName = siftedVideoFileFromRam.filename } if(videoPath){ - sendMessage({},[ + sendMessage({ + text: notifyText, + },[ { buffer: await fs.promises.readFile(videoPath), name: videoName, diff --git a/libs/notifications/pushover.js b/libs/notifications/pushover.js index e2ac79af..590752f3 100644 --- a/libs/notifications/pushover.js +++ b/libs/notifications/pushover.js @@ -1,7 +1,9 @@ var fs = require('fs'); module.exports = function (s, config, lang, getSnapshot) { - const { getEventBasedRecordingUponCompletion } = - require('../events/utils.js')(s, config, lang); + const { + getObjectTagNotifyText, + getEventBasedRecordingUponCompletion, + } = require('../events/utils.js')(s,config,lang) if (config.pushover === true) { const Pushover = require('pushover-notifications'); @@ -116,6 +118,7 @@ module.exports = function (s, config, lang, getSnapshot) { (filter.pushover || monitorConfig.details.notify_pushover === '1') && !s.group[d.ke].activeMonitors[d.id].detector_pushover ) { + const notifyText = getObjectTagNotifyText(d) var detector_pushover_timeout; if ( !monitorConfig.details.detector_pushover_timeout || @@ -144,9 +147,8 @@ module.exports = function (s, config, lang, getSnapshot) { if (d.screenshotBuffer) { sendMessage( { - title: lang.Event + ' - ' + d.screenshotName, - description: - lang.EventText1 + ' ' + d.currentTimestamp, + title: notifyText, + description: lang.EventText1 + ' ' + d.currentTimestamp, }, [ { diff --git a/libs/notifications/telegram.js b/libs/notifications/telegram.js index 2a842262..466dc5f7 100644 --- a/libs/notifications/telegram.js +++ b/libs/notifications/telegram.js @@ -8,6 +8,7 @@ var fs = require("fs") // } module.exports = function(s,config,lang,getSnapshot){ const { + getObjectTagNotifyText, getEventBasedRecordingUponCompletion, } = require('../events/utils.js')(s,config,lang) const { @@ -99,6 +100,7 @@ module.exports = function(s,config,lang,getSnapshot){ // d = event object //telegram bot if(s.group[d.ke].telegramBot && (filter.telegram || monitorConfig.details.notify_telegram === '1') && !s.group[d.ke].activeMonitors[d.id].detector_telegrambot){ + const notifyText = getObjectTagNotifyText(d) var detector_telegrambot_timeout if(!monitorConfig.details.detector_telegrambot_timeout||monitorConfig.details.detector_telegrambot_timeout===''){ detector_telegrambot_timeout = 1000 * 60 * 10; @@ -112,13 +114,13 @@ module.exports = function(s,config,lang,getSnapshot){ await getSnapshot(d,monitorConfig) if(d.screenshotBuffer){ sendMessage({ - title: lang.Event+' - '+d.screenshotName, + title: notifyText, description: lang.EventText1+' '+d.currentTimestamp, },[ { type: 'photo', attachment: d.screenshotBuffer, - name: d.screenshotName+'.jpg' + name: notifyText + '.jpg' } ],d.ke) } @@ -142,12 +144,12 @@ module.exports = function(s,config,lang,getSnapshot){ const thumbFile = getStreamDirectory(d) + 'thumb.jpg'; fs.writeFileSync(thumbFile, d.screenshotBuffer) sendMessage({ - title: videoName, + title: notifyText, },[ { type: 'video', attachment: videoPath, - name: videoName, + name: notifyText + '.mp4', thumb: thumbFile } ],d.ke)