Add language notifications; Add power door handel
This commit is contained in:
parent
d97d90cf95
commit
0876e73c68
12 changed files with 445 additions and 581 deletions
|
|
@ -7,7 +7,7 @@ exports.output = 1;
|
|||
exports.author = 'Jakub Klena';
|
||||
exports.icon = 'plug';
|
||||
exports.version = '1.0.8';
|
||||
exports.options = { 'name':'', 'types': '["emergency", "critical", "error", "alert"]', 'message_includes':'["is responding again"]', 'tag_on_include':'[{"user_id":"U072JE5JUQG", "includes":["Electrometer", "Twilight sensor"]}]', 'slack_channel':'' };
|
||||
exports.options = { 'name': '', 'types': '["emergency", "critical", "error", "alert"]', 'message_includes': '["is responding again"]', 'tag_on_include': '[{"user_id":"U072JE5JUQG", "includes":["Electrometer", "Twilight sensor"]}]', 'slack_channel': '' };
|
||||
|
||||
exports.html = `<div class="padding">
|
||||
<div class="row">
|
||||
|
|
@ -37,7 +37,7 @@ exports.install = function(instance) {
|
|||
if (!running) return;
|
||||
let value = response.data;
|
||||
if (typeof value !== 'object') return;
|
||||
|
||||
|
||||
let can = false
|
||||
var k = Object.keys(value);
|
||||
var interested = JSON.parse(instance.options.types);
|
||||
|
|
@ -57,11 +57,11 @@ exports.install = function(instance) {
|
|||
let icon = ':totaljs:';
|
||||
let type = value[k[0]][0]['values']['_event']['type'];
|
||||
let source = value[k[0]][0]['values']['_event']['source']['func'];
|
||||
let message = value[k[0]][0]['values']['_event']['message'];
|
||||
let message = value[k[0]][0]['values']['_event']['message']['en'];
|
||||
let message_data = value[k[0]][0]['values']['_event']['message_data'];
|
||||
let tag = '';
|
||||
|
||||
switch(type){
|
||||
switch (type) {
|
||||
case 'debug':
|
||||
icon = ':beetle:';
|
||||
break;
|
||||
|
|
@ -89,15 +89,15 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
// Check if this message includes one of the strings we are watching for
|
||||
for (const msg of msg_incl){
|
||||
if (message.includes(msg)){
|
||||
for (const msg of msg_incl) {
|
||||
if (message.includes(msg)) {
|
||||
if (msg == 'is responding again') icon = ':large_green_circle:';
|
||||
can = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Check if message is one of the types we are watching for
|
||||
if (interested.includes(type)){
|
||||
if (interested.includes(type)) {
|
||||
can = true;
|
||||
}
|
||||
|
||||
|
|
@ -105,10 +105,10 @@ exports.install = function(instance) {
|
|||
|
||||
|
||||
// Check for each person tags based on what the message includes
|
||||
for (const person of tags){
|
||||
for (const msg of person.includes){
|
||||
if (message.includes(msg)){
|
||||
tag += '<@'+person.user_id+'> ';
|
||||
for (const person of tags) {
|
||||
for (const msg of person.includes) {
|
||||
if (message.includes(msg)) {
|
||||
tag += '<@' + person.user_id + '> ';
|
||||
break; // Break out from this person checks as they are already tagged now
|
||||
}
|
||||
}
|
||||
|
|
@ -116,46 +116,46 @@ exports.install = function(instance) {
|
|||
// Now that all people are tagged add new line symbol
|
||||
if (tag != '') tag += '\n';
|
||||
|
||||
let send_data = tag+instance.options.name+' '+type.toUpperCase()+'\n*Source*: '+source+'\n*Message*: '+message;
|
||||
let send_data = tag + instance.options.name + ' ' + type.toUpperCase() + '\n*Source*: ' + source + '\n*Message*: ' + message;
|
||||
if (message_data) {
|
||||
send_data += '\nData: '+message_data;
|
||||
send_data += '\nData: ' + message_data;
|
||||
}
|
||||
|
||||
let ignore_msg = false
|
||||
if (message.includes('Configuration of dimming profile to node no')){
|
||||
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++){
|
||||
if (FLOW["savedSlackMessages"][i].message == message){
|
||||
if (message.includes('Configuration of dimming profile to node no')) {
|
||||
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++) {
|
||||
if (FLOW["savedSlackMessages"][i].message == message) {
|
||||
ignore_msg = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ignore_msg){
|
||||
FLOW["savedSlackMessages"].push({message, 'dateandtime': Date.now()});
|
||||
if (timer === null){
|
||||
timer = setTimeout(checkSavedMessages, 60*60000);
|
||||
if (!ignore_msg) {
|
||||
FLOW["savedSlackMessages"].push({ message, 'dateandtime': Date.now() });
|
||||
if (timer === null) {
|
||||
timer = setTimeout(checkSavedMessages, 60 * 60000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignore_msg){
|
||||
instance.send2({'msg':send_data,'bot_name':instance.options.name+' '+type.toUpperCase(),'bot_icon':icon,'channel':instance.options.slack_channel});
|
||||
if (!ignore_msg) {
|
||||
instance.send2({ 'msg': send_data, 'bot_name': instance.options.name + ' ' + type.toUpperCase(), 'bot_icon': icon, 'channel': instance.options.slack_channel });
|
||||
}
|
||||
});
|
||||
|
||||
function checkSavedMessages(){
|
||||
function checkSavedMessages() {
|
||||
var d = Date.now();
|
||||
d = d - 86400000; // older then 24hr
|
||||
var a = [];
|
||||
//Remove msgs older then 24hr
|
||||
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++){
|
||||
if (FLOW["savedSlackMessages"][i].dateandtime > d){
|
||||
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++) {
|
||||
if (FLOW["savedSlackMessages"][i].dateandtime > d) {
|
||||
a.push(FLOW["savedSlackMessages"][i]);
|
||||
}
|
||||
}
|
||||
FLOW["savedSlackMessages"] = a;
|
||||
|
||||
if (FLOW["savedSlackMessages"].length > 0) {
|
||||
timer = setTimeout(checkSavedMessages, 60*60000);
|
||||
timer = setTimeout(checkSavedMessages, 60 * 60000);
|
||||
} else {
|
||||
timer = null;
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ exports.install = function(instance) {
|
|||
|
||||
instance.reconfigure = function() {
|
||||
try {
|
||||
if (!FLOW["savedSlackMessages"]){
|
||||
if (!FLOW["savedSlackMessages"]) {
|
||||
FLOW["savedSlackMessages"] = [];
|
||||
}
|
||||
|
||||
|
|
@ -183,5 +183,4 @@ exports.install = function(instance) {
|
|||
instance.on('options', instance.reconfigure);
|
||||
setTimeout(instance.reconfigure, 10000);
|
||||
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue