iobroker.telegram-menu 0.3.0 → 0.4.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 CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  Easily create Telegram Menus
17
17
 
18
- You can create a separate menu for each user, or you can use the global user to generate the same menu for all users.
18
+ You can create different groups with separate menus, and then assign users to them.
19
19
 
20
20
  **If you like it, please consider a donation:**
21
21
 
@@ -33,6 +33,14 @@ You can create a separate menu for each user, or you can use the global user to
33
33
  Placeholder for the next version (at the beginning of the line):
34
34
  ### **WORK IN PROGRESS**
35
35
  -->
36
+ ### 0.4.0 (2023-07-28)
37
+
38
+ - change output value for getState
39
+ - checkbox to disbale Text No Entry found in the settings #34
40
+ - submenu
41
+ - **changed!!!**, states are always set with ack false
42
+ - adapter does not restart when telegram restarts #35
43
+
36
44
  ### 0.3.0 (2023-07-02)
37
45
 
38
46
  - add ack Flag
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Kein Eintrag, an alle Benutzer senden.",
3
3
  "Action": "Aktion",
4
+ "Active": "Aktiv",
4
5
  "Add": "hinzufügen",
5
6
  "Add && as a placeholder for the value in the text": "Fügen Sie && als Platzhalter für den Wert im Text hinzu",
6
7
  "Add && as a placeholder for the value in the text": "Fügen Sie && als Platzhalter für den Wert im Text hinzu",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": " No entry, send to all Users.",
3
3
  "Action": "Action",
4
+ "Active": "Active",
4
5
  "Add": "add",
5
6
  "Add && as a placeholder for the value in the text": "Add && as a placeholder for the value in the text",
6
7
  "Add && as a placeholder for the value in the text": "Add && as a placeholder for the value in the text",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Sin entrada, enviar a todos los usuarios.",
3
3
  "Action": "Acción",
4
+ "Active": "Activo",
4
5
  "Add": "agregar",
5
6
  "Add && as a placeholder for the value in the text": "Agregue && como marcador de posición para el valor en el texto",
6
7
  "Add && as a placeholder for the value in the text": "Agregue && como marcador de posición para el valor en el texto",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Aucune entrée, envoyer à tous les utilisateurs.",
3
3
  "Action": "Action",
4
+ "Active": "Actif",
4
5
  "Add": "ajouter",
5
6
  "Add && as a placeholder for the value in the text": "Ajouter && comme espace réservé pour la valeur dans le texte",
6
7
  "Add && as a placeholder for the value in the text": "Ajouter && comme espace réservé pour la valeur dans le texte",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Nessuna voce, invia a tutti gli utenti.",
3
3
  "Action": "Azione",
4
+ "Active": "Attivo",
4
5
  "Add": "aggiungere",
5
6
  "Add && as a placeholder for the value in the text": "Aggiungi && come segnaposto per il valore nel testo",
6
7
  "Add && as a placeholder for the value in the text": "Aggiungi && come segnaposto per il valore nel testo",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Geen invoer, verzenden naar alle gebruikers.",
3
3
  "Action": "Actie",
4
+ "Active": "Actief",
4
5
  "Add": "toevoegen",
5
6
  "Add && as a placeholder for the value in the text": "Voeg && toe als tijdelijke aanduiding voor de waarde in de tekst",
6
7
  "Add && as a placeholder for the value in the text": "Voeg && toe als tijdelijke aanduiding voor de waarde in de tekst",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Brak wpisu, wyślij do wszystkich Użytkowników.",
3
3
  "Action": "Działanie",
4
+ "Active": "Aktywny",
4
5
  "Add": "dodać",
5
6
  "Add && as a placeholder for the value in the text": "Dodaj && jako symbol zastępczy wartości w tekście",
6
7
  "Add && as a placeholder for the value in the text": "Dodaj && jako symbol zastępczy wartości w tekście",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Sem entrada, envie para todos os usuários.",
3
3
  "Action": "Ação",
4
+ "Active": "Ativo",
4
5
  "Add": "adicionar",
5
6
  "Add && as a placeholder for the value in the text": "Adicionar && como espaço reservado para o valor no texto",
6
7
  "Add && as a placeholder for the value in the text": "Adicionar && como espaço reservado para o valor no texto",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Нет записи, отправить всем пользователям.",
3
3
  "Action": "Действие",
4
+ "Active": "Активный",
4
5
  "Add": "добавлять",
5
6
  "Add && as a placeholder for the value in the text": "Добавьте && в качестве заполнителя для значения в тексте",
6
7
  "Add && as a placeholder for the value in the text": "Добавьте && в качестве заполнителя для значения в тексте",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "Заборонено, відправити всім користувачам.",
3
3
  "Action": "Дія",
4
+ "Active": "Активний",
4
5
  "Add": "додати",
5
6
  "Add && as a placeholder for the value in the text": "Додайте && як заповнювач для значення в тексті",
6
7
  "Add && as a placeholder for the value in the text": "Додайте && як заповнювач для значення в тексті",
@@ -1,6 +1,7 @@
1
1
  {
2
2
  " No entry, send to all Users.": "没有条目,发送给所有用户。",
3
3
  "Action": "行动",
4
+ "Active": "积极的",
4
5
  "Add": "添加",
5
6
  "Add && as a placeholder for the value in the text": "添加 && 作为文本中值的占位符",
6
7
  "Add && as a placeholder for the value in the text": "添加 && 作为文本中值的占位符",
@@ -52,6 +52,7 @@
52
52
  setCheckbox(settings.checkbox)
53
53
  generateSelectTrigger(activeGroup)
54
54
  checkUpAndDownArrowBtn(activeGroup)
55
+ disableEnableInputField("#checkboxNoValueFound", "#textNoEntry")
55
56
  // When import from old Version import Username
56
57
  if (settings.usersForGlobal) $("#group_UserInput input[name='Global']").val(settings.usersForGlobal)
57
58
  if (settings.instance) telegramInstance = settings.instance
@@ -359,6 +360,13 @@
359
360
  $(`#tab_${$("#select_action").val()} tbody`).append(newTrInAction($("#select_action").val(), undefined, rows))
360
361
  $("#btn_action_set").attr("disabled", "disabled")
361
362
  })
363
+
364
+ // Settings--------------------------------------------------------------------
365
+ $("#tab-settings").on("change", "#checkboxNoValueFound", function () {
366
+ disableEnableInputField("#checkboxNoValueFound", "#textNoEntry")
367
+
368
+ })
369
+
362
370
  // --------------------------------------------------------------------------------
363
371
  // Global Disable delete Button in Tables
364
372
  $("div.adapter-container").on("DOMSubtreeModified", "table tbody", function () {
@@ -507,16 +515,6 @@
507
515
  findElementsToCopy("#tab-nav tbody", "nav")
508
516
  }
509
517
  else findElementsToCopy(`#tab-action tbody[data-name='${$(this).val()}']`, $(this).val())
510
-
511
- // if ($(this).val() == "set") {
512
- // )
513
- // }
514
- // else if ($(this).val() == "get") {
515
- // findElementsToCopy("#tab-action tbody[data-name='get']", "get")
516
- // }
517
- // else if ($(this).val() == "pic") {
518
- // findElementsToCopy("#tab-action tbody[data-name='pic']", "pic")
519
- // }
520
518
  })
521
519
  function findElementsToCopy(selektor, toDo) {
522
520
  const $bodys = $(selektor).map((index, tbody) => {
@@ -799,6 +797,7 @@
799
797
  </div>
800
798
  </div>
801
799
  <div id="tab-action"></div>
800
+ <!-- //SECTION - Settings -->
802
801
  <div id="tab-settings">
803
802
  <div class=" row">
804
803
  <div class="col s12">
@@ -815,6 +814,13 @@
815
814
  <input id="textNoEntry" type="text" class="value translateV" value="Entry not found!">
816
815
  <label for="textNoEntry" class="translate">Text will be send if no entry was found!</label>
817
816
  </div>
817
+ <div class="input-field col s3">
818
+ <label>
819
+ <input id="checkboxNoValueFound" type="checkbox" class="filled-in valCheckbox"
820
+ checked />
821
+ <span class="translate">Active</span>
822
+ </label>
823
+ </div>
818
824
  </div>
819
825
  <div class="row">
820
826
  <div class="input-field col s3">
@@ -70,10 +70,11 @@ function userActivCheckbox(user, val) {
70
70
  <span class="marginTop">${user} <span> </span><span class="translate">active</span>
71
71
  </span></div> `;
72
72
  }
73
-
73
+ //SECTION - Trigger
74
74
  function createSelectTrigger(list) {
75
75
  let element = '<option value="" disabled selected class="translate">Choose a trigger</option>';
76
76
  list.forEach(function (e) {
77
+ if (e.includes("menu:")) e = e.split(":")[2];
77
78
  const dynamicChild = `<option value="${e}" >${e}</option>`;
78
79
  element += dynamicChild;
79
80
  });
package/admin/js/main.js CHANGED
@@ -1,13 +1,25 @@
1
- /*global newUserBtn,navElement ,actionElement,createSelectTrigger,newTableRow_Action,newTableRow_Action,newTrInAction, newSelectInstanceRow,userActivCheckbox,$, groupUserInput*/
2
- /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "isStringEmty|generate|create|set|fill|reset|add|show|ins|table|get|new|show|checkValueModal|disable|checkUpAndDownArrowBtn"}]*/
1
+ /*global newUserBtn ,navElement ,actionElement,createSelectTrigger,newTableRow_Action,newTableRow_Action,newTrInAction, newSelectInstanceRow,userActivCheckbox,$, groupUserInput*/
2
+ /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "disableEnableInputField|isStringEmty|generate|create|set|fill|reset|add|show|ins|table|get|new|show|checkValueModal|disable|checkUpAndDownArrowBtn|"}]*/
3
3
 
4
+ /**
5
+ *
6
+ * @param {string} checkbox ID of the checkbox
7
+ * @param {string} inputfield ID of the Input Field
8
+ */
9
+ function disableEnableInputField(checkbox, inputfield) {
10
+ const active = $(checkbox).is(":checked");
11
+ if (active) $(inputfield).removeAttr("disabled");
12
+ else $(inputfield).attr("disabled", "disabled");
13
+ }
4
14
  /**
5
15
  *
6
16
  * @param {string} classes Class to browse for empty String
7
17
  * @returns boolean True Everything is ok
8
18
  */
19
+ // @ts-ignore
9
20
  function isStringEmty(classes) {
10
21
  let allOk = true;
22
+ // @ts-ignore
11
23
  $(classes).each(function (key, element) {
12
24
  if (element.value == "") {
13
25
  $(element).parent().addClass("bg-error");
@@ -18,6 +30,7 @@ function isStringEmty(classes) {
18
30
  });
19
31
  return allOk;
20
32
  }
33
+ // @ts-ignore
21
34
  function checkUpAndDownArrowBtn(activeuser) {
22
35
  const lengthOfNavList = $(`tbody#${activeuser}.visibilityArrowBtn tr`).length - 1;
23
36
  $(`tbody#${activeuser}.visibilityArrowBtn tr`).each(function (key) {
@@ -31,13 +44,16 @@ function checkUpAndDownArrowBtn(activeuser) {
31
44
  });
32
45
  }
33
46
 
47
+ // @ts-ignore
34
48
  function generateNav() {
35
49
  const navigationArray = {};
36
50
  const ids = [];
37
51
  const nav = [];
52
+ // @ts-ignore
38
53
  $(".nav-id").each((key, element) => {
39
54
  ids.push(element.value);
40
55
  });
56
+ // @ts-ignore
41
57
  $(".nav-value").each((key, element) => {
42
58
  nav.push(element.value);
43
59
  });
@@ -63,20 +79,26 @@ function generateNav() {
63
79
  */
64
80
  function createGroup(id, users, activeGroup, userActiveCheckbox, usersInGroup) {
65
81
  users.forEach((user) => {
82
+ // @ts-ignore
66
83
  $(id).append(newUserBtn(user));
84
+ // @ts-ignore
67
85
  $("#table_nav").append(navElement(user));
86
+ // @ts-ignore
68
87
  $("#tab-action").append(actionElement(user));
69
88
  let val;
70
89
  if (userActiveCheckbox && userActiveCheckbox[user] != undefined) val = userActiveCheckbox[user];
71
90
  else val = "";
91
+ // @ts-ignore
72
92
  $("#group_active_checkbox").append(userActivCheckbox(user, val));
73
93
  if (usersInGroup && usersInGroup[user] != undefined) val = usersInGroup[user];
74
94
  else val = "";
95
+ // @ts-ignore
75
96
  $("#group_UserInput").append(groupUserInput(user, val));
76
97
  });
77
98
  if (activeGroup) $(`#group_active_checkbox div.${activeGroup}`).show();
78
99
  }
79
100
  //SECTION - Save 5 Save to Object
101
+ // @ts-ignore
80
102
  function table2Values(id) {
81
103
  let oldName;
82
104
  const $tbodys = $(id).find("tbody");
@@ -176,6 +198,7 @@ function showHideUserEntry(activeGroup) {
176
198
  *
177
199
  * @param {Array} checkbox Entrys with Checkbox Values
178
200
  */
201
+ // @ts-ignore
179
202
  function setCheckbox(checkbox) {
180
203
  Object.keys(checkbox).forEach((key) => {
181
204
  if (checkbox[key]) {
@@ -199,12 +222,15 @@ function splitTextInArray(activeGroup) {
199
222
  return value_list;
200
223
  }
201
224
 
225
+ // @ts-ignore
202
226
  function generateSelectTrigger(activeGroup) {
203
227
  const list = splitTextInArray(activeGroup);
204
228
  // HTML Elemente löschen und neu aufbauen
229
+ // @ts-ignore
205
230
  $("#select_trigger").empty().append(createSelectTrigger(list));
206
231
  }
207
232
 
233
+ // @ts-ignore
208
234
  function fillTable(id, data, newTableRow_Nav, users) {
209
235
  if (data) {
210
236
  for (const name in data) {
@@ -220,6 +246,7 @@ function fillTable(id, data, newTableRow_Nav, users) {
220
246
  }
221
247
  }
222
248
 
249
+ // @ts-ignore
223
250
  function fillTableAction(data) {
224
251
  if (data) {
225
252
  for (const name in data) {
@@ -234,10 +261,13 @@ function fillTableAction(data) {
234
261
 
235
262
  function generatActionRow(user, action, result, editedRowUpdate) {
236
263
  if (editedRowUpdate) {
264
+ // @ts-ignore
237
265
  $(editedRowUpdate).empty().html(newTableRow_Action(action, result)?.replace("<tr>", "").replace("</tr>", ""));
266
+ // @ts-ignore
238
267
  } else $(`.user_${user} .table_${action}`).append(newTableRow_Action(action, result));
239
268
  }
240
269
 
270
+ // @ts-ignore
241
271
  function resetModal() {
242
272
  $(".reset").each(function () {
243
273
  $(this).val("");
@@ -269,6 +299,7 @@ function showSelectModal(showTrigger, show) {
269
299
  else $("#btn_action_set").attr("disabled", "disabled");
270
300
  }
271
301
  //SECTION - Save 4 edit Values
302
+ // @ts-ignore
272
303
  function insertEditValues(action, $this) {
273
304
  const IDs = valuesToArray($this, "p[data-name='IDs']");
274
305
  let newline, switchs, confirm, returnText, values, texts, picSendDelay, fileName;
@@ -287,6 +318,7 @@ function insertEditValues(action, $this) {
287
318
  picSendDelay = valuesToArray($this, "p[data-name='picSendDelay']");
288
319
  fileName = valuesToArray($this, "p[data-name='fileName']");
289
320
  }
321
+ // @ts-ignore
290
322
  IDs.forEach(function (element, key) {
291
323
  if (key == 0) {
292
324
  $(`#tab_${action} tbody input.set_id`).val(IDs[0].trim());
@@ -338,6 +370,7 @@ function insertEditValues(action, $this) {
338
370
  _confirm,
339
371
  _returnText,
340
372
  ];
373
+ // @ts-ignore
341
374
  $(`#tab_${$("#select_action").val()} tbody`).append(newTrInAction($("#select_action").val(), array));
342
375
  }
343
376
  });
@@ -355,6 +388,7 @@ function valuesToArray($this, selector) {
355
388
  return val;
356
389
  }
357
390
 
391
+ // @ts-ignore
358
392
  function addNewGroup(users, newUser, _onChange) {
359
393
  users.push(newUser);
360
394
  createGroup("#group_list", [newUser], null, null, null);
@@ -367,6 +401,7 @@ function addNewGroup(users, newUser, _onChange) {
367
401
  *
368
402
  * @param {array} users Array of Users
369
403
  */
404
+ // @ts-ignore
370
405
  function generateStartside(users) {
371
406
  const obj = {};
372
407
  users.forEach(function (user) {
@@ -380,6 +415,7 @@ function generateStartside(users) {
380
415
  * @param {*} socket
381
416
  * @returns
382
417
  */
418
+ // @ts-ignore
383
419
  function getAllTelegramInstances(socket, _this) {
384
420
  const id = [];
385
421
  try {
@@ -403,6 +439,7 @@ function getAllTelegramInstances(socket, _this) {
403
439
  }
404
440
  if (i == doc.rows.length - 1) {
405
441
  id.forEach((id) => {
442
+ // @ts-ignore
406
443
  $("#select_instance").append(newSelectInstanceRow(id));
407
444
  });
408
445
  }
@@ -414,6 +451,7 @@ function getAllTelegramInstances(socket, _this) {
414
451
  _this.log.debug("Error getAllTelegramInstance: " + JSON.stringify(err));
415
452
  }
416
453
  }
454
+ // @ts-ignore
417
455
  function showUser(activeGroup, showHideUserCheckbox) {
418
456
  showHideUserEntry(activeGroup);
419
457
 
@@ -423,6 +461,7 @@ function showUser(activeGroup, showHideUserCheckbox) {
423
461
  $(`#group_list li a[name=${activeGroup}]`).addClass("active");
424
462
  if (showHideUserCheckbox) showHideUserCheckbox(activeGroup);
425
463
  }
464
+ // @ts-ignore
426
465
  function checkValueModal(showTrigger) {
427
466
  let show = true;
428
467
  $(".checkValue").each(function () {
@@ -449,6 +488,7 @@ function checkValueModal(showTrigger) {
449
488
 
450
489
  showSelectModal(showTrigger, show);
451
490
  }
491
+ // @ts-ignore
452
492
  function disableValueInput() {
453
493
  $(".switch_checkbox").each(function () {
454
494
  if ($(this).is(":checked")) {
package/admin/words.js CHANGED
@@ -56,4 +56,5 @@ systemDictionary = {
56
56
  "What is to do?": { "en": "What is to do?", "de": "Was ist zu tun?", "ru": "Что делать?", "pt": "O que fazer?", "nl": "Wat is er te doen?", "fr": "Que faire ?", "it": "Cosa fare?", "es": "¿Qué hay que hacer?", "pl": "Co robić?", "uk": "Що робити?", "zh-cn": "怎么办?"},
57
57
  "active": { "en": "active", "de": "aktiv", "ru": "активный", "pt": "ativo", "nl": "actief", "fr": "actif", "it": "attivo", "es": "activo", "pl": "aktywny", "uk": "активний", "zh-cn": "积极的"},
58
58
  "telegram-menu adapter settings": { "en": "Adapter settings for telegram-menu", "de": "Adaptereinstellungen für Telegram-Menü", "ru": "Настройки адаптера для телеграм-меню", "pt": "Configurações do adaptador para menu de telegrama", "nl": "Adapterinstellingen voor telegrammenu", "fr": "Paramètres de l'adaptateur pour le menu télégramme", "it": "Impostazioni dell'adattatore per il menu del telegramma", "es": "Configuración del adaptador para el menú de telegramas", "pl": "Ustawienia adaptera dla menu telegramu", "uk": "Налаштування адаптера для telegram-меню", "zh-cn": "电报菜单的适配器设置"},
59
+ "Active": { "en": "Active", "de": "Aktiv", "ru": "Активный", "pt": "Ativo", "nl": "Actief", "fr": "Actif", "it": "Attivo", "es": "Activo", "pl": "Aktywny", "uk": "Активний", "zh-cn": "积极的"},
59
60
  };
package/io-package.json CHANGED
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "telegram-menu",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "news": {
6
+ "0.4.0": {
7
+ "en": "change output value for getState\ncheckbox to disbale Text No Entry found in the settings #34\nsubmenu\n**changed!!!**, states are always set with ack false\nadapter does not restart when telegram restarts #35",
8
+ "de": "ausgabewert ändern für getState\ncheckbox zum Ausbalieren Text Kein Eintrag gefunden in den Einstellungen #34\nunterpositionen\ngeändert! zustände werden immer mit ack false gesetzt\nadapter startet nicht neu, wenn telegramm neu gestartet #35",
9
+ "ru": "изменить значение вывода для getState\ncheckbox на disbale Текст Не найдено записей в настройках #34\nподменю\nизменено! государства всегда установлены с ack false\nадаптер не перезапускается при перезагрузке телеграмм #35",
10
+ "pt": "mudar o valor de saída para getState\ncaixa de seleção para debalar Texto Nenhuma entrada encontrada nas configurações #34\nsubmenu\nmudou! estados são sempre definidos com ack false\nadaptador não reinicia quando o telegrama reinicia #35",
11
+ "nl": "veranderingswaarde voor het krijgen van\ncontrolebox om te disbaliseren Sms No Entry gevonden in de settings 34\nsubmenu\nverander. er zijn altijd valse staten\n#355",
12
+ "fr": "valeur de sortie de changement pour getState\ncheckbox to disbale Texte Aucune entrée trouvée dans les paramètres #34\nsous-menu\nchangé ! les états sont toujours fixés avec ack false\nadaptateur ne redémarre pas lorsque le télégramme redémarre #35",
13
+ "it": "cambio valore di uscita per getState\ncasella di controllo per sbilanciare Testo Nessuna Entrata trovata nelle impostazioni #34\nsottomenu\ncambiato! stati sono sempre impostati con ack falso\nadattatore non riavvia quando il telegramma riavvia #35",
14
+ "es": "cambio de valor de salida para getState\ncheckbox to disbale Texto No Entrada encontrada en la configuración #34\nsubmenú\n¡cambiado! estados siempre están establecidos con ack falso\nadaptador no se reinicia cuando el telegrama se reinicia #35",
15
+ "pl": "zmiana wartości wyjściowej\nskrzynia kontrolna Tekst No Entry znalazł się w ustawieniach #34\nsubmenu\nzmieniło się! wszystkie stany są zawsze ustawione jako fałszywe\nadaptacja nie rozpoczęła się, gdy telegram wznowił #35",
16
+ "uk": "змінити вихідне значення для getState\nчекбокс на дискбаль Текст No Entry знайдено в налаштуваннях #34\nсубмену\nзмінено! держави завжди встановлюються з невірним\nперехідник не перезавантажує при перезапусках телеграм #35",
17
+ "zh-cn": "b. 国家产出价值的变化\n核对箱 第34号活动\n分项\n改为: 各州总是有假肢。\n变通器在电图包中装有第35条时不会再接再厉。"
18
+ },
6
19
  "0.3.0": {
7
20
  "en": "add ack Flag\nCopy-Button to copy User-elements to activ User",
8
21
  "de": "eine Seite hinzufügen\nCopy-Button zu kopieren Benutzerelemente zum Aktivieren",
@@ -80,19 +93,6 @@
80
93
  "pl": "Bug\nTranslat",
81
94
  "uk": "Виправлені помилки\nПереклад",
82
95
  "zh-cn": "固定的黑体\n笔译"
83
- },
84
- "0.0.6": {
85
- "en": "Fixed SetState and GetState\nTranslate",
86
- "de": "Fixed SetState und GetState\nÜbersetzung",
87
- "ru": "Фиксированный SetState и GetState\nПеревести",
88
- "pt": "Fixo SetState e GetState\nTraduzir",
89
- "nl": "Vertaling:\nVertaling:",
90
- "fr": "Fixed SetState and GetState\nTraduire",
91
- "it": "Set fissoState e GetState\nTraduttore",
92
- "es": "SetState y GetState\nTraducir",
93
- "pl": "Fixe SetState and GetState (ang.)\nTranslat",
94
- "uk": "Фіксований SetState і GetState\nПереклад",
95
- "zh-cn": "B. 固定的国家和国\n笔译"
96
96
  }
97
97
  },
98
98
  "titleLang": {
package/lib/js/action.js CHANGED
@@ -1,5 +1,28 @@
1
1
  const sendToTelegram = require("./telegram").sendToTelegram;
2
2
 
3
+ /**
4
+ *
5
+ * @param {String} textToSend Text which should be send to user
6
+ */
7
+ function replaceValues(textToSend, stateVal, _this) {
8
+ const startindex = textToSend.indexOf("change{");
9
+ const match = textToSend.substring(startindex + "change".length + 1, textToSend.indexOf("}", startindex));
10
+ let objChangeValue;
11
+ if (isJSON("{" + match + "}")) objChangeValue = JSON.parse("{" + match + "}");
12
+ else {
13
+ _this.log.error(`There is a error in your input: ` + JSON.stringify(match.replace(/"/g, "'")));
14
+ return false;
15
+ }
16
+ return { valueChange: objChangeValue[String(stateVal)], textToSend: textToSend.substring(0, startindex) };
17
+ }
18
+ function isJSON(str) {
19
+ try {
20
+ JSON.parse(str);
21
+ return true;
22
+ } catch (error) {
23
+ return false;
24
+ }
25
+ }
3
26
  /**
4
27
  * Generate Array
5
28
  * @param {*} val
@@ -127,19 +150,12 @@ async function generateNewObjectStructure(_this, val) {
127
150
  nav: element.value,
128
151
  text: element.text,
129
152
  };
130
- // _this.log.debug("Object " + JSON.stringify(obj));
153
+ _this.log.debug("elementVal " + JSON.stringify(element.value));
131
154
  });
132
155
  return obj;
133
156
  } catch (err) {
134
157
  console.log("Error GenerateNewObjectStructure " + err);
135
158
  }
136
- //
137
- //
138
- // menu.data[user] = obj;
139
- // }
140
-
141
- // _this.log.debug("Menu " + JSON.stringify(menu));
142
- // _this.log.debug("mi " + JSON.stringify(menu.data.Michael));
143
159
  }
144
160
 
145
161
  /**
@@ -223,4 +239,5 @@ module.exports = {
223
239
  wertUebermitteln,
224
240
  generateNewObjectStructure,
225
241
  generateActions,
242
+ replaceValues,
226
243
  };
@@ -1,5 +1,7 @@
1
1
  const sendToTelegram = require("./telegram").sendToTelegram;
2
2
  const idBySelector = require("./action").idBySelector;
3
+ const replaceValues = require("./action").replaceValues;
4
+
3
5
  function getstate(_this, part, userToSend) {
4
6
  try {
5
7
  let text = "";
@@ -17,7 +19,7 @@ function getstate(_this, part, userToSend) {
17
19
  _this.log.debug("Value " + JSON.stringify(value));
18
20
  }
19
21
  if (value) {
20
- const val = JSON.stringify(value.val);
22
+ let val = JSON.stringify(value.val);
21
23
  _this.log.debug("GetValue " + JSON.stringify(value.val));
22
24
  _this.log.debug("Element.text " + JSON.stringify(element.text));
23
25
  let newline = "";
@@ -25,9 +27,18 @@ function getstate(_this, part, userToSend) {
25
27
  newline = "\n";
26
28
  }
27
29
  if (element.text) {
28
- if (element.text.indexOf("&&") != -1)
29
- text += `${element.text.replace("&&", val)}${newline}`;
30
- else text += element.text + " " + val + newline;
30
+ let result = {};
31
+ let textToSend;
32
+ if (element.text.toString().includes("change{")) {
33
+ result = replaceValues(element.text, val, _this);
34
+ val = result["valueChange"];
35
+ _this.log.debug("result " + JSON.stringify(result));
36
+ textToSend = result["textToSend"];
37
+ } else textToSend = element.text;
38
+
39
+ // valueChange ? val = valueChange : val;
40
+ if (textToSend.indexOf("&&") != -1) text += `${textToSend.replace("&&", val)}${newline}`;
41
+ else text += textToSend + " " + val + newline;
31
42
  } else text += `${val} ${newline}`;
32
43
  _this.log.debug("Text " + JSON.stringify(text));
33
44
  }
@@ -1,4 +1,4 @@
1
- function setstate(_this, part, userToSend) {
1
+ function setstate(_this, part, userToSend, valueFromSubmenu, SubmenuValuePriority) {
2
2
  try {
3
3
  const setStateIds = [];
4
4
  part.switch.forEach(
@@ -6,12 +6,14 @@ function setstate(_this, part, userToSend) {
6
6
  /** @type {{ id: string; value: boolean; toggle:boolean; confirm:Boolean; returnText: string }} */ element,
7
7
  ) => {
8
8
  _this.log.debug("Element to set " + JSON.stringify(element));
9
- let ack = true;
9
+ let ack = false;
10
10
  let returnText = element.returnText;
11
11
  if (returnText.includes("ack:true")) {
12
+ _this.log.debug("Set ack: " + JSON.stringify(true));
12
13
  ack = true;
13
14
  returnText = returnText.replace("ack:true", "");
14
15
  } else if (returnText.includes("ack:false")) {
16
+ _this.log.debug("Set sck: " + JSON.stringify(false));
15
17
  ack = false;
16
18
  returnText = element.returnText.replace("ack:false", "").trim();
17
19
  }
@@ -21,21 +23,23 @@ function setstate(_this, part, userToSend) {
21
23
  returnText: returnText,
22
24
  userToSend: userToSend,
23
25
  });
24
-
26
+ _this.log.debug("Ack: " + JSON.stringify(ack));
25
27
  if (element.toggle) {
26
28
  _this.log.debug("Toggle");
27
29
  _this
28
30
  .getForeignStateAsync(element.id)
29
31
  .then((val) => {
30
- _this.log.debug("Value " + JSON.stringify(val));
32
+ _this.log.debug("ValueToggle " + JSON.stringify(val));
31
33
  if (val) _this.setForeignStateAsync(element.id, !val.val, ack);
32
34
  })
33
35
  .catch((e) => {
34
36
  console.log(e);
35
37
  });
36
38
  } else {
37
- _this.log.debug("Value " + JSON.stringify(element.value));
38
- _this.setForeignStateAsync(element.id, element.value, ack);
39
+ let valueToSet;
40
+ SubmenuValuePriority ? (valueToSet = valueFromSubmenu) : (valueToSet = element.value);
41
+ _this.log.debug("Value to Set: " + JSON.stringify(valueToSet));
42
+ _this.setForeignStateAsync(element.id, valueToSet, ack);
39
43
  }
40
44
  },
41
45
  );
@@ -44,6 +48,7 @@ function setstate(_this, part, userToSend) {
44
48
  _this.log.error("Error Switch" + JSON.stringify(error));
45
49
  }
46
50
  }
51
+
47
52
  module.exports = {
48
53
  setstate,
49
54
  };
@@ -0,0 +1,132 @@
1
+ const setstate = require("./setstate").setstate;
2
+ let step = 0;
3
+ let device2Switch = "";
4
+ /**
5
+ *
6
+ * @param {*} _this
7
+ * @param {string} text
8
+ * @param {*} groupData
9
+ * @param {string} userToSend
10
+ * @returns
11
+ */
12
+ function subMenu(_this, text, groupData, userToSend) {
13
+ const splittetText = JSON.stringify(text).split(":");
14
+ const callbackData = splittetText[1];
15
+ _this.log.debug("splittet text2 " + JSON.stringify(splittetText[2]));
16
+ _this.log.debug("callback: " + JSON.stringify(callbackData));
17
+ _this.log.debug("devicetoswitch: " + JSON.stringify(device2Switch));
18
+ _this.log.debug("text: " + JSON.stringify(text));
19
+
20
+ if (callbackData === "yes-no") {
21
+ const keyboard = {
22
+ inline_keyboard: [
23
+ [
24
+ {
25
+ text: "Yes",
26
+ callback_data: "menu:yes",
27
+ },
28
+ {
29
+ text: "No",
30
+ callback_data: "menu:no",
31
+ },
32
+ ],
33
+ ],
34
+ };
35
+ return ["Wähle eine Option", JSON.stringify(keyboard), device2Switch];
36
+ } else if (callbackData === "yes") {
37
+ setstate(_this, groupData[device2Switch], userToSend, true);
38
+ } else if (callbackData === "no") {
39
+ setstate(_this, groupData[device2Switch], userToSend, false);
40
+ } else if (callbackData === "on-off") {
41
+ const keyboard = {
42
+ inline_keyboard: [
43
+ [
44
+ {
45
+ text: "On",
46
+ callback_data: "menu:on:",
47
+ },
48
+ {
49
+ text: "Off",
50
+ callback_data: "menu:off:",
51
+ },
52
+ ],
53
+ ],
54
+ };
55
+ device2Switch = splittetText[2];
56
+ return ["Wähle eine Option", JSON.stringify(keyboard), device2Switch];
57
+ } else if (callbackData === "on") {
58
+ setstate(_this, groupData[device2Switch], userToSend, true, true);
59
+ } else if (callbackData === "off") {
60
+ setstate(_this, groupData[device2Switch], userToSend, false, true);
61
+ } else if (!text.includes("submenu") && callbackData.includes("percent")) {
62
+ step = parseInt(callbackData.replace("percent", ""));
63
+ let rowEntrys = 0;
64
+ let menu = [];
65
+ const keyboard = {
66
+ inline_keyboard: [],
67
+ };
68
+ for (let i = 100; i >= 0; i -= step) {
69
+ menu.push({
70
+ text: `${i}%`,
71
+ callback_data: `submenu:percent${step}:${i}:`,
72
+ });
73
+ if (i != 0 && i - step < 0)
74
+ menu.push({
75
+ text: `0%`,
76
+ callback_data: `submenu:percent${step}:${0}:`,
77
+ });
78
+ // _this.log.debug("menu " + JSON.stringify(menu));
79
+ // _this.log.debug("keyboard " + JSON.stringify(keyboard.inline_keyboard));
80
+ rowEntrys++;
81
+ if (rowEntrys == 8) {
82
+ // @ts-ignore
83
+ keyboard.inline_keyboard.push(menu);
84
+ menu = [];
85
+ rowEntrys = 0;
86
+ }
87
+ }
88
+ // @ts-ignore
89
+ if (rowEntrys != 0) keyboard.inline_keyboard.push(menu);
90
+
91
+ device2Switch = splittetText[2];
92
+ return ["Welcher Wert soll gesetzt werden?", JSON.stringify(keyboard), device2Switch];
93
+ } else if (text.includes(`submenu:percent${step}`)) {
94
+ const value = parseInt(text.split(":")[2]);
95
+ setstate(_this, groupData[device2Switch], userToSend, value, true);
96
+ } else if (!text.includes("submenu") && callbackData.includes("number")) {
97
+ const splittedData = callbackData.replace("number", "").split("-");
98
+ let rowEntrys = 0;
99
+ let menu = [];
100
+ const keyboard = {
101
+ inline_keyboard: [],
102
+ };
103
+ let unit = "";
104
+ if (splittedData[3] != "") unit = splittedData[3];
105
+ for (let i = parseInt(splittedData[1]); i >= parseInt(splittedData[0]); i -= parseInt(splittedData[2])) {
106
+ menu.push({
107
+ text: `${i}${unit}`,
108
+ callback_data: `submenu:${callbackData}:${i}:`,
109
+ });
110
+ _this.log.debug("menu " + JSON.stringify(menu));
111
+ _this.log.debug("keyboard " + JSON.stringify(keyboard.inline_keyboard));
112
+ rowEntrys++;
113
+ if (rowEntrys == 8) {
114
+ // @ts-ignore
115
+ keyboard.inline_keyboard.push(menu);
116
+ menu = [];
117
+ rowEntrys = 0;
118
+ }
119
+ }
120
+ // @ts-ignore
121
+ if (rowEntrys != 0) keyboard.inline_keyboard.push(menu);
122
+ device2Switch = splittetText[2];
123
+ return ["Welcher Wert soll gesetzt werden?", JSON.stringify(keyboard), device2Switch];
124
+ } else if (text.includes(`submenu:${callbackData}`)) {
125
+ const value = parseInt(text.split(":")[2]);
126
+ setstate(_this, groupData[device2Switch], userToSend, value, true);
127
+ _this.log.debug("cal " + JSON.stringify(callbackData));
128
+ }
129
+ }
130
+ module.exports = {
131
+ subMenu: subMenu,
132
+ };
@@ -51,7 +51,16 @@ function sendToTelegram(
51
51
  );
52
52
  }
53
53
  }
54
+ function sendToTelegramSubmenu(_this, name, text, keyboard, instance = "telegram.0") {
55
+ _this.sendTo(instance, "send", {
56
+ // chatId: chatId,
57
+ name: name,
58
+ text: text,
59
+ reply_markup: keyboard,
60
+ });
61
+ }
54
62
 
55
63
  module.exports = {
56
64
  sendToTelegram,
65
+ sendToTelegramSubmenu,
57
66
  };
package/main.js CHANGED
@@ -12,9 +12,11 @@ const sendToTelegram = require("./lib/js/telegram").sendToTelegram;
12
12
  const editArrayButtons = require("./lib/js/action").editArrayButtons;
13
13
  const generateNewObjectStructure = require("./lib/js/action").generateNewObjectStructure;
14
14
  const generateActions = require("./lib/js/action").generateActions;
15
+ const replaceValues = require("./lib/js/action").replaceValues;
15
16
  const setstate = require("./lib/js/setstate").setstate;
16
17
  const getstate = require("./lib/js/getstate").getstate;
17
-
18
+ const subMenu = require("./lib/js/subMenu").subMenu;
19
+ const sendToTelegramSubmenu = require("./lib/js/telegram").sendToTelegramSubmenu;
18
20
  // const lichtAn = require("./lib/js/action").lichtAn;
19
21
  // const wertUebermitteln = require("./lib/js/action").wertUebermitteln;
20
22
 
@@ -22,7 +24,6 @@ let timeouts = [];
22
24
  let timeoutKey = 0;
23
25
  let setStateIds;
24
26
  let setStateIdsToListenTo;
25
- let restartAdapter = false;
26
27
 
27
28
  // Load your modules here, e.g.:
28
29
  // const fs = require("fs");
@@ -58,6 +59,7 @@ class TelegramMenu extends utils.Adapter {
58
59
  const checkbox = this.config.checkbox;
59
60
  const one_time_keyboard = checkbox["oneTiKey"];
60
61
  const resize_keyboard = checkbox["resKey"];
62
+ const checkboxNoEntryFound = checkbox["checkboxNoValueFound"];
61
63
  const userList = this.config.users;
62
64
  const startsides = this.config.startsides;
63
65
  let token = this.config.tokenGrafana;
@@ -102,7 +104,8 @@ class TelegramMenu extends utils.Adapter {
102
104
  const returnValue = generateActions(_this, action[name], menu.data[name]);
103
105
  menu.data[name] = returnValue?.obj;
104
106
  setStateIds = returnValue?.ids;
105
- if (setStateIds && setStateIds?.length > 0) _setForeignStatesAsync(setStateIds, _this);
107
+ if (setStateIds && setStateIds?.length > 0)
108
+ _subscribeForeignStatesAsync(setStateIds, _this);
106
109
  this.log.debug("SetForeignStates: " + JSON.stringify(setStateIds));
107
110
  this.log.debug("Name " + JSON.stringify(name));
108
111
  this.log.debug("Array Buttons: " + JSON.stringify(value));
@@ -113,29 +116,26 @@ class TelegramMenu extends utils.Adapter {
113
116
  }
114
117
  this.log.debug("Checkbox " + JSON.stringify(checkbox));
115
118
 
116
- if (!restartAdapter) {
117
- try {
118
- this.log.debug("GroupList " + JSON.stringify(userList));
119
- userList.forEach((group) => {
120
- this.log.debug("Group " + JSON.stringify(group));
121
- const startside = [startsides[group]].toString();
122
- if (userActiveCheckbox[group])
123
- usersInGroup[group].forEach((user) => {
124
- sendToTelegram(
125
- _this,
126
- user,
127
- menu.data[group][startside].text,
128
- menu.data[group][startside].nav,
129
- instanceTelegram,
130
- resize_keyboard,
131
- one_time_keyboard,
132
- );
133
- });
134
- });
135
- } catch (error) {
136
- console.log("Error read UserList" + error);
137
- }
138
- restartAdapter = false;
119
+ try {
120
+ this.log.debug("GroupList " + JSON.stringify(userList));
121
+ userList.forEach((group) => {
122
+ this.log.debug("Group " + JSON.stringify(group));
123
+ const startside = [startsides[group]].toString();
124
+ if (userActiveCheckbox[group])
125
+ usersInGroup[group].forEach((user) => {
126
+ sendToTelegram(
127
+ _this,
128
+ user,
129
+ menu.data[group][startside].text,
130
+ menu.data[group][startside].nav,
131
+ instanceTelegram,
132
+ resize_keyboard,
133
+ one_time_keyboard,
134
+ );
135
+ });
136
+ });
137
+ } catch (error) {
138
+ console.log("Error read UserList" + error);
139
139
  }
140
140
  }
141
141
  let oldValue;
@@ -146,10 +146,10 @@ class TelegramMenu extends utils.Adapter {
146
146
  if (state && typeof state.val === "string" && state.val != "" && id == telegramID) {
147
147
  const value = state.val;
148
148
  const user = value.slice(1, value.indexOf("]"));
149
- const toDo = value.slice(value.indexOf("]") + 1, value.length);
149
+ const calledValue = value.slice(value.indexOf("]") + 1, value.length);
150
150
  this.log.debug("Value: " + JSON.stringify(value));
151
151
  this.log.debug("User: " + JSON.stringify(user));
152
- this.log.debug("Todo: " + JSON.stringify(toDo));
152
+ this.log.debug("Todo: " + JSON.stringify(calledValue));
153
153
 
154
154
  userToSend = null;
155
155
 
@@ -158,38 +158,47 @@ class TelegramMenu extends utils.Adapter {
158
158
  usersInGroup[key].includes(user),
159
159
  );
160
160
  this.log.debug("Group with User " + JSON.stringify(groupWithUser));
161
- const nav = menu.data[groupWithUser];
161
+ const groupData = menu.data[groupWithUser];
162
162
  userToSend = user;
163
163
 
164
- this.log.debug("Nav " + JSON.stringify(nav));
164
+ this.log.debug("Nav " + JSON.stringify(groupData));
165
165
  this.log.debug("Menu " + JSON.stringify(menu.data));
166
- if (nav[toDo] && userToSend && groupWithUser && userActiveCheckbox[groupWithUser]) {
167
- const part = nav[toDo];
166
+ if (
167
+ groupData[calledValue] &&
168
+ userToSend &&
169
+ groupWithUser &&
170
+ userActiveCheckbox[groupWithUser]
171
+ ) {
172
+ const part = groupData[calledValue];
168
173
  this.log.debug("Part " + JSON.stringify(part));
169
174
  // Navigation
170
175
  if (part.nav) {
171
176
  this.log.debug("User to send: " + JSON.stringify(userToSend));
172
- this.log.debug("Todo " + JSON.stringify(toDo));
177
+ this.log.debug("Todo " + JSON.stringify(calledValue));
173
178
  this.log.debug("Part.nav: " + JSON.stringify(part.nav));
174
- if (userToSend)
175
- sendToTelegram(
176
- this,
177
- userToSend,
178
- part.text,
179
- part.nav,
180
- instanceTelegram,
181
- resize_keyboard,
182
- one_time_keyboard,
183
- );
179
+ //TODO -
180
+ if (JSON.stringify(part.nav).includes("menu")) {
181
+ this.log.debug("Submenu");
182
+ callSubMenu(this, part.nav, groupData, userToSend);
183
+ } else {
184
+ if (userToSend)
185
+ sendToTelegram(
186
+ this,
187
+ userToSend,
188
+ part.text,
189
+ part.nav,
190
+ instanceTelegram,
191
+ resize_keyboard,
192
+ one_time_keyboard,
193
+ );
194
+ }
184
195
  }
185
196
  // Schalten
186
- if (part.switch) {
197
+ else if (part.switch) {
187
198
  setStateIdsToListenTo = setstate(_this, part, userToSend);
188
- }
189
- if (part.getData) {
199
+ } else if (part.getData) {
190
200
  getstate(_this, part, userToSend);
191
- }
192
- if (part.sendPic) {
201
+ } else if (part.sendPic) {
193
202
  try {
194
203
  this.log.debug("Send Picture");
195
204
 
@@ -221,9 +230,11 @@ class TelegramMenu extends utils.Adapter {
221
230
  this.log.error("Error :" + JSON.stringify(e));
222
231
  }
223
232
  }
233
+ } else if (calledValue.startsWith("menu") || calledValue.startsWith("submenu")) {
234
+ callSubMenu(this, calledValue, groupData, userToSend);
224
235
  } else {
225
236
  if (typeof userToSend == "string")
226
- sendToTelegram(this, userToSend, textNoEntryFound);
237
+ if (checkboxNoEntryFound) sendToTelegram(this, userToSend, textNoEntryFound);
227
238
  }
228
239
  // Auf Setstate reagieren und Wert schicken
229
240
  } else if (
@@ -237,28 +248,28 @@ class TelegramMenu extends utils.Adapter {
237
248
  this.log.debug("Send Value " + JSON.stringify(element));
238
249
  if (element.confirm != "false") {
239
250
  this.log.debug("User " + JSON.stringify(element.userToSend));
240
- let textToSend = element.returnText;
251
+
252
+ let textToSend = "";
253
+ textToSend = element.returnText;
241
254
  // Wenn eine Rückkgabe des Value an den User nicht gewünscht ist soll value durch einen leeren String ersetzt werden
242
- let value;
255
+ let value = "";
243
256
  // Change set value in another Value, like true => on, false => off
244
- let objChangeValue = {};
257
+ let result = {};
245
258
  let valueChange = "";
246
259
  if (textToSend.toString().includes("change{")) {
247
- const startindex = textToSend.indexOf("change{");
248
- const match = textToSend.substring(
249
- startindex + "change".length + 1,
250
- textToSend.indexOf("}", startindex),
251
- );
252
- objChangeValue = JSON.parse("{" + match + "}");
253
- valueChange = objChangeValue[String(state.val)];
254
- textToSend = textToSend.substring(0, startindex);
260
+ result = replaceValues(textToSend, state.val, this);
261
+ if (result) {
262
+ textToSend = result["textToSend"];
263
+ valueChange = result["valueChange"];
264
+ }
255
265
  }
256
- textToSend?.toString().includes("{novalue}")
257
- ? (value = "")
258
- : (value = state.val);
259
- textToSend = textToSend.replace("{novalue}", "");
266
+ if (textToSend?.toString().includes("{novalue}")) {
267
+ value = "";
268
+ textToSend = textToSend.replace("{novalue}", "");
269
+ } else if (state.val || state.val == false) value = state.val?.toString();
270
+
260
271
  valueChange ? (value = valueChange) : value;
261
- textToSend.indexOf("&amp;&amp;") != -1
272
+ textToSend.toString().indexOf("&amp;&amp;") != -1
262
273
  ? (textToSend = textToSend.replace("&amp;&amp;", value))
263
274
  : (textToSend += " " + value);
264
275
  sendToTelegram(this, element.userToSend, textToSend);
@@ -272,11 +283,6 @@ class TelegramMenu extends utils.Adapter {
272
283
 
273
284
  if (state && id == `${instanceTelegram}.info.connection`) {
274
285
  this.log.debug("Oldvalue " + JSON.stringify(oldValue));
275
- if (!oldValue) {
276
- this.log.debug("Restart Adapter Telegram Menu");
277
- restartAdapter = true;
278
- this.restart();
279
- }
280
286
  oldValue = state.val;
281
287
  if (!state.val) telegramAktiv = false;
282
288
  }
@@ -286,36 +292,27 @@ class TelegramMenu extends utils.Adapter {
286
292
  });
287
293
  }
288
294
  });
295
+ /**
296
+ *
297
+ * @param {*} _this
298
+ * @param {*} part
299
+ * @param {*} groupData
300
+ * @param {string} userToSend
301
+ */
302
+ function callSubMenu(_this, part, groupData, userToSend) {
303
+ const subMenuData = subMenu(_this, part, groupData, userToSend);
304
+ _this.log.debug("SubMenuData " + JSON.stringify(subMenuData));
305
+ if (subMenuData && subMenuData[0]) sendToTelegramSubmenu(_this, userToSend, subMenuData[0], subMenuData[1]);
306
+ }
289
307
 
290
- /*
291
- For every state in the system there has to be also an object of type state
292
- Here a simple template for a boolean variable named "testVariable"
293
- Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables
294
- */
295
- // await this.setObjectNotExistsAsync("testVariable", {
296
- // type: "state",
297
- // common: {
298
- // name: "testVariable",
299
- // type: "boolean",
300
- // role: "indicator",
301
- // read: true,
302
- // write: true,
303
- // },
304
- // native: {},
305
- // });
306
-
307
- // In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above.
308
- // this.subscribeStates("testVariable");
309
- // You can also add a subscription for multiple states. The following line watches all states starting with "lights."
310
- // this.subscribeStates("lights.*");
311
- // Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system:
312
308
  /**
313
309
  *
314
310
  * @param {Array} array
315
311
  * @param {*} _this
316
312
  */
317
- function _setForeignStatesAsync(array, _this) {
313
+ function _subscribeForeignStatesAsync(array, _this) {
318
314
  array.forEach((element) => {
315
+ _this.log.debug("Subscribe " + JSON.stringify(element));
319
316
  _this.subscribeForeignStatesAsync(element);
320
317
  });
321
318
  }
@@ -323,27 +320,6 @@ class TelegramMenu extends utils.Adapter {
323
320
  this.subscribeForeignStatesAsync("telegram.0.communicate.request");
324
321
  this.subscribeForeignStatesAsync(telegramID);
325
322
  this.subscribeForeignStatesAsync(`${instanceTelegram}.info.connection`);
326
-
327
- /*
328
- setState examples
329
- you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd)
330
- */
331
- // the variable testVariable is set to true as command (ack=false)
332
- // await this.setStateAsync("testVariable", true);
333
-
334
- // same thing, but the value is flagged "ack"
335
- // ack should be always set to true if the value is received from or acknowledged from the target system
336
- // 'await this.setStateAsync("testVariable", { val: true, ack: true });
337
-
338
- // same thing, but the state is deleted after 30s (getState will return null afterwards)
339
- // 'await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 });
340
-
341
- // examples for the checkPassword/checkGroup functions
342
- // let result = await this.checkPasswordAsync("admin", "iobroker");
343
- // this.log.info("check user admin pw iobroker: " + result);
344
-
345
- // result = await this.checkGroupAsync("admin", "admin");
346
- // this.log.info("check group user admin group admin: " + result);
347
323
  }
348
324
 
349
325
  /**
@@ -363,45 +339,6 @@ class TelegramMenu extends utils.Adapter {
363
339
  }
364
340
  }
365
341
 
366
- // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor.
367
- // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`.
368
- // /**
369
- // * Is called if a subscribed object changes
370
- // * @param {string} id
371
- // * @param {ioBroker.Object | null | undefined} obj
372
- // */
373
- // onObjectChange(id, obj) {
374
- // if (obj) {
375
- // // The object was changed
376
- // this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`);
377
- // } else {
378
- // // The object was deleted
379
- // this.log.info(`object ${id} deleted`);
380
- // }
381
- // }
382
-
383
- // /**
384
- // * Is called if a subscribed state changes
385
- // * @param {string} id
386
- // * @param {ioBroker.State | null | undefined} state
387
- // */
388
- // onStateChange(id, state) {
389
- // if (state) {
390
-
391
- // // The state was changed
392
- // this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
393
- // } else {
394
- // // The state was deleted
395
- // this.log.info(`state ${id} deleted`);
396
- // }
397
- // }
398
-
399
- // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor.
400
- // /**
401
- // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ...
402
- // * Using this method requires "common.messagebox" property to be set to true in io-package.json
403
- // * @param {ioBroker.Message} obj
404
- // */
405
342
  onMessage(obj) {
406
343
  this.log.debug(obj);
407
344
  if (typeof obj === "object" && obj.message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.telegram-menu",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Easily create Telegram Menus",
5
5
  "author": {
6
6
  "name": "MiRo1310",