@Jan-0 said in MMM-Fritz-Box-Callmonitor: Notification formatting:
Hi,
I’m referring to this module (https://github.com/paviro/MMM-FRITZ-Box-Callmonitor). Although it is quite outdated, I still like it and I was able to transfer it to an python3 environment. However, since some update (don’t know which one), the notification (“alert”) is not formatted properly.
The reason seems to be in line 85 of the file MMM-FRITZ-Box-Callmonitor.js:
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification === “call”) {
//Show alert on UI
this.sendNotification(“SHOW_ALERT”, {
title: this.translate(“title”),
message: “” + payload + “”,
imageFA: “phone”
});//Set active Alert to current call this.activeAlert = payload; }
There are two problems: 1) the title is not translated but printed, 2) the message is not formatted but the formatting information is printed verbosely.
Unfortunately, I’m neither an expert in the MagicMirror syntax nor in javascript. Could somebody give me a hint how I need to adopt the code?
To fix this, you can remove the quotes and use template literals instead. Template literals allow you to include variables and formatting within a string using backticks () instead of quotes. Here's how you can modify the code to use template literals: socketNotificationReceived: function(notification, payload) { if (notification === "call") { //Show alert on UI this.sendNotification("SHOW_ALERT", { title: this.translate("title"), message:
${payload}`,
imageFA: “phone”
});
//Set active Alert to current call
this.activeAlert = payload;
}
}
As for the translation issue, you need to make sure that the translate function is correctly configured in your module. The translate function should be defined in the getTranslations function in the module’s node_helper.js file. Here’s an example of how to define the translate function:
getTranslations: function() {
return {
en: “translations/en.json”,
de: “translations/de.json”
};
},
translate: function(key) {
return this.translate(key);
}
This assumes that you have translation files for English and German located in the translations folder of your module. You may need to modify this code to match the structure of your module.
I hope this helps! Let me know if you have any other questions.