iobroker.telegram-menu 2.4.0 → 2.4.2

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.
Files changed (158) hide show
  1. package/README.md +8 -1
  2. package/admin/build/index.js +1 -1
  3. package/admin/build/index.js.map +3 -3
  4. package/build/app/action.js +4 -3
  5. package/build/app/action.js.map +2 -2
  6. package/build/app/echarts.js.map +1 -1
  7. package/build/app/getstate.js +8 -6
  8. package/build/app/getstate.js.map +2 -2
  9. package/build/app/idBySelector.js.map +2 -2
  10. package/build/app/telegram.js +5 -1
  11. package/build/app/telegram.js.map +2 -2
  12. package/build/lib/appUtils.js.map +2 -2
  13. package/build/lib/exchangeValue.js +8 -4
  14. package/build/lib/exchangeValue.js.map +2 -2
  15. package/build/lib/string.js +7 -1
  16. package/build/lib/string.js.map +2 -2
  17. package/build/types/types.js.map +1 -1
  18. package/io-package.json +27 -27
  19. package/package.json +5 -5
  20. package/build/.eslintrc.js +0 -70
  21. package/build/.eslintrc.js.map +0 -1
  22. package/build/build/src/app/action.js +0 -447
  23. package/build/build/src/app/adapterStartMenuSend.js +0 -37
  24. package/build/build/src/app/backMenu.js +0 -70
  25. package/build/build/src/app/botAction.js +0 -25
  26. package/build/build/src/app/connection.js +0 -19
  27. package/build/build/src/app/createState.js +0 -19
  28. package/build/build/src/app/dynamicSwitch.js +0 -51
  29. package/build/build/src/app/dynamicValue.js +0 -64
  30. package/build/build/src/app/echarts.js +0 -45
  31. package/build/build/src/app/getstate.js +0 -157
  32. package/build/build/src/app/global.js +0 -59
  33. package/build/build/src/app/httpRequest.js +0 -64
  34. package/build/build/src/app/jsonTable.js +0 -147
  35. package/build/build/src/app/logging.js +0 -13
  36. package/build/build/src/app/messageIds.js +0 -88
  37. package/build/build/src/app/processData.js +0 -208
  38. package/build/build/src/app/sendNav.js +0 -30
  39. package/build/build/src/app/sendpic.js +0 -69
  40. package/build/build/src/app/setstate.js +0 -126
  41. package/build/build/src/app/shoppingList.js +0 -72
  42. package/build/build/src/app/subMenu.js +0 -361
  43. package/build/build/src/app/subscribeStates.js +0 -25
  44. package/build/build/src/app/telegram.js +0 -101
  45. package/build/build/src/lib/string.js +0 -28
  46. package/build/build/src/lib/time.js +0 -23
  47. package/build/build/src/lib/utilities.js +0 -263
  48. package/build/build/src/lib/utils.js +0 -13
  49. package/build/build/src/main.js +0 -402
  50. package/build/io-package.json +0 -324
  51. package/build/src/app/action.js +0 -239
  52. package/build/src/app/action.js.map +0 -1
  53. package/build/src/app/adapterManager.js +0 -12
  54. package/build/src/app/adapterManager.js.map +0 -1
  55. package/build/src/app/adapterStartMenuSend.js +0 -36
  56. package/build/src/app/adapterStartMenuSend.js.map +0 -1
  57. package/build/src/app/backMenu.js +0 -81
  58. package/build/src/app/backMenu.js.map +0 -1
  59. package/build/src/app/botAction.js +0 -25
  60. package/build/src/app/botAction.js.map +0 -1
  61. package/build/src/app/configVariables.js +0 -32
  62. package/build/src/app/configVariables.js.map +0 -1
  63. package/build/src/app/connection.js +0 -20
  64. package/build/src/app/connection.js.map +0 -1
  65. package/build/src/app/createState.js +0 -19
  66. package/build/src/app/createState.js.map +0 -1
  67. package/build/src/app/dynamicSwitch.js +0 -52
  68. package/build/src/app/dynamicSwitch.js.map +0 -1
  69. package/build/src/app/dynamicSwitchMenu.js +0 -52
  70. package/build/src/app/dynamicSwitchMenu.js.map +0 -1
  71. package/build/src/app/dynamicValue.js +0 -52
  72. package/build/src/app/dynamicValue.js.map +0 -1
  73. package/build/src/app/echarts.js +0 -33
  74. package/build/src/app/echarts.js.map +0 -1
  75. package/build/src/app/getstate.js +0 -122
  76. package/build/src/app/getstate.js.map +0 -1
  77. package/build/src/app/global.js +0 -8
  78. package/build/src/app/global.js.map +0 -1
  79. package/build/src/app/httpRequest.js +0 -55
  80. package/build/src/app/httpRequest.js.map +0 -1
  81. package/build/src/app/jsonTable.js +0 -147
  82. package/build/src/app/jsonTable.js.map +0 -1
  83. package/build/src/app/logging.js +0 -22
  84. package/build/src/app/logging.js.map +0 -1
  85. package/build/src/app/messageIds.js +0 -89
  86. package/build/src/app/messageIds.js.map +0 -1
  87. package/build/src/app/processData.js +0 -153
  88. package/build/src/app/processData.js.map +0 -1
  89. package/build/src/app/sendNav.js +0 -26
  90. package/build/src/app/sendNav.js.map +0 -1
  91. package/build/src/app/sendpic.js +0 -66
  92. package/build/src/app/sendpic.js.map +0 -1
  93. package/build/src/app/sentry.js +0 -18
  94. package/build/src/app/sentry.js.map +0 -1
  95. package/build/src/app/setStateIdsToListenTo.js +0 -17
  96. package/build/src/app/setStateIdsToListenTo.js.map +0 -1
  97. package/build/src/app/setstate.js +0 -114
  98. package/build/src/app/setstate.js.map +0 -1
  99. package/build/src/app/shoppingList.js +0 -74
  100. package/build/src/app/shoppingList.js.map +0 -1
  101. package/build/src/app/subMenu.js +0 -237
  102. package/build/src/app/subMenu.js.map +0 -1
  103. package/build/src/app/subscribeStates.js +0 -17
  104. package/build/src/app/subscribeStates.js.map +0 -1
  105. package/build/src/app/telegram.js +0 -83
  106. package/build/src/app/telegram.js.map +0 -1
  107. package/build/src/app/validateMenus.js +0 -30
  108. package/build/src/app/validateMenus.js.map +0 -1
  109. package/build/src/config/config.js +0 -100
  110. package/build/src/config/config.js.map +0 -1
  111. package/build/src/lib/appUtils.js +0 -126
  112. package/build/src/lib/appUtils.js.map +0 -1
  113. package/build/src/lib/appUtilsString.js +0 -13
  114. package/build/src/lib/appUtilsString.js.map +0 -1
  115. package/build/src/lib/json.js +0 -37
  116. package/build/src/lib/json.js.map +0 -1
  117. package/build/src/lib/math.js +0 -17
  118. package/build/src/lib/math.js.map +0 -1
  119. package/build/src/lib/object.js +0 -10
  120. package/build/src/lib/object.js.map +0 -1
  121. package/build/src/lib/splitValues.js +0 -35
  122. package/build/src/lib/splitValues.js.map +0 -1
  123. package/build/src/lib/string.js +0 -121
  124. package/build/src/lib/string.js.map +0 -1
  125. package/build/src/lib/time.js +0 -57
  126. package/build/src/lib/time.js.map +0 -1
  127. package/build/src/lib/utilities.js +0 -111
  128. package/build/src/lib/utilities.js.map +0 -1
  129. package/build/src/lib/utils.js +0 -37
  130. package/build/src/lib/utils.js.map +0 -1
  131. package/build/src/main.js +0 -332
  132. package/build/src/main.js.map +0 -1
  133. package/build/src/test/setup.js +0 -12
  134. package/build/src/test/setup.js.map +0 -1
  135. package/build/src/types/types.js +0 -3
  136. package/build/src/types/types.js.map +0 -1
  137. package/build/test/integration.js +0 -6
  138. package/build/test/integration.js.map +0 -1
  139. package/build/test/mocha.setup.js +0 -14
  140. package/build/test/mocha.setup.js.map +0 -1
  141. package/build/test/package.js +0 -6
  142. package/build/test/package.js.map +0 -1
  143. package/build/test/setup.js +0 -12
  144. package/build/test/setup.js.map +0 -1
  145. package/build/test/test/appUtils.test.js +0 -519
  146. package/build/test/test/appUtils.test.js.map +0 -1
  147. package/build/test/test/appUtilsString.test.js +0 -16
  148. package/build/test/test/appUtilsString.test.js.map +0 -1
  149. package/build/test/test/math.test.js +0 -33
  150. package/build/test/test/math.test.js.map +0 -1
  151. package/build/test/test/object.test.js +0 -66
  152. package/build/test/test/object.test.js.map +0 -1
  153. package/build/test/test/string.test.js +0 -385
  154. package/build/test/test/string.test.js.map +0 -1
  155. package/build/test/test/time.test.js +0 -186
  156. package/build/test/test/time.test.js.map +0 -1
  157. package/build/test/test/utils.test.js +0 -115
  158. package/build/test/test/utils.test.js.map +0 -1
@@ -1,263 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.processTimeIdLc = exports.checkStatusInfo = void 0;
5
- exports.checkTypeOfId = checkTypeOfId;
6
- exports.changeValue = changeValue;
7
- exports.decomposeText = decomposeText;
8
- const main_1 = require("../main");
9
- const global_1 = require("../app/global");
10
- const string_1 = require("./string");
11
- const logging_1 = require("../app/logging");
12
- const time_1 = require("./time");
13
- const exchangeValue = (textToSend, stateVal) => {
14
- const { startindex, endindex } = decomposeText(textToSend, 'change{', '}');
15
- let match = textToSend.substring(startindex + 'change'.length + 1, textToSend.indexOf('}', startindex));
16
- let objChangeValue;
17
- match = (0, string_1.replaceAll)(match, "'", '"');
18
- // TODO check type
19
- const { json, isValidJson } = (0, string_1.parseJSON)(`{${match}}`);
20
- if (isValidJson) {
21
- objChangeValue = json;
22
- }
23
- else {
24
- main_1._this.log.error(`There is a error in your input: ${match}`);
25
- return false;
26
- }
27
- let newValue;
28
- objChangeValue[String(stateVal)] ? (newValue = objChangeValue[String(stateVal)]) : (newValue = stateVal);
29
- return {
30
- valueChange: newValue,
31
- textToSend: textToSend.substring(0, startindex) + textToSend.substring(endindex + 1),
32
- };
33
- };
34
- function decomposeText(text, searchValue, secondValue) {
35
- const startindex = text.indexOf(searchValue);
36
- const endindex = text.indexOf(secondValue, startindex);
37
- const substring = text.substring(startindex, endindex + secondValue.length);
38
- const textWithoutSubstring = text.replace(substring, '').trim();
39
- return {
40
- startindex: startindex,
41
- endindex: endindex,
42
- substring: substring,
43
- textWithoutSubstring: textWithoutSubstring,
44
- };
45
- }
46
- function changeValue(textToSend, val) {
47
- if (textToSend.includes('change{')) {
48
- const result = exchangeValue(textToSend, val);
49
- if (!result) {
50
- return { textToSend: '', val: '', error: true };
51
- }
52
- if (typeof result === 'boolean') {
53
- return { textToSend: '', val: '', error: true };
54
- }
55
- return { textToSend: result.textToSend, val: result.valueChange, error: false };
56
- }
57
- return { textToSend: '', val: '', error: true };
58
- }
59
- const processTimeIdLc = async (textToSend, id) => {
60
- let key = '';
61
- const { substring } = decomposeText(textToSend, '{time.', '}');
62
- const array = substring.split(',');
63
- let changedSubstring = substring;
64
- changedSubstring = changedSubstring.replace(array[0], '');
65
- if (array[0].includes('lc')) {
66
- key = 'lc';
67
- }
68
- else if (array[0].includes('ts')) {
69
- key = 'ts';
70
- }
71
- let idFromText = '';
72
- if (!id) {
73
- if (!changedSubstring.includes('id:')) {
74
- main_1._this.log.debug(`Error processTimeIdLc: id not found in: ${changedSubstring}`);
75
- return;
76
- }
77
- if (array[2]) {
78
- idFromText = array[2].replace('id:', '').replace('}', '').replace(/'/g, '');
79
- changedSubstring = changedSubstring.replace(array[2], '').replace(/,/g, '');
80
- }
81
- }
82
- if (!id && !idFromText) {
83
- return;
84
- }
85
- const value = await main_1._this.getForeignStateAsync(id || idFromText);
86
- let timeValue;
87
- let timeStringUser;
88
- if (key && value) {
89
- timeStringUser = changedSubstring.replace(',(', '').replace(')', '').replace('}', '');
90
- timeValue = value[key];
91
- }
92
- if (!timeValue) {
93
- return;
94
- }
95
- const timeObj = new Date(timeValue);
96
- const milliseconds = timeObj.getMilliseconds();
97
- const seconds = timeObj.getSeconds();
98
- const minutes = timeObj.getMinutes();
99
- const hours = timeObj.getHours();
100
- const day = timeObj.getDate();
101
- const month = timeObj.getMonth() + 1;
102
- const year = timeObj.getFullYear();
103
- const time = {
104
- ms: milliseconds < 10 ? `00${milliseconds}` : milliseconds < 100 ? `0${milliseconds}` : milliseconds,
105
- s: seconds < 10 ? `0${seconds}` : seconds,
106
- m: minutes < 10 ? `0${minutes}` : minutes,
107
- h: hours < 10 ? `0${hours}` : hours,
108
- d: day < 10 ? `0${day}` : day,
109
- mo: month < 10 ? `0${month}` : month,
110
- y: year,
111
- };
112
- if (timeStringUser) {
113
- if (timeStringUser.includes('sss')) {
114
- timeStringUser = timeStringUser.replace('sss', time.ms.toString());
115
- }
116
- if (timeStringUser.includes('ss')) {
117
- timeStringUser = timeStringUser.replace('ss', time.s.toString());
118
- }
119
- if (timeStringUser.includes('mm')) {
120
- timeStringUser = timeStringUser.replace('mm', time.m.toString());
121
- }
122
- if (timeStringUser.includes('hh')) {
123
- timeStringUser = timeStringUser.replace('hh', time.h.toString());
124
- }
125
- if (timeStringUser.includes('DD')) {
126
- timeStringUser = timeStringUser.replace('DD', time.d.toString());
127
- }
128
- if (timeStringUser.includes('MM')) {
129
- timeStringUser = timeStringUser.replace('MM', time.mo.toString());
130
- }
131
- if (timeStringUser.includes('YYYY')) {
132
- timeStringUser = timeStringUser.replace('YYYY', time.y.toString());
133
- }
134
- if (timeStringUser.includes('YY')) {
135
- timeStringUser = timeStringUser.replace('YY', time.y.toString().slice(-2));
136
- }
137
- timeStringUser = timeStringUser.replace('(', '').replace(')', '');
138
- return textToSend.replace(substring, timeStringUser);
139
- }
140
- return textToSend;
141
- };
142
- exports.processTimeIdLc = processTimeIdLc;
143
- const checkStatus = async (text, processTimeValue) => {
144
- try {
145
- const substring = decomposeText(text, '{status:', '}').substring;
146
- let id, valueChange;
147
- main_1._this.log.debug(`Substring ${substring}`);
148
- if (substring.includes("status:'id':")) {
149
- id = substring.split(':')[2].replace("'}", '').replace(/'/g, '').replace(/}/g, '');
150
- valueChange = substring.split(':')[3] ? substring.split(':')[3].replace('}', '') !== 'false' : true;
151
- }
152
- else {
153
- id = substring.split(':')[1].replace("'}", '').replace(/'/g, '').replace(/}/g, '');
154
- valueChange = substring.split(':')[2] ? substring.split(':')[2].replace('}', '') !== 'false' : true;
155
- }
156
- const stateValue = await main_1._this.getForeignStateAsync(id);
157
- if (!stateValue) {
158
- main_1._this.log.debug(`State not found: ${id}`);
159
- return '';
160
- }
161
- if (text.includes('{time}') && processTimeValue) {
162
- text = text.replace(substring, '');
163
- if (stateValue.val && typeof stateValue.val === 'string') {
164
- return processTimeValue(text, stateValue).replace(stateValue.val, '');
165
- }
166
- }
167
- if (!(0, global_1.isDefined)(stateValue.val)) {
168
- main_1._this.log.debug(`State Value is undefined: ${id}`);
169
- return text.replace(substring, '');
170
- }
171
- if (!valueChange) {
172
- return text.replace(substring, stateValue.val.toString());
173
- }
174
- const changedResult = changeValue(text, stateValue.val);
175
- let newValue;
176
- if (changedResult) {
177
- text = changedResult.textToSend;
178
- newValue = changedResult.val;
179
- }
180
- else {
181
- newValue = stateValue.val;
182
- }
183
- main_1._this.log.debug(`CheckStatus Text: ${text} Substring: ${substring} NewValue: ${substring}`);
184
- main_1._this.log.debug(`CheckStatus Return Value: ${text.replace(substring, newValue.toString())}`);
185
- return text.replace(substring, newValue.toString());
186
- }
187
- catch (e) {
188
- main_1._this.log.error(`Error checkStatus:${e.message}`);
189
- main_1._this.log.error(`Stack:${e.stack}`);
190
- return '';
191
- }
192
- };
193
- const checkStatusInfo = async (text) => {
194
- try {
195
- if (!text) {
196
- return;
197
- }
198
- main_1._this.log.debug(`Text: ${text}`);
199
- if (text.includes('{status:')) {
200
- while (text.includes('{status:')) {
201
- text = await checkStatus(text, time_1.processTimeValue);
202
- }
203
- }
204
- if (text.includes('{time.lc') || text.includes('{time.ts')) {
205
- text = (await processTimeIdLc(text, null)) || '';
206
- }
207
- if (text.includes('{set:')) {
208
- const result = decomposeText(text, '{set:', '}');
209
- const id = result.substring.split(',')[0].replace("{set:'id':", '').replace(/'/g, '');
210
- const importedValue = result.substring.split(',')[1];
211
- text = result.textWithoutSubstring;
212
- const convertedValue = await checkTypeOfId(id, importedValue);
213
- const ack = result.substring.split(',')[2].replace('}', '') == 'true';
214
- if (text === '') {
215
- text = 'Wähle eine Aktion';
216
- }
217
- if (convertedValue) {
218
- await main_1._this.setForeignStateAsync(id, convertedValue, ack);
219
- }
220
- }
221
- if (text) {
222
- main_1._this.log.debug(`CheckStatusInfo: ${text}`);
223
- return text;
224
- }
225
- }
226
- catch (e) {
227
- (0, logging_1.errorLogger)('Error checkStatusInfo:', e);
228
- }
229
- };
230
- exports.checkStatusInfo = checkStatusInfo;
231
- async function checkTypeOfId(id, value) {
232
- try {
233
- main_1._this.log.debug(`Check Type of Id: ${id}`);
234
- const obj = await main_1._this.getForeignObjectAsync(id);
235
- const receivedType = typeof value;
236
- if (!obj || !value) {
237
- return value;
238
- }
239
- if (receivedType === obj.common.type || !obj.common.type) {
240
- return value;
241
- }
242
- main_1._this.log.debug(`Change Value type from "${receivedType}" to "${obj.common.type}"`);
243
- if (obj.common.type === 'boolean') {
244
- if (value == 'true') {
245
- value = true;
246
- }
247
- if (value == 'false') {
248
- value = false;
249
- }
250
- return value;
251
- }
252
- if (obj.common.type === 'string') {
253
- return JSON.stringify(value);
254
- }
255
- if (obj && obj.common && obj.common.type === 'number' && typeof value === 'string') {
256
- return parseFloat(value);
257
- }
258
- return value;
259
- }
260
- catch (e) {
261
- (0, logging_1.errorLogger)('Error checkTypeOfId:', e);
262
- }
263
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getChatID = void 0;
5
- const getChatID = (userListWithChatID, user) => {
6
- for (const element of userListWithChatID) {
7
- if (element.name === user) {
8
- return element.chatID;
9
- }
10
- }
11
- return;
12
- };
13
- exports.getChatID = getChatID;
@@ -1,402 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
4
- if (k2 === undefined)
5
- k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function () { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function (o, m, k, k2) {
12
- if (k2 === undefined)
13
- k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function (o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || (function () {
22
- var ownKeys = function (o) {
23
- ownKeys = Object.getOwnPropertyNames || function (o) {
24
- var ar = [];
25
- for (var k in o)
26
- if (Object.prototype.hasOwnProperty.call(o, k))
27
- ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule)
34
- return mod;
35
- var result = {};
36
- if (mod != null)
37
- for (var k = ownKeys(mod), i = 0; i < k.length; i++)
38
- if (k[i] !== "default")
39
- __createBinding(result, mod, k[i]);
40
- __setModuleDefault(result, mod);
41
- return result;
42
- };
43
- })();
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.adapter = exports._this = void 0;
46
- /*
47
- * Created with @iobroker/create-adapter v2.3.0
48
- */
49
- // The adapter-core module gives you access to the core ioBroker functions
50
- // you need to create an adapter
51
- const utils = __importStar(require("@iobroker/adapter-core"));
52
- const action_js_1 = require("./app/action.js");
53
- const subscribeStates_js_1 = require("./app/subscribeStates.js");
54
- const telegram_js_1 = require("./app/telegram.js");
55
- const utilities_js_1 = require("./lib/utilities.js");
56
- const createState_js_1 = require("./app/createState.js");
57
- const messageIds_js_1 = require("./app/messageIds.js");
58
- const adapterStartMenuSend_js_1 = require("./app/adapterStartMenuSend.js");
59
- const processData_js_1 = require("./app/processData.js");
60
- const shoppingList_js_1 = require("./app/shoppingList.js");
61
- const logging_js_1 = require("./app/logging.js");
62
- const connection_js_1 = require("./app/connection.js");
63
- const global_1 = require("./app/global");
64
- const string_1 = require("./lib/string");
65
- const timeoutKey = '0';
66
- let subscribeForeignStateIds;
67
- class TelegramMenu extends utils.Adapter {
68
- static instance;
69
- /**
70
- * @param [options] - Adapter options
71
- */
72
- constructor(options = {}) {
73
- super({
74
- ...options,
75
- name: 'telegram-menu',
76
- });
77
- this.on('ready', this.onReady.bind(this));
78
- this.on('unload', this.onUnload.bind(this));
79
- TelegramMenu.instance = this;
80
- }
81
- async onReady() {
82
- exports._this = this;
83
- await this.setState('info.connection', false, true);
84
- await (0, createState_js_1.createState)(this);
85
- let instanceTelegram = this.config.instance;
86
- if (!instanceTelegram || instanceTelegram.length == 0) {
87
- instanceTelegram = 'telegram.0';
88
- }
89
- const telegramID = `${instanceTelegram}.communicate.request`;
90
- const botSendMessageID = `${instanceTelegram}.communicate.botSendMessageId`;
91
- const requestMessageID = `${instanceTelegram}.communicate.requestMessageId`;
92
- const infoConnectionOfTelegram = `${instanceTelegram}.info.connection`;
93
- const checkboxes = this.config.checkbox;
94
- const one_time_keyboard = checkboxes.oneTiKey;
95
- const resize_keyboard = checkboxes.resKey;
96
- const checkboxNoEntryFound = checkboxes.checkboxNoValueFound;
97
- const sendMenuAfterRestart = checkboxes.sendMenuAfterRestart;
98
- let listOfMenus = [];
99
- if (this.config.usersInGroup) {
100
- listOfMenus = Object.keys(this.config.usersInGroup);
101
- }
102
- const token = this.config.tokenGrafana;
103
- const directoryPicture = this.config.directory;
104
- const isUserActiveCheckbox = this.config.userActiveCheckbox;
105
- const menusWithUsers = this.config.usersInGroup;
106
- const textNoEntryFound = this.config.textNoEntry;
107
- const userListWithChatID = this.config.userListWithChatID;
108
- const dataObject = this.config.data;
109
- const startSides = {};
110
- const menuData = {
111
- data: {},
112
- };
113
- Object.keys(menusWithUsers).forEach(element => {
114
- startSides[element] = dataObject.nav[element][0].call;
115
- });
116
- await this.getForeignObject(infoConnectionOfTelegram, async (err, obj) => {
117
- try {
118
- if (err || obj == null) {
119
- this.log.error(`The State ${infoConnectionOfTelegram} was not found! ${err}`);
120
- return;
121
- }
122
- const isTelegramActive = await (0, connection_js_1.checkIsTelegramActive)(infoConnectionOfTelegram);
123
- if (!isTelegramActive) {
124
- return;
125
- }
126
- const { nav, action } = dataObject;
127
- this.log.info('Telegram was found');
128
- for (const name in nav) {
129
- const value = (0, action_js_1.editArrayButtons)(nav[name]);
130
- const newObjectStructure = (0, action_js_1.generateNewObjectStructure)(value);
131
- if (newObjectStructure) {
132
- menuData.data[name] = newObjectStructure;
133
- }
134
- const generatedActions = (0, action_js_1.generateActions)(action[name], menuData.data[name]);
135
- if (generatedActions) {
136
- menuData.data[name] = generatedActions?.obj;
137
- subscribeForeignStateIds = generatedActions?.ids;
138
- }
139
- else {
140
- exports._this.log.debug('No Actions generated!');
141
- }
142
- if (subscribeForeignStateIds && subscribeForeignStateIds?.length > 0) {
143
- await (0, subscribeStates_js_1._subscribeForeignStatesAsync)(subscribeForeignStateIds);
144
- }
145
- else {
146
- exports._this.log.debug('Nothing to Subscribe!');
147
- }
148
- // Subscribe Events
149
- if (dataObject.action[name] && dataObject.action[name].events) {
150
- for (const event of dataObject.action[name].events) {
151
- await (0, subscribeStates_js_1._subscribeForeignStatesAsync)([event.ID]);
152
- }
153
- }
154
- exports._this.log.debug(`Menu: ${name}`);
155
- exports._this.log.debug(`Array Buttons: ${(0, string_1.jsonString)(value)}`);
156
- exports._this.log.debug(`Gen. Actions: ${(0, string_1.jsonString)(menuData.data[name])}`);
157
- }
158
- exports._this.log.debug(`Checkbox: ${(0, string_1.jsonString)(checkboxes)}`);
159
- exports._this.log.debug(`MenuList: ${(0, string_1.jsonString)(listOfMenus)}`);
160
- if (sendMenuAfterRestart) {
161
- await (0, adapterStartMenuSend_js_1.adapterStartMenuSend)(listOfMenus, startSides, isUserActiveCheckbox, menusWithUsers, menuData, userListWithChatID, instanceTelegram, resize_keyboard, one_time_keyboard);
162
- }
163
- this.on('stateChange', async (id, state) => {
164
- const setStateIdsToListenTo = (0, processData_js_1.getStateIdsToListenTo)();
165
- const isActive = await this.checkInfoConnection(id, infoConnectionOfTelegram);
166
- if (!isActive) {
167
- return;
168
- }
169
- const obj = await this.getChatIDAndUserToSend(instanceTelegram, userListWithChatID);
170
- if (!obj) {
171
- return;
172
- }
173
- const { userToSend } = obj;
174
- if ((0, global_1.isString)(state?.val) && state.val.includes('sList:')) {
175
- await (0, shoppingList_js_1.shoppingListSubscribeStateAndDeleteItem)(state.val, instanceTelegram, userListWithChatID, resize_keyboard, one_time_keyboard);
176
- return;
177
- }
178
- if (this.isAddToShoppingList(id, userToSend)) {
179
- await (0, shoppingList_js_1.deleteMessageAndSendNewShoppingList)(instanceTelegram, userListWithChatID, userToSend);
180
- return;
181
- }
182
- if (state &&
183
- (await (0, action_js_1.checkEvent)(dataObject, id, state, menuData, userListWithChatID, instanceTelegram, resize_keyboard, one_time_keyboard, menusWithUsers))) {
184
- return;
185
- }
186
- if (this.isMessageID(id, botSendMessageID, requestMessageID) && state) {
187
- await (0, messageIds_js_1.saveMessageIds)(state, instanceTelegram);
188
- }
189
- else if (this.isMenuToSend(state, id, telegramID, userToSend)) {
190
- let value = state?.val;
191
- if (!value || !userToSend) {
192
- return;
193
- }
194
- value = value.toString();
195
- const calledValue = value.slice(value.indexOf(']') + 1, value.length);
196
- const menus = (0, action_js_1.getMenusWithUserToSend)(menusWithUsers, userToSend);
197
- const dataFound = await (0, processData_js_1.checkEveryMenuForData)({
198
- menuData,
199
- calledValue,
200
- userToSend,
201
- instanceTelegram,
202
- resize_keyboard,
203
- one_time_keyboard,
204
- userListWithChatID,
205
- menus,
206
- isUserActiveCheckbox,
207
- token,
208
- directoryPicture,
209
- timeoutKey,
210
- });
211
- this.log.debug(`Groups with searched User: ${(0, string_1.jsonString)(menus)}`);
212
- this.log.debug(`Data found: ${dataFound}`);
213
- if (!dataFound && checkboxNoEntryFound && userToSend) {
214
- exports._this.log.debug('No Entry found');
215
- await (0, telegram_js_1.sendToTelegram)({
216
- user: userToSend,
217
- textToSend: textNoEntryFound,
218
- instance: instanceTelegram,
219
- resize_keyboard: resize_keyboard,
220
- one_time_keyboard: one_time_keyboard,
221
- userListWithChatID: userListWithChatID,
222
- parse_mode: 'false',
223
- });
224
- }
225
- return;
226
- }
227
- if (state &&
228
- setStateIdsToListenTo &&
229
- setStateIdsToListenTo.find((element) => element.id == id)) {
230
- exports._this.log.debug(`State, which is listen to was changed: ${id}`);
231
- exports._this.log.debug(`State: ${(0, string_1.jsonString)(state)}`);
232
- setStateIdsToListenTo.forEach((element, key) => {
233
- if (element.id == id) {
234
- exports._this.log.debug(`Send Value: ${(0, string_1.jsonString)(element)}`);
235
- exports._this.log.debug(`State: ${(0, string_1.jsonString)(state)}`);
236
- if (!(0, global_1.isFalsy)(element.confirm) &&
237
- !state?.ack &&
238
- element.returnText.includes('{confirmSet:')) {
239
- const substring = (0, utilities_js_1.decomposeText)(element.returnText, '{confirmSet:', '}').substring.split(':');
240
- exports._this.log.debug(`Substring: ${(0, string_1.jsonString)(substring)}`);
241
- let text = '';
242
- if ((0, global_1.isDefined)(state.val)) {
243
- text =
244
- substring[2] && substring[2].includes('noValue')
245
- ? substring[1]
246
- : (0, action_js_1.exchangePlaceholderWithValue)(substring[1], state.val.toString());
247
- }
248
- exports._this.log.debug(`Return-text: ${text}`);
249
- if (text === '') {
250
- exports._this.log.error('The return text cannot be empty, please check.');
251
- }
252
- (0, telegram_js_1.sendToTelegram)({
253
- user: element.userToSend,
254
- textToSend: text,
255
- instance: instanceTelegram,
256
- resize_keyboard: resize_keyboard,
257
- one_time_keyboard: one_time_keyboard,
258
- userListWithChatID: userListWithChatID,
259
- parse_mode: element.parse_mode,
260
- }).catch((e) => {
261
- (0, logging_js_1.errorLogger)('Error SendToTelegram', e);
262
- });
263
- return;
264
- }
265
- exports._this.log.debug(`Data: ${(0, string_1.jsonString)({ confirm: element.confirm, ack: state?.ack, val: state?.val })}`);
266
- if (!(0, global_1.isFalsy)(element.confirm) && state?.ack) {
267
- let textToSend = element.returnText;
268
- if (textToSend.includes('{confirmSet:')) {
269
- const substring = (0, utilities_js_1.decomposeText)(textToSend, '{confirmSet:', '}').substring;
270
- textToSend = textToSend.replace(substring, '');
271
- }
272
- let value = '';
273
- let valueChange = null;
274
- const { val, textToSend: changedText, error, } = (0, utilities_js_1.changeValue)(textToSend, state.val?.toString() || '');
275
- if (!error) {
276
- valueChange = val;
277
- textToSend = changedText;
278
- }
279
- if (textToSend?.toString().includes('{novalue}')) {
280
- value = '';
281
- textToSend = textToSend.replace('{novalue}', '');
282
- }
283
- else if ((0, global_1.isDefined)(state?.val)) {
284
- value = state.val?.toString() || '';
285
- }
286
- if (valueChange) {
287
- value = valueChange;
288
- }
289
- exports._this.log.debug(`Value to send: ${value}`);
290
- textToSend = (0, action_js_1.exchangePlaceholderWithValue)(textToSend, value);
291
- (0, telegram_js_1.sendToTelegram)({
292
- user: element.userToSend,
293
- textToSend: textToSend,
294
- keyboard: undefined,
295
- instance: instanceTelegram,
296
- resize_keyboard: resize_keyboard,
297
- one_time_keyboard: one_time_keyboard,
298
- userListWithChatID: userListWithChatID,
299
- parse_mode: element.parse_mode,
300
- }).catch((e) => {
301
- (0, logging_js_1.errorLogger)('Error sendToTelegram', e);
302
- });
303
- setStateIdsToListenTo.splice(key, 1);
304
- }
305
- }
306
- });
307
- }
308
- });
309
- }
310
- catch (e) {
311
- (0, logging_js_1.errorLogger)('Error onReady', e);
312
- }
313
- });
314
- await this.subscribeForeignStatesAsync(botSendMessageID);
315
- await this.subscribeForeignStatesAsync(requestMessageID);
316
- await this.subscribeForeignStatesAsync(`${instanceTelegram}.communicate.requestChatId`);
317
- await this.subscribeForeignStatesAsync(telegramID);
318
- await this.subscribeForeignStatesAsync(`${instanceTelegram}.info.connection`);
319
- }
320
- isMessageID(id, botSendMessageID, requestMessageID) {
321
- return id == botSendMessageID || id == requestMessageID;
322
- }
323
- isAddToShoppingList(id, userToSend) {
324
- return !!(id.includes('alexa-shoppinglist') && !id.includes('add_position') && userToSend);
325
- }
326
- isMenuToSend(state, id, telegramID, userToSend) {
327
- return !!(state &&
328
- typeof state.val === 'string' &&
329
- state.val != '' &&
330
- id == telegramID &&
331
- state?.ack &&
332
- userToSend);
333
- }
334
- async checkInfoConnection(id, infoConnectionOfTelegram) {
335
- if (id === infoConnectionOfTelegram) {
336
- const isActive = await (0, connection_js_1.checkIsTelegramActive)(infoConnectionOfTelegram);
337
- if (!isActive) {
338
- this.log.debug('Telegram is not active');
339
- return false;
340
- }
341
- return true;
342
- }
343
- return true;
344
- }
345
- async getChatIDAndUserToSend(instanceTelegram, userListWithChatID) {
346
- const chatID = await this.getForeignStateAsync(`${instanceTelegram}.communicate.requestChatId`);
347
- if (!chatID?.val) {
348
- exports._this.log.debug('ChatID not found');
349
- return;
350
- }
351
- const userToSend = (0, action_js_1.getUserToSendFromUserListWithChatID)(userListWithChatID, chatID.val.toString());
352
- if (!userToSend) {
353
- this.log.debug('User to send not found');
354
- return;
355
- }
356
- return { chatID: chatID.val.toString(), userToSend };
357
- }
358
- /**
359
- * Is called when adapter shuts down - callback has to be called under any circumstances!
360
- *
361
- * @param callback - Is called when adapter has closed all connections and released all resources
362
- */
363
- onUnload(callback) {
364
- const timeouts = (0, processData_js_1.getTimeouts)();
365
- try {
366
- // Here you must clear all timeouts or intervals that may still be active
367
- timeouts.forEach(element => {
368
- exports._this.clearTimeout(element.timeout);
369
- });
370
- callback();
371
- }
372
- catch (e) {
373
- (0, logging_js_1.errorLogger)(e, 'Error onUnload');
374
- callback();
375
- }
376
- }
377
- onMessage(obj) {
378
- if (typeof obj === 'object' && obj.message) {
379
- if (obj.command === 'send') {
380
- // e.g. send email or pushover or whatever
381
- this.log.info('send command');
382
- // Send response in callback if required
383
- if (obj.callback) {
384
- this.sendTo(obj.from, obj.command, 'Message received', obj.callback);
385
- }
386
- }
387
- }
388
- }
389
- }
390
- exports.default = TelegramMenu;
391
- let adapter;
392
- if (require.main !== module) {
393
- // Export the constructor in compact mode
394
- /**
395
- * @param [options] - Adapter options
396
- */
397
- exports.adapter = adapter = (options) => new TelegramMenu(options);
398
- }
399
- else {
400
- // otherwise start the instance directly
401
- new TelegramMenu();
402
- }