iobroker.telegram-menu 0.6.9 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/admin/index_m.html +8 -3
- package/io-package.json +27 -27
- package/lib/js/action.js +24 -25
- package/lib/js/getstate.js +10 -0
- package/lib/js/global.js +34 -0
- package/lib/js/setstate.js +9 -0
- package/lib/js/subMenu.js +14 -14
- package/lib/js/telegram.js +9 -0
- package/main.js +76 -57
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -33,6 +33,16 @@ You can create different groups with separate menus, and then assign users to th
|
|
|
33
33
|
Placeholder for the next version (at the beginning of the line):
|
|
34
34
|
### **WORK IN PROGRESS**
|
|
35
35
|
-->
|
|
36
|
+
### 0.7.0 (2023-10-01)
|
|
37
|
+
|
|
38
|
+
- #53 feature: sendPicture von server-path
|
|
39
|
+
- #52 icons are missing, copy data
|
|
40
|
+
- #51 by creating a new Menu, the Users are not shown
|
|
41
|
+
|
|
42
|
+
### 0.6.10 (2023-09-23)
|
|
43
|
+
|
|
44
|
+
- bug fix
|
|
45
|
+
|
|
36
46
|
### 0.6.9 (2023-09-23)
|
|
37
47
|
|
|
38
48
|
- Rearranging listed actions #49
|
package/admin/index_m.html
CHANGED
|
@@ -168,9 +168,10 @@
|
|
|
168
168
|
addNewGroup(menus, newMenu, _onChange)
|
|
169
169
|
activeMenu = newMenu
|
|
170
170
|
showUser(newMenu, showHideUserCheckbox)
|
|
171
|
-
userListWithChatID = buildUserSelection(valUserFromTelegram, newMenu, usersInMenus)
|
|
171
|
+
userListWithChatID = buildUserSelection(valUserFromTelegram, [newMenu], usersInMenus)
|
|
172
172
|
translateAll()
|
|
173
173
|
}
|
|
174
|
+
|
|
174
175
|
})
|
|
175
176
|
// Delete Btn, open popup
|
|
176
177
|
$("#group_menu").on("click", "#deleteUser", function () {
|
|
@@ -590,9 +591,13 @@
|
|
|
590
591
|
rowToCopy.find("a").parent().remove()
|
|
591
592
|
const buttonsNav = `<td><a class="deleteRow btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td>
|
|
592
593
|
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_down"><i class="material-icons" name="down">arrow_downward</i></a></td>
|
|
593
|
-
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_up"><i class="material-icons" name="up">arrow_upward</i></a></td
|
|
594
|
+
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_up"><i class="material-icons" name="up">arrow_upward</i></a></td>
|
|
595
|
+
<td><a class="btn-floating btn-small waves-effect waves-light green btn_add_row"><i class="material-icons">add</i></a></td>`
|
|
594
596
|
const buttonsAction = `<td><a class="deleteEveryRow btn-floating btn-small waves-effect waves-light red"><i class="material-icons">delete</i></a></td>
|
|
595
|
-
<td><a data-target="tab_action" class="editEntry modal-trigger btn-floating btn-small waves-effect waves-light green"><i class="material-icons">edit</i></a></td
|
|
597
|
+
<td><a data-target="tab_action" class="editEntry modal-trigger btn-floating btn-small waves-effect waves-light green"><i class="material-icons">edit</i></a></td>
|
|
598
|
+
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_down"><i class="material-icons" name="down">arrow_downward</i></a></td>
|
|
599
|
+
<td><a class="btn-floating btn-small waves-effect waves-light blue btn_up"><i class="material-icons" name="up">arrow_upward</i></a></td> `;
|
|
600
|
+
|
|
596
601
|
if (action == "nav") {
|
|
597
602
|
rowToCopy.append(buttonsNav)
|
|
598
603
|
$(`#${activeMenu}`).append(rowToCopy)
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "telegram-menu",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"news": {
|
|
6
|
+
"0.7.0": {
|
|
7
|
+
"en": "#53 feature: sendPicture von server-path\n#52 icons are missing, copy data\n#51 by creating a new Menu, the Users are not shown",
|
|
8
|
+
"de": "#53 Feature: sendPicture von server-path\n#52 symbole fehlen, kopierdaten\n#51 durch Erstellen eines neuen Menüs, die Benutzer werden nicht angezeigt",
|
|
9
|
+
"ru": "#53 функция: sendPicture von server-path\n#52 иконки отсутствуют, копирование данных\n#51, создавая новое меню, Пользователи не отображаются",
|
|
10
|
+
"pt": "Característica #53: sendPicture von server-path\n#52 ícones estão faltando, copiar dados\n#51 criando um novo Menu, os Usuários não são mostrados",
|
|
11
|
+
"nl": "Vertaling:\n52 iconen ontbreken\nQuality over Quantity (QoQ) Releases Vertaling:",
|
|
12
|
+
"fr": "#53 fonction: sendPicture von server-path\n#52 icônes sont manquantes, données de copie\n#51 en créant un nouveau menu, les Utilisateurs ne sont pas affichés",
|
|
13
|
+
"it": "#53 caratteristica: sendPicture von server-path\n#52 icone mancanti, copia dati\n#51 creando un nuovo menu, gli utenti non vengono mostrati",
|
|
14
|
+
"es": "función #53: sendPicture von server-path\n#52 iconos faltan, copiar datos\n#51 mediante la creación de un nuevo Menú, los Usuarios no se muestran",
|
|
15
|
+
"pl": "#53: Wysyłanie serwera\nzaginęło 52 ikony\n#51 poprzez stworzenie nowego Menu, Użytkownicy nie zostali przedstawieni",
|
|
16
|
+
"uk": "#53 Функція: sendPicture фон сервер-path\n#52 іконки відсутні, копіювання даних\n#51 шляхом створення нового меню Користувачі не показані",
|
|
17
|
+
"zh-cn": "#53 特色:寄电器\n第52条 遗漏,复印数据\n第51号活动是创建一个新的男子,用户没有证明。"
|
|
18
|
+
},
|
|
19
|
+
"0.6.10": {
|
|
20
|
+
"en": "bug fix",
|
|
21
|
+
"de": "fehlerbehebung",
|
|
22
|
+
"ru": "исправление ошибки",
|
|
23
|
+
"pt": "correção de bugs",
|
|
24
|
+
"nl": "insecten",
|
|
25
|
+
"fr": "bug fix",
|
|
26
|
+
"it": "correzione bug",
|
|
27
|
+
"es": "bug",
|
|
28
|
+
"pl": "błąd",
|
|
29
|
+
"uk": "виправлення помилок",
|
|
30
|
+
"zh-cn": "bug fix"
|
|
31
|
+
},
|
|
6
32
|
"0.6.9": {
|
|
7
33
|
"en": "Rearranging listed actions #49\nwhen calling up the submenu, Text was send no entry found, fixed\nbug switch menu, fixed\nset a state, and receive the change of another state",
|
|
8
34
|
"de": "Rearrangieren von aufgelisteten Aktionen #49\nbeim Aufruf des Untermenüs, Text wurde nicht gefunden, behoben\nbugschalter-menü, fixiert\neinen zustand einstellen und die änderung eines anderen zustands empfangen",
|
|
@@ -67,32 +93,6 @@
|
|
|
67
93
|
"pl": "użytkowanie przez czat i wysyłane do tego czatID",
|
|
68
94
|
"uk": "отримати користувач по chatID і відправити назад в цей чатID",
|
|
69
95
|
"zh-cn": "被混乱者利用,然后再送给这一混乱的裁研所。"
|
|
70
|
-
},
|
|
71
|
-
"0.6.4": {
|
|
72
|
-
"en": "Trigger check, used triggers are no longer available in action, in nav it is visualized that the trigger is already in use",
|
|
73
|
-
"de": "Trigger-Check, verwendete Trigger sind nicht mehr in Aktion, in nav wird visualisiert, dass der Trigger bereits im Einsatz ist",
|
|
74
|
-
"ru": "Проверка Trigger, используемые триггеры больше не доступны в действии, в nav визуализируется, что триггер уже используется",
|
|
75
|
-
"pt": "Verificação de gatilho, gatilhos usados não estão mais disponíveis em ação, nav é visualizado que o gatilho já está em uso",
|
|
76
|
-
"nl": "Trigger controle, gebruikte triggers zijn niet meer beschikbaar in actie, in Nav is het gevisualiseerd dat de trekker al gebruikt is",
|
|
77
|
-
"fr": "Trigger check, triggers utilisés ne sont plus disponibles en action, dans nav il est visualisé que le trigger est déjà en service",
|
|
78
|
-
"it": "Controllo del trigger, i trigger utilizzati non sono più disponibili in azione, in nav è visualizzato che il trigger è già in uso",
|
|
79
|
-
"es": "Comprobación del desencadenante, los disparadores usados ya no están disponibles en acción, en nav se visualiza que el gatillo ya está en uso",
|
|
80
|
-
"pl": "Kontrola Triggera nie jest już dostępna w akcji, w nav jest wizualizowana, że wyzwalanie jest już w użyciu",
|
|
81
|
-
"uk": "Перевірка тригера, використовувані тригери більше не доступні в дії, в нав він візуалізований, що тригер вже в використанні",
|
|
82
|
-
"zh-cn": "突然的检查不再可供采取行动,在无知的情况下,触发者已经使用。"
|
|
83
|
-
},
|
|
84
|
-
"0.6.3": {
|
|
85
|
-
"en": "user check, least one user must be checked",
|
|
86
|
-
"de": "benutzerüberprüfung, mindestens ein benutzer muss überprüft werden",
|
|
87
|
-
"ru": "проверка пользователя, хотя бы один пользователь должен быть проверен",
|
|
88
|
-
"pt": "verificação do usuário, pelo menos um usuário deve ser verificado",
|
|
89
|
-
"nl": "eén gebruiker moet gecontroleerd worden",
|
|
90
|
-
"fr": "contrôle utilisateur, le moins d'un utilisateur doit être vérifié",
|
|
91
|
-
"it": "controllo utente, almeno un utente deve essere controllato",
|
|
92
|
-
"es": "control de usuario, al menos un usuario debe ser revisado",
|
|
93
|
-
"pl": "wskaźnik użytkownika musi być sprawdzany przynajmniej jeden użytkownik",
|
|
94
|
-
"uk": "перевірка користувачів, принаймні один користувач повинен перевіряти",
|
|
95
|
-
"zh-cn": "用户检查,至少必须检查一名用户。"
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"titleLang": {
|
package/lib/js/action.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const sendToTelegram = require("./telegram").sendToTelegram;
|
|
2
|
+
const Utils = require("./global");
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param {string} textToSend
|
|
5
|
-
* @param {string} val
|
|
4
|
+
* Calculates Value with the Value in {math:} from textToSend
|
|
5
|
+
* @param {string} textToSend Text to send to user
|
|
6
|
+
* @param {string} val Value to calculate with
|
|
7
|
+
* @returns {object} textToSend and val
|
|
6
8
|
*/
|
|
7
9
|
function calcValue(_this, textToSend, val) {
|
|
8
10
|
const startindex = textToSend.indexOf("{math");
|
|
@@ -19,33 +21,29 @@ function calcValue(_this, textToSend, val) {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Exchange Value with other Value
|
|
23
25
|
* @param {String} textToSend Text which should be send to user
|
|
26
|
+
* @param {String} stateVal Value to exchange
|
|
27
|
+
* @param {*} _this
|
|
28
|
+
* @returns {object} valueChange and textToSend
|
|
24
29
|
*/
|
|
25
30
|
function exchangeValue(textToSend, stateVal, _this) {
|
|
26
31
|
const startindex = textToSend.indexOf("change{");
|
|
27
32
|
const match = textToSend.substring(startindex + "change".length + 1, textToSend.indexOf("}", startindex));
|
|
28
33
|
let objChangeValue;
|
|
29
|
-
if (isJSON("{" + match + "}")) objChangeValue = JSON.parse("{" + match + "}");
|
|
34
|
+
if (Utils.isJSON("{" + match + "}")) objChangeValue = JSON.parse("{" + match + "}");
|
|
30
35
|
else {
|
|
31
|
-
_this.log.error(`There is a error in your input: ` + JSON.stringify(
|
|
36
|
+
_this.log.error(`There is a error in your input: ` + JSON.stringify(Utils.replaceAll(match, '"', "'")));
|
|
32
37
|
return false;
|
|
33
38
|
}
|
|
34
39
|
return { valueChange: objChangeValue[String(stateVal)], textToSend: textToSend.substring(0, startindex) };
|
|
35
40
|
}
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
JSON.parse(str);
|
|
39
|
-
return true;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
41
|
+
|
|
44
42
|
/**
|
|
45
43
|
* Generate Array
|
|
46
|
-
* @param {
|
|
44
|
+
* @param {object[]} val
|
|
47
45
|
* @param {*} _this
|
|
48
|
-
* @returns
|
|
46
|
+
* @returns Arrays with Buttons
|
|
49
47
|
*/
|
|
50
48
|
async function editArrayButtons(val, _this) {
|
|
51
49
|
try {
|
|
@@ -76,10 +74,10 @@ async function editArrayButtons(val, _this) {
|
|
|
76
74
|
/**
|
|
77
75
|
*
|
|
78
76
|
* @param {*} _this
|
|
79
|
-
* @param {string} selector
|
|
80
|
-
* @param {
|
|
81
|
-
* @param {
|
|
82
|
-
* @param {
|
|
77
|
+
* @param {string} selector Selector
|
|
78
|
+
* @param {string} text Text to send
|
|
79
|
+
* @param {string} userToSend User to send
|
|
80
|
+
* @param {string} newline Newline
|
|
83
81
|
*/
|
|
84
82
|
const idBySelector = async (
|
|
85
83
|
_this,
|
|
@@ -122,7 +120,7 @@ const idBySelector = async (
|
|
|
122
120
|
text2Send += " " + value.val;
|
|
123
121
|
}
|
|
124
122
|
}
|
|
125
|
-
if (newline == "true"
|
|
123
|
+
if (newline == "true") text2Send += "\n";
|
|
126
124
|
else text2Send += " ";
|
|
127
125
|
_this.log.debug("text2send " + JSON.stringify(text2Send));
|
|
128
126
|
});
|
|
@@ -156,7 +154,8 @@ const idBySelector = async (
|
|
|
156
154
|
/**
|
|
157
155
|
*
|
|
158
156
|
* @param {*} _this
|
|
159
|
-
* @param {array} val
|
|
157
|
+
* @param {array} val Array with Objects
|
|
158
|
+
* @returns Object with new Structure
|
|
160
159
|
*/
|
|
161
160
|
async function generateNewObjectStructure(_this, val) {
|
|
162
161
|
try {
|
|
@@ -176,9 +175,10 @@ async function generateNewObjectStructure(_this, val) {
|
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
/**
|
|
179
|
-
*
|
|
178
|
+
* Generate Actions
|
|
180
179
|
* @param {object} action Object with Actions
|
|
181
|
-
* @param {
|
|
180
|
+
* @param {object} userObject Object from User with generated Navigation
|
|
181
|
+
* @returns {object} Object with Actions and IDs
|
|
182
182
|
*/
|
|
183
183
|
function generateActions(_this, action, userObject) {
|
|
184
184
|
try {
|
|
@@ -223,7 +223,6 @@ function generateActions(_this, action, userObject) {
|
|
|
223
223
|
});
|
|
224
224
|
});
|
|
225
225
|
action.pic.forEach(function (element, key) {
|
|
226
|
-
_this.log.debug("Pic ");
|
|
227
226
|
userObject[element.trigger] = { sendPic: [] };
|
|
228
227
|
if (key == 0) userObject[element.trigger] = { sendPic: [] };
|
|
229
228
|
element.IDs.forEach(function (id, key) {
|
package/lib/js/getstate.js
CHANGED
|
@@ -3,6 +3,16 @@ const idBySelector = require("./action").idBySelector;
|
|
|
3
3
|
const exchangeValue = require("./action").exchangeValue;
|
|
4
4
|
const calcValue = require("./action").calcValue;
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Get the state of the id and send it to the user
|
|
8
|
+
* @param {*} _this
|
|
9
|
+
* @param {object} part Part of the Menu
|
|
10
|
+
* @param {string} userToSend User to send the message to
|
|
11
|
+
* @param {string} telegramInstance Instance to send the message to
|
|
12
|
+
* @param {boolean} one_time_keyboard
|
|
13
|
+
* @param {boolean} resize_keyboard
|
|
14
|
+
* @param {object} userListWithChatID Userlist with ChatID
|
|
15
|
+
*/
|
|
6
16
|
function getstate(_this, part, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID) {
|
|
7
17
|
try {
|
|
8
18
|
let text = "";
|
package/lib/js/global.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicate entries and saves the result
|
|
3
|
+
* @param {string[]} arr Array
|
|
4
|
+
* @returns Array with unique entrys
|
|
5
|
+
*/
|
|
6
|
+
function deleteDoubleEntrysInArray(arr, _this) {
|
|
7
|
+
return arr.filter((item, index) => arr.indexOf(item) === index);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Replaces all searchValue with replaceValue in text
|
|
12
|
+
* @param {string} text Text to replace the searchValue with replaceValue
|
|
13
|
+
* @param {string} searchValue Value to search for
|
|
14
|
+
* @param {string} replaceValue Value to replace the searchValue with
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
function replaceAll(text, searchValue, replaceValue) {
|
|
18
|
+
return text.replace(new RegExp(searchValue, "g"), replaceValue);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if _string is JSON
|
|
22
|
+
* @param {string} _string
|
|
23
|
+
* @returns {boolean} Returns True if _string is JSON else False
|
|
24
|
+
*/
|
|
25
|
+
function isJSON(_string) {
|
|
26
|
+
try {
|
|
27
|
+
JSON.parse(_string);
|
|
28
|
+
return true;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = { deleteDoubleEntrysInArray, replaceAll, isJSON };
|
package/lib/js/setstate.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the state
|
|
3
|
+
* @param {*} _this
|
|
4
|
+
* @param {object} part Part of the menu
|
|
5
|
+
* @param {string} userToSend User to send the message to
|
|
6
|
+
* @param {number} valueFromSubmenu Value from the submenu
|
|
7
|
+
* @param {boolean} SubmenuValuePriority If true the value from the submenu will be used else the value from the switch
|
|
8
|
+
* @returns Returns an array with the ids to set
|
|
9
|
+
*/
|
|
1
10
|
function setstate(_this, part, userToSend, valueFromSubmenu, SubmenuValuePriority) {
|
|
2
11
|
try {
|
|
3
12
|
const setStateIds = [];
|
package/lib/js/subMenu.js
CHANGED
|
@@ -7,14 +7,14 @@ const backMenu = {};
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
* @param {*} _this
|
|
10
|
-
* @param {string}
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {string} userToSend
|
|
13
|
-
* @returns
|
|
10
|
+
* @param {string} part
|
|
11
|
+
* @param {{}} groupData - Data of the group
|
|
12
|
+
* @param {string} userToSend - user to send the message to
|
|
13
|
+
* @returns []
|
|
14
14
|
*/
|
|
15
15
|
function subMenu(
|
|
16
16
|
_this,
|
|
17
|
-
|
|
17
|
+
part,
|
|
18
18
|
groupData,
|
|
19
19
|
userToSend,
|
|
20
20
|
instanceTelegram,
|
|
@@ -22,13 +22,13 @@ function subMenu(
|
|
|
22
22
|
one_time_keyboard,
|
|
23
23
|
userListWithChatID,
|
|
24
24
|
) {
|
|
25
|
-
const splittetText =
|
|
25
|
+
const splittetText = part.split(`"`)[1].split(":");
|
|
26
26
|
const callbackData = splittetText[1];
|
|
27
27
|
let device2Switch = splittetText[2];
|
|
28
28
|
_this.log.debug("callbackData: " + JSON.stringify(callbackData));
|
|
29
29
|
_this.log.debug("splittet Data of callbackData " + JSON.stringify(splittetText[1]));
|
|
30
30
|
_this.log.debug("devicetoswitch: " + JSON.stringify(device2Switch));
|
|
31
|
-
_this.log.debug("text: " + JSON.stringify(
|
|
31
|
+
_this.log.debug("text: " + JSON.stringify(part));
|
|
32
32
|
|
|
33
33
|
//ANCHOR - Switch
|
|
34
34
|
|
|
@@ -77,7 +77,7 @@ function subMenu(
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
//ANCHOR - Percent
|
|
80
|
-
else if (!
|
|
80
|
+
else if (!part.includes("submenu") && callbackData.includes("percent")) {
|
|
81
81
|
step = parseInt(callbackData.replace("percent", ""));
|
|
82
82
|
let rowEntrys = 0;
|
|
83
83
|
let menu = [];
|
|
@@ -106,15 +106,15 @@ function subMenu(
|
|
|
106
106
|
if (rowEntrys != 0) keyboard.inline_keyboard.push(menu);
|
|
107
107
|
|
|
108
108
|
return ["Welcher Wert soll gesetzt werden?", JSON.stringify(keyboard), device2Switch];
|
|
109
|
-
} else if (
|
|
110
|
-
const value = parseInt(
|
|
109
|
+
} else if (part.includes(`submenu:percent${step}`)) {
|
|
110
|
+
const value = parseInt(part.split(":")[1].split(",")[1]);
|
|
111
111
|
|
|
112
112
|
const result = setstate(_this, groupData[device2Switch], userToSend, value, true);
|
|
113
113
|
if (Array.isArray(result)) returnIDToListenTo = result;
|
|
114
114
|
return [null, null, null, returnIDToListenTo];
|
|
115
115
|
|
|
116
116
|
//ANCHOR - Number
|
|
117
|
-
} else if (!
|
|
117
|
+
} else if (!part.includes("submenu") && callbackData.includes("number")) {
|
|
118
118
|
const splittedData = callbackData.replace("number", "").split("-");
|
|
119
119
|
let rowEntrys = 0;
|
|
120
120
|
let menu = [];
|
|
@@ -157,9 +157,9 @@ function subMenu(
|
|
|
157
157
|
if (rowEntrys != 0) keyboard.inline_keyboard.push(menu);
|
|
158
158
|
_this.log.debug("keyboard " + JSON.stringify(keyboard.inline_keyboard));
|
|
159
159
|
return ["Welcher Wert soll gesetzt werden?", JSON.stringify(keyboard), device2Switch];
|
|
160
|
-
} else if (
|
|
161
|
-
const value = parseInt(
|
|
162
|
-
device2Switch =
|
|
160
|
+
} else if (part.includes(`submenu:${callbackData}`)) {
|
|
161
|
+
const value = parseInt(part.split(":")[2]);
|
|
162
|
+
device2Switch = part.split(":")[3];
|
|
163
163
|
_this.log.debug(
|
|
164
164
|
JSON.stringify({ device2Switch: device2Switch, data: groupData, user: userToSend, value: value }),
|
|
165
165
|
);
|
package/lib/js/telegram.js
CHANGED
|
@@ -56,6 +56,15 @@ function sendToTelegram(
|
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param {*} _this
|
|
62
|
+
* @param {string} user Username
|
|
63
|
+
* @param {string} text Text to send
|
|
64
|
+
* @param {*} keyboard
|
|
65
|
+
* @param {*} instance
|
|
66
|
+
* @param {*} userListWithChatID
|
|
67
|
+
*/
|
|
59
68
|
function sendToTelegramSubmenu(_this, user, text, keyboard, instance = "telegram.0", userListWithChatID) {
|
|
60
69
|
try {
|
|
61
70
|
let chatId = "";
|
package/main.js
CHANGED
|
@@ -19,6 +19,7 @@ const getstate = require("./lib/js/getstate").getstate;
|
|
|
19
19
|
const subMenu = require("./lib/js/subMenu").subMenu;
|
|
20
20
|
const backMenuFuc = require("./lib/js/subMenu").backMenuFuc;
|
|
21
21
|
const sendToTelegramSubmenu = require("./lib/js/telegram").sendToTelegramSubmenu;
|
|
22
|
+
const Utils = require("./lib/js/global");
|
|
22
23
|
|
|
23
24
|
let timeouts = [];
|
|
24
25
|
let timeoutKey = 0;
|
|
@@ -58,9 +59,9 @@ class TelegramMenu extends utils.Adapter {
|
|
|
58
59
|
const one_time_keyboard = checkbox["oneTiKey"];
|
|
59
60
|
const resize_keyboard = checkbox["resKey"];
|
|
60
61
|
const checkboxNoEntryFound = checkbox["checkboxNoValueFound"];
|
|
61
|
-
const
|
|
62
|
+
const listofMenus = this.config.users;
|
|
62
63
|
const startsides = this.config.startsides;
|
|
63
|
-
|
|
64
|
+
const token = this.config.tokenGrafana;
|
|
64
65
|
const directoryPicture = this.config.directory;
|
|
65
66
|
const userActiveCheckbox = this.config.userActiveCheckbox;
|
|
66
67
|
const groupsWithUsers = this.config.usersInGroup;
|
|
@@ -72,7 +73,6 @@ class TelegramMenu extends utils.Adapter {
|
|
|
72
73
|
const _this = this;
|
|
73
74
|
this.getForeignObject(datapoint, async (err, obj) => {
|
|
74
75
|
if (err || obj == null) {
|
|
75
|
-
// Error
|
|
76
76
|
this.log.error(JSON.stringify(err));
|
|
77
77
|
this.log.error(`The State ${datapoint} was not found!`);
|
|
78
78
|
} else {
|
|
@@ -80,7 +80,7 @@ class TelegramMenu extends utils.Adapter {
|
|
|
80
80
|
try {
|
|
81
81
|
telegramState = await this.getForeignStateAsync(datapoint);
|
|
82
82
|
} catch (e) {
|
|
83
|
-
this.log.
|
|
83
|
+
this.log.error("Error getForeignState: " + JSON.stringify(e));
|
|
84
84
|
}
|
|
85
85
|
telegramAktiv = telegramState?.val;
|
|
86
86
|
if (!telegramAktiv) {
|
|
@@ -99,14 +99,15 @@ class TelegramMenu extends utils.Adapter {
|
|
|
99
99
|
try {
|
|
100
100
|
for (const name in nav) {
|
|
101
101
|
const value = await editArrayButtons(nav[name], this);
|
|
102
|
-
menu.data[name] = await generateNewObjectStructure(_this, value);
|
|
102
|
+
if (value) menu.data[name] = await generateNewObjectStructure(_this, value);
|
|
103
103
|
this.log.debug("New Structure: " + JSON.stringify(menu.data[name]));
|
|
104
104
|
const returnValue = generateActions(_this, action[name], menu.data[name]);
|
|
105
105
|
menu.data[name] = returnValue?.obj;
|
|
106
106
|
subscribeForeignStateIds = returnValue?.ids;
|
|
107
|
-
if (subscribeForeignStateIds && subscribeForeignStateIds?.length > 0)
|
|
108
|
-
_subscribeForeignStatesAsync(subscribeForeignStateIds, _this);
|
|
109
107
|
this.log.debug("SubscribeForeignStates: " + JSON.stringify(subscribeForeignStateIds));
|
|
108
|
+
if (subscribeForeignStateIds && subscribeForeignStateIds?.length > 0) {
|
|
109
|
+
_subscribeForeignStatesAsync(subscribeForeignStateIds, _this);
|
|
110
|
+
} else this.log.debug("Nothing to Subscribe!");
|
|
110
111
|
this.log.debug("Menu: " + JSON.stringify(name));
|
|
111
112
|
this.log.debug("Array Buttons: " + JSON.stringify(value));
|
|
112
113
|
this.log.debug("Gen. Actions: " + JSON.stringify(menu.data[name]));
|
|
@@ -117,27 +118,31 @@ class TelegramMenu extends utils.Adapter {
|
|
|
117
118
|
this.log.debug("Checkbox " + JSON.stringify(checkbox));
|
|
118
119
|
|
|
119
120
|
try {
|
|
120
|
-
this.log.debug("MenuList: " + JSON.stringify(
|
|
121
|
-
|
|
122
|
-
this.log.debug("Menu: " + JSON.stringify(
|
|
123
|
-
const startside = [startsides[
|
|
124
|
-
if (userActiveCheckbox[
|
|
121
|
+
this.log.debug("MenuList: " + JSON.stringify(listofMenus));
|
|
122
|
+
listofMenus.forEach((menu) => {
|
|
123
|
+
this.log.debug("Menu: " + JSON.stringify(menu));
|
|
124
|
+
const startside = [startsides[menu]].toString();
|
|
125
|
+
if (userActiveCheckbox[menu] && startside != "-") {
|
|
125
126
|
this.log.debug("Startseite: " + JSON.stringify(startside));
|
|
126
|
-
groupsWithUsers[
|
|
127
|
+
groupsWithUsers[menu].forEach((user) => {
|
|
127
128
|
backMenuFuc(this, startside, null, user);
|
|
128
129
|
this.log.debug("User List " + JSON.stringify(userListWithChatID));
|
|
129
130
|
sendToTelegram(
|
|
130
131
|
_this,
|
|
131
132
|
user,
|
|
132
|
-
menu.data[
|
|
133
|
-
menu.data[
|
|
133
|
+
menu.data[menu][startside].text,
|
|
134
|
+
menu.data[menu][startside].nav,
|
|
134
135
|
instanceTelegram,
|
|
135
136
|
resize_keyboard,
|
|
136
137
|
one_time_keyboard,
|
|
137
138
|
userListWithChatID,
|
|
138
139
|
);
|
|
139
140
|
});
|
|
140
|
-
}
|
|
141
|
+
} else
|
|
142
|
+
this.log.debug(
|
|
143
|
+
"Menu inactive or is Submenu. " +
|
|
144
|
+
JSON.stringify({ active: userActiveCheckbox[menu], startside: startside }),
|
|
145
|
+
);
|
|
141
146
|
});
|
|
142
147
|
} catch (error) {
|
|
143
148
|
this.log.error("Error read UserList" + error);
|
|
@@ -293,7 +298,7 @@ class TelegramMenu extends utils.Adapter {
|
|
|
293
298
|
_this.log.debug("Menu to Send: " + JSON.stringify(part.nav));
|
|
294
299
|
backMenuFuc(_this, calledValue, part.nav, userToSend);
|
|
295
300
|
if (JSON.stringify(part.nav).includes("menu")) {
|
|
296
|
-
callSubMenu(_this, part.nav, groupData, userToSend);
|
|
301
|
+
callSubMenu(_this, JSON.stringify(part.nav), groupData, userToSend);
|
|
297
302
|
return true;
|
|
298
303
|
} else {
|
|
299
304
|
if (userToSend) {
|
|
@@ -314,7 +319,11 @@ class TelegramMenu extends utils.Adapter {
|
|
|
314
319
|
}
|
|
315
320
|
// Schalten
|
|
316
321
|
else if (part.switch) {
|
|
317
|
-
setStateIdsToListenTo = setstate(_this, part, userToSend);
|
|
322
|
+
setStateIdsToListenTo = setstate(_this, part, userToSend, 0, false);
|
|
323
|
+
|
|
324
|
+
_this.log.debug("SubmenuData3" + JSON.stringify(setStateIdsToListenTo));
|
|
325
|
+
if (Array.isArray(setStateIdsToListenTo))
|
|
326
|
+
_subscribeAndUnSubscribeForeignStatesAsync(setStateIdsToListenTo, _this, true);
|
|
318
327
|
return true;
|
|
319
328
|
} else if (part.getData) {
|
|
320
329
|
getstate(
|
|
@@ -328,36 +337,40 @@ class TelegramMenu extends utils.Adapter {
|
|
|
328
337
|
);
|
|
329
338
|
return true;
|
|
330
339
|
} else if (part.sendPic) {
|
|
331
|
-
|
|
332
|
-
_this.log.debug("Send Picture");
|
|
340
|
+
_this.log.debug("Send Picture");
|
|
333
341
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
342
|
+
part.sendPic.forEach((element) => {
|
|
343
|
+
let path = "";
|
|
344
|
+
if (element.id != "-") {
|
|
337
345
|
const url = element.id;
|
|
338
|
-
const newUrl =
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
346
|
+
const newUrl = Utils.replaceAll(url, "&", "&");
|
|
347
|
+
try {
|
|
348
|
+
exec(
|
|
349
|
+
`curl -H "Authorisation: Bearer ${token.trim()}" "${newUrl}" > ${directoryPicture}${
|
|
350
|
+
element.fileName
|
|
351
|
+
}`,
|
|
352
|
+
(error, stdout, stderr) => {
|
|
353
|
+
if (stdout) {
|
|
354
|
+
_this.log.debug("Stdout: " + JSON.stringify(stdout));
|
|
355
|
+
}
|
|
356
|
+
if (stderr) {
|
|
357
|
+
_this.log.debug("Stderr: " + JSON.stringify(stderr));
|
|
358
|
+
}
|
|
359
|
+
if (error) {
|
|
360
|
+
_this.log.error("Ein Fehler ist aufgetreten: " + JSON.stringify(error));
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
);
|
|
365
|
+
} catch (e) {
|
|
366
|
+
_this.log.error("Error :" + JSON.stringify(e));
|
|
367
|
+
}
|
|
354
368
|
|
|
355
|
-
_this.log.debug(
|
|
356
|
-
"url " +
|
|
357
|
-
`curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`,
|
|
358
|
-
);
|
|
369
|
+
_this.log.debug("Delay Time " + JSON.stringify(element.delay));
|
|
359
370
|
timeoutKey += 1;
|
|
360
|
-
|
|
371
|
+
path = `${directoryPicture}${element.fileName}`;
|
|
372
|
+
} else path = element.fileName;
|
|
373
|
+
try {
|
|
361
374
|
const timeout = _this.setTimeout(async () => {
|
|
362
375
|
_this.log.debug("Send Pic to Telegram");
|
|
363
376
|
sendToTelegram(
|
|
@@ -375,13 +388,17 @@ class TelegramMenu extends utils.Adapter {
|
|
|
375
388
|
timeoutToClear = timeouts.filter((item) => item.key == timeoutKey);
|
|
376
389
|
clearTimeout(timeoutToClear.timeout);
|
|
377
390
|
timeouts = timeouts.filter((item) => item.key !== timeoutKey);
|
|
378
|
-
}, element.delay);
|
|
391
|
+
}, parseInt(element.delay));
|
|
392
|
+
_this.log.debug("Timeout add");
|
|
379
393
|
timeouts.push({ key: timeoutKey, timeout: timeout });
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
394
|
+
} catch (e) {
|
|
395
|
+
_this.log.error("Error: " + JSON.stringify(e));
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
_this.log.debug("Picture sended");
|
|
400
|
+
|
|
401
|
+
return true;
|
|
385
402
|
}
|
|
386
403
|
} else if (calledValue.startsWith("menu") || calledValue.startsWith("submenu")) {
|
|
387
404
|
callSubMenu(_this, calledValue, groupData, userToSend);
|
|
@@ -393,8 +410,8 @@ class TelegramMenu extends utils.Adapter {
|
|
|
393
410
|
/**
|
|
394
411
|
*
|
|
395
412
|
* @param {*} _this
|
|
396
|
-
* @param {
|
|
397
|
-
* @param {
|
|
413
|
+
* @param {string} part
|
|
414
|
+
* @param {{}} groupData
|
|
398
415
|
* @param {string} userToSend
|
|
399
416
|
*/
|
|
400
417
|
function callSubMenu(_this, part, groupData, userToSend) {
|
|
@@ -415,7 +432,7 @@ class TelegramMenu extends utils.Adapter {
|
|
|
415
432
|
if (subMenuData[3]) setStateIdsToListenTo = subMenuData[3];
|
|
416
433
|
_subscribeAndUnSubscribeForeignStatesAsync(setStateIdsToListenTo, _this, true);
|
|
417
434
|
}
|
|
418
|
-
if (subMenuData && subMenuData[0]) {
|
|
435
|
+
if (subMenuData && typeof subMenuData[0] == "string") {
|
|
419
436
|
sendToTelegramSubmenu(
|
|
420
437
|
_this,
|
|
421
438
|
userToSend,
|
|
@@ -429,18 +446,20 @@ class TelegramMenu extends utils.Adapter {
|
|
|
429
446
|
|
|
430
447
|
/**
|
|
431
448
|
*
|
|
432
|
-
* @param {
|
|
449
|
+
* @param {string[]} array
|
|
433
450
|
* @param {*} _this
|
|
434
451
|
*/
|
|
435
452
|
function _subscribeForeignStatesAsync(array, _this) {
|
|
453
|
+
array = Utils.deleteDoubleEntrysInArray(array, _this);
|
|
454
|
+
_this.log.debug("Subscribe all States of: " + JSON.stringify(array));
|
|
436
455
|
array.forEach((element) => {
|
|
437
|
-
|
|
438
|
-
_this.subscribeForeignStatesAsync(element.id);
|
|
456
|
+
_this.subscribeForeignStatesAsync(element);
|
|
439
457
|
});
|
|
440
458
|
}
|
|
459
|
+
|
|
441
460
|
/**
|
|
442
461
|
*
|
|
443
|
-
* @param {[]} array
|
|
462
|
+
* @param {any[]} array
|
|
444
463
|
* @param {*} _this
|
|
445
464
|
* @param {boolean} subscribe If true, then subscribe, else unsubscribe
|
|
446
465
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.telegram-menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Easily create Telegram Menus",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "MiRo1310",
|
|
@@ -34,22 +34,24 @@
|
|
|
34
34
|
"@types/chai": "^4.3.5",
|
|
35
35
|
"@types/chai-as-promised": "^7.1.5",
|
|
36
36
|
"@types/jquery": "^3.5.16",
|
|
37
|
-
"@types/mocha": "^10.0.
|
|
37
|
+
"@types/mocha": "^10.0.2",
|
|
38
38
|
"@types/node": "^20.3.3",
|
|
39
|
-
"@types/proxyquire": "^1.3.
|
|
39
|
+
"@types/proxyquire": "^1.3.29",
|
|
40
40
|
"@types/sinon": "^10.0.15",
|
|
41
|
-
"@types/sinon-chai": "^3.2.
|
|
41
|
+
"@types/sinon-chai": "^3.2.10",
|
|
42
42
|
"chai": "^4.3.7",
|
|
43
43
|
"chai-as-promised": "^7.1.1",
|
|
44
|
-
"eslint": "^8.
|
|
44
|
+
"eslint": "^8.50.0",
|
|
45
45
|
"eslint-config-prettier": "^9.0.0",
|
|
46
|
-
"eslint-plugin-prettier": "^
|
|
46
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
47
47
|
"mocha": "^10.2.0",
|
|
48
48
|
"prettier": "^3.0.3",
|
|
49
49
|
"proxyquire": "^2.1.3",
|
|
50
50
|
"sinon": "^15.2.0",
|
|
51
51
|
"sinon-chai": "^3.7.0",
|
|
52
|
-
"typescript": "~5.2.2"
|
|
52
|
+
"typescript": "~5.2.2",
|
|
53
|
+
"chalk": "^5.3.0",
|
|
54
|
+
"inquirer": "^9.2.11"
|
|
53
55
|
},
|
|
54
56
|
"main": "main.js",
|
|
55
57
|
"files": [
|