NotificamBot/src/templates.js

41 lines
583 B
JavaScript
Raw Normal View History

2020-06-21 17:24:53 +02:00
const genericTemplate = (msg) => {
2022-01-31 16:19:33 +01:00
value = `---
type: ${msg.type}
description: ${msg.description}`;
2020-06-21 17:24:53 +02:00
return value;
}
2020-07-07 14:21:22 +02:00
const noTemplate = (msg) => {
return msg;
}
2020-06-21 17:24:53 +02:00
const handler = (msg) => {
let msgParsed;
let value;
try {
msgParsed = JSON.parse(msg);
} catch (e) {
console.error('Error parse');
return 'Error';
}
2022-01-31 16:19:33 +01:00
switch (msgParsed.type) {
2020-06-21 17:24:53 +02:00
case 'generic':
value = genericTemplate(msgParsed);
break;
default:
2020-07-07 14:21:22 +02:00
value = noTemplate(msgParsed)
2020-06-21 17:24:53 +02:00
}
return value;
}
const template = {
handler
}
module.exports = template;