iobroker.telegram-menu 2.2.4 → 2.3.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.
Files changed (274) hide show
  1. package/README.md +12 -0
  2. package/admin/build/index.js +49 -49
  3. package/admin/build/index.js.map +3 -3
  4. package/admin/css/button.css +3 -0
  5. package/admin/css/row-editor.css +1 -1
  6. package/admin/css/style.css +46 -25
  7. package/admin/css/textarea.css +7 -11
  8. package/admin/i18n/de/translations.json +124 -123
  9. package/admin/i18n/en/translations.json +3 -2
  10. package/admin/i18n/es/translations.json +3 -2
  11. package/admin/i18n/fr/translations.json +3 -2
  12. package/admin/i18n/it/translations.json +3 -2
  13. package/admin/i18n/nl/translations.json +3 -2
  14. package/admin/i18n/pl/translations.json +3 -2
  15. package/admin/i18n/pt/translations.json +3 -2
  16. package/admin/i18n/ru/translations.json +3 -2
  17. package/admin/i18n/uk/translations.json +3 -2
  18. package/admin/i18n/zh-cn/translations.json +3 -2
  19. package/admin/words.js +3 -1
  20. package/build/admin/src/config/helper.js +178 -0
  21. package/build/admin/src/config/helper.js.map +1 -0
  22. package/build/admin/src/lib/Utils.js +64 -0
  23. package/build/admin/src/lib/Utils.js.map +1 -0
  24. package/build/admin/src/types/event.js +3 -0
  25. package/build/admin/src/types/event.js.map +1 -0
  26. package/build/app/action.js +270 -0
  27. package/build/app/action.js.map +7 -0
  28. package/build/app/adapterManager.js +36 -0
  29. package/build/app/adapterManager.js.map +7 -0
  30. package/build/app/adapterStartMenuSend.js +59 -0
  31. package/build/app/adapterStartMenuSend.js.map +7 -0
  32. package/build/app/backMenu.js +110 -0
  33. package/build/app/backMenu.js.map +7 -0
  34. package/build/app/botAction.js +47 -0
  35. package/build/app/botAction.js.map +7 -0
  36. package/build/app/configVariables.js +56 -0
  37. package/build/app/configVariables.js.map +7 -0
  38. package/build/app/connection.js +42 -0
  39. package/build/app/connection.js.map +7 -0
  40. package/build/app/createState.js +42 -0
  41. package/build/app/createState.js.map +7 -0
  42. package/build/app/dynamicSwitch.js +69 -0
  43. package/build/app/dynamicSwitch.js.map +7 -0
  44. package/build/app/dynamicSwitchMenu.js +69 -0
  45. package/build/app/dynamicSwitchMenu.js.map +7 -0
  46. package/build/app/dynamicValue.js +80 -0
  47. package/build/app/dynamicValue.js.map +7 -0
  48. package/build/app/echarts.js +60 -0
  49. package/build/app/echarts.js.map +7 -0
  50. package/build/app/getstate.js +148 -0
  51. package/build/app/getstate.js.map +7 -0
  52. package/build/app/global.js +2 -0
  53. package/build/app/global.js.map +7 -0
  54. package/build/app/httpRequest.js +84 -0
  55. package/build/app/httpRequest.js.map +7 -0
  56. package/build/app/jsonTable.js +158 -0
  57. package/build/app/jsonTable.js.map +7 -0
  58. package/build/app/logging.js +46 -0
  59. package/build/app/logging.js.map +7 -0
  60. package/build/app/messageIds.js +116 -0
  61. package/build/app/messageIds.js.map +7 -0
  62. package/build/app/processData.js +198 -0
  63. package/build/app/processData.js.map +7 -0
  64. package/build/app/sendNav.js +49 -0
  65. package/build/app/sendNav.js.map +7 -0
  66. package/build/app/sendpic.js +95 -0
  67. package/build/app/sendpic.js.map +7 -0
  68. package/build/app/sentry.js +43 -0
  69. package/build/app/sentry.js.map +7 -0
  70. package/build/app/setStateIdsToListenTo.js +42 -0
  71. package/build/app/setStateIdsToListenTo.js.map +7 -0
  72. package/build/app/setstate.js +145 -0
  73. package/build/app/setstate.js.map +7 -0
  74. package/build/app/shoppingList.js +97 -0
  75. package/build/app/shoppingList.js.map +7 -0
  76. package/build/app/subMenu.js +281 -0
  77. package/build/app/subMenu.js.map +7 -0
  78. package/build/app/subscribeStates.js +41 -0
  79. package/build/app/subscribeStates.js.map +7 -0
  80. package/build/app/telegram.js +131 -0
  81. package/build/app/telegram.js.map +7 -0
  82. package/build/app/validateMenus.js +64 -0
  83. package/build/app/validateMenus.js.map +7 -0
  84. package/build/build/src/app/action.js +447 -0
  85. package/build/build/src/app/adapterStartMenuSend.js +37 -0
  86. package/build/build/src/app/backMenu.js +70 -0
  87. package/build/build/src/app/botAction.js +25 -0
  88. package/build/build/src/app/connection.js +19 -0
  89. package/build/build/src/app/createState.js +19 -0
  90. package/build/build/src/app/dynamicSwitch.js +51 -0
  91. package/build/build/src/app/dynamicValue.js +64 -0
  92. package/build/build/src/app/echarts.js +45 -0
  93. package/build/build/src/app/getstate.js +157 -0
  94. package/build/build/src/app/global.js +59 -0
  95. package/build/build/src/app/httpRequest.js +64 -0
  96. package/build/build/src/app/jsonTable.js +147 -0
  97. package/build/build/src/app/logging.js +13 -0
  98. package/build/build/src/app/messageIds.js +88 -0
  99. package/build/build/src/app/processData.js +208 -0
  100. package/build/build/src/app/sendNav.js +30 -0
  101. package/build/build/src/app/sendpic.js +69 -0
  102. package/build/build/src/app/setstate.js +126 -0
  103. package/build/build/src/app/shoppingList.js +72 -0
  104. package/build/build/src/app/subMenu.js +361 -0
  105. package/build/build/src/app/subscribeStates.js +25 -0
  106. package/build/build/src/app/telegram.js +101 -0
  107. package/build/build/src/lib/string.js +28 -0
  108. package/build/build/src/lib/time.js +23 -0
  109. package/build/build/src/lib/utilities.js +263 -0
  110. package/build/build/src/lib/utils.js +13 -0
  111. package/build/build/src/main.js +402 -0
  112. package/build/config/config.js +134 -0
  113. package/build/config/config.js.map +7 -0
  114. package/build/io-package.json +87 -87
  115. package/build/lib/action.js +1 -3
  116. package/build/lib/action.js.map +2 -2
  117. package/build/lib/adapterStartMenuSend.js.map +1 -1
  118. package/build/lib/appUtils.js +158 -0
  119. package/build/lib/appUtils.js.map +7 -0
  120. package/build/lib/appUtilsString.js +37 -0
  121. package/build/lib/appUtilsString.js.map +7 -0
  122. package/build/lib/backMenu.js.map +2 -2
  123. package/build/lib/botAction.js.map +1 -1
  124. package/build/lib/dynamicSwitch.js.map +1 -1
  125. package/build/lib/dynamicValue.js.map +1 -1
  126. package/build/lib/echarts.js.map +1 -1
  127. package/build/lib/getstate.js.map +1 -1
  128. package/build/lib/global.js.map +1 -1
  129. package/build/lib/httpRequest.js.map +1 -1
  130. package/build/lib/json.js +54 -0
  131. package/build/lib/json.js.map +7 -0
  132. package/build/lib/jsonTable.js.map +1 -1
  133. package/build/lib/math.js +41 -0
  134. package/build/lib/math.js.map +7 -0
  135. package/build/lib/messageIds.js.map +1 -1
  136. package/build/lib/object.js +35 -0
  137. package/build/lib/object.js.map +7 -0
  138. package/build/lib/processData.js +4 -18
  139. package/build/lib/processData.js.map +3 -3
  140. package/build/lib/sendNav.js.map +1 -1
  141. package/build/lib/sendpic.js +23 -22
  142. package/build/lib/sendpic.js.map +2 -2
  143. package/build/lib/setstate.js.map +1 -1
  144. package/build/lib/shoppingList.js.map +1 -1
  145. package/build/lib/splitValues.js +63 -0
  146. package/build/lib/splitValues.js.map +7 -0
  147. package/build/lib/string.js +125 -3
  148. package/build/lib/string.js.map +2 -2
  149. package/build/lib/subMenu.js +1 -2
  150. package/build/lib/subMenu.js.map +2 -2
  151. package/build/lib/subscribeStates.js.map +1 -1
  152. package/build/lib/telegram.js.map +1 -1
  153. package/build/lib/time.js +93 -0
  154. package/build/lib/time.js.map +7 -0
  155. package/build/lib/utilities.js +84 -281
  156. package/build/lib/utilities.js.map +3 -3
  157. package/build/lib/utils.js +66 -0
  158. package/build/lib/utils.js.map +7 -0
  159. package/build/main.js +151 -233
  160. package/build/main.js.map +3 -3
  161. package/build/src/app/action.js +239 -0
  162. package/build/src/app/action.js.map +1 -0
  163. package/build/src/app/adapterManager.js +12 -0
  164. package/build/src/app/adapterManager.js.map +1 -0
  165. package/build/src/app/adapterStartMenuSend.js +36 -0
  166. package/build/src/app/adapterStartMenuSend.js.map +1 -0
  167. package/build/src/app/backMenu.js +81 -0
  168. package/build/src/app/backMenu.js.map +1 -0
  169. package/build/src/app/botAction.js +25 -0
  170. package/build/src/app/botAction.js.map +1 -0
  171. package/build/src/app/configVariables.js +32 -0
  172. package/build/src/app/configVariables.js.map +1 -0
  173. package/build/src/app/connection.js +20 -0
  174. package/build/src/app/connection.js.map +1 -0
  175. package/build/src/app/createState.js +19 -0
  176. package/build/src/app/createState.js.map +1 -0
  177. package/build/src/app/dynamicSwitch.js +52 -0
  178. package/build/src/app/dynamicSwitch.js.map +1 -0
  179. package/build/src/app/dynamicSwitchMenu.js +52 -0
  180. package/build/src/app/dynamicSwitchMenu.js.map +1 -0
  181. package/build/src/app/dynamicValue.js +52 -0
  182. package/build/src/app/dynamicValue.js.map +1 -0
  183. package/build/src/app/echarts.js +33 -0
  184. package/build/src/app/echarts.js.map +1 -0
  185. package/build/src/app/getstate.js +122 -0
  186. package/build/src/app/getstate.js.map +1 -0
  187. package/build/src/app/global.js +8 -0
  188. package/build/src/app/global.js.map +1 -0
  189. package/build/src/app/httpRequest.js +55 -0
  190. package/build/src/app/httpRequest.js.map +1 -0
  191. package/build/src/app/jsonTable.js +147 -0
  192. package/build/src/app/jsonTable.js.map +1 -0
  193. package/build/src/app/logging.js +22 -0
  194. package/build/src/app/logging.js.map +1 -0
  195. package/build/src/app/messageIds.js +89 -0
  196. package/build/src/app/messageIds.js.map +1 -0
  197. package/build/src/app/processData.js +153 -0
  198. package/build/src/app/processData.js.map +1 -0
  199. package/build/src/app/sendNav.js +26 -0
  200. package/build/src/app/sendNav.js.map +1 -0
  201. package/build/src/app/sendpic.js +66 -0
  202. package/build/src/app/sendpic.js.map +1 -0
  203. package/build/src/app/sentry.js +18 -0
  204. package/build/src/app/sentry.js.map +1 -0
  205. package/build/src/app/setStateIdsToListenTo.js +17 -0
  206. package/build/src/app/setStateIdsToListenTo.js.map +1 -0
  207. package/build/src/app/setstate.js +114 -0
  208. package/build/src/app/setstate.js.map +1 -0
  209. package/build/src/app/shoppingList.js +74 -0
  210. package/build/src/app/shoppingList.js.map +1 -0
  211. package/build/src/app/subMenu.js +237 -0
  212. package/build/src/app/subMenu.js.map +1 -0
  213. package/build/src/app/subscribeStates.js +17 -0
  214. package/build/src/app/subscribeStates.js.map +1 -0
  215. package/build/src/app/telegram.js +83 -0
  216. package/build/src/app/telegram.js.map +1 -0
  217. package/build/src/app/validateMenus.js +30 -0
  218. package/build/src/app/validateMenus.js.map +1 -0
  219. package/build/src/config/config.js +100 -0
  220. package/build/src/config/config.js.map +1 -0
  221. package/build/src/lib/appUtils.js +126 -0
  222. package/build/src/lib/appUtils.js.map +1 -0
  223. package/build/src/lib/appUtilsString.js +13 -0
  224. package/build/src/lib/appUtilsString.js.map +1 -0
  225. package/build/src/lib/json.js +37 -0
  226. package/build/src/lib/json.js.map +1 -0
  227. package/build/src/lib/math.js +17 -0
  228. package/build/src/lib/math.js.map +1 -0
  229. package/build/src/lib/object.js +10 -0
  230. package/build/src/lib/object.js.map +1 -0
  231. package/build/src/lib/splitValues.js +35 -0
  232. package/build/src/lib/splitValues.js.map +1 -0
  233. package/build/src/lib/string.js +121 -0
  234. package/build/src/lib/string.js.map +1 -0
  235. package/build/src/lib/time.js +57 -0
  236. package/build/src/lib/time.js.map +1 -0
  237. package/build/src/lib/utilities.js +111 -0
  238. package/build/src/lib/utilities.js.map +1 -0
  239. package/build/src/lib/utils.js +37 -0
  240. package/build/src/lib/utils.js.map +1 -0
  241. package/build/src/main.js +332 -0
  242. package/build/src/main.js.map +1 -0
  243. package/build/src/test/setup.js +12 -0
  244. package/build/src/test/setup.js.map +1 -0
  245. package/build/src/types/types.js +3 -0
  246. package/build/src/types/types.js.map +1 -0
  247. package/build/test/integration.js +0 -1
  248. package/build/test/integration.js.map +1 -1
  249. package/build/test/mocha.setup.js +0 -1
  250. package/build/test/mocha.setup.js.map +1 -1
  251. package/build/test/package.js +0 -1
  252. package/build/test/package.js.map +1 -1
  253. package/build/test/setup.js +12 -0
  254. package/build/test/setup.js.map +1 -0
  255. package/build/test/test/appUtils.test.js +507 -0
  256. package/build/test/test/appUtils.test.js.map +1 -0
  257. package/build/test/test/appUtilsString.test.js +16 -0
  258. package/build/test/test/appUtilsString.test.js.map +1 -0
  259. package/build/test/test/math.test.js +33 -0
  260. package/build/test/test/math.test.js.map +1 -0
  261. package/build/test/test/object.test.js +54 -0
  262. package/build/test/test/object.test.js.map +1 -0
  263. package/build/test/test/string.test.js +361 -0
  264. package/build/test/test/string.test.js.map +1 -0
  265. package/build/test/test/time.test.js +201 -0
  266. package/build/test/test/time.test.js.map +1 -0
  267. package/build/test/test/utils.test.js +115 -0
  268. package/build/test/test/utils.test.js.map +1 -0
  269. package/build/types/types.js +15 -0
  270. package/build/types/types.js.map +3 -3
  271. package/io-package.json +19 -14
  272. package/package.json +14 -10
  273. package/build/main.test.js +0 -24
  274. package/build/main.test.js.map +0 -1
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createState = void 0;
5
+ const createState = async (_this) => {
6
+ await _this.setObjectNotExistsAsync('communication.requestIds', {
7
+ type: 'state',
8
+ common: {
9
+ name: 'RequestIds',
10
+ type: 'string',
11
+ role: 'state',
12
+ read: true,
13
+ write: false,
14
+ def: '',
15
+ },
16
+ native: {},
17
+ });
18
+ };
19
+ exports.createState = createState;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.dynamicSwitch = dynamicSwitch;
5
+ const logging_1 = require("./logging");
6
+ const utilities_1 = require("../lib/utilities");
7
+ async function dynamicSwitch(calledValue, device, text) {
8
+ try {
9
+ const changedCalledValue = await (0, utilities_1.checkStatusInfo)(calledValue);
10
+ const splittedArray = changedCalledValue?.replace(/"/g, '').split(':');
11
+ if (!splittedArray) {
12
+ return;
13
+ }
14
+ device = splittedArray[2];
15
+ const arrayOfValues = splittedArray[1]
16
+ .replace('dynSwitch', '')
17
+ .replace(/\]/g, '')
18
+ .replace(/\[/g, '')
19
+ .split(',');
20
+ const lengthOfRow = parseInt(splittedArray[3]) || 6;
21
+ const array = [];
22
+ const keyboard = { inline_keyboard: array };
23
+ if (arrayOfValues) {
24
+ let keyboardItemsArray = [];
25
+ arrayOfValues.forEach((value, index) => {
26
+ if (value.includes('|')) {
27
+ const splittedValue = value.split('|');
28
+ keyboardItemsArray.push({
29
+ text: splittedValue[0],
30
+ callback_data: `menu:dynS:${device}:${splittedValue[1]}`,
31
+ });
32
+ }
33
+ else {
34
+ keyboardItemsArray.push({
35
+ text: value,
36
+ callback_data: `menu:dynS:${device}:${value}`,
37
+ });
38
+ }
39
+ if (((index + 1) % lengthOfRow == 0 && index != 0 && arrayOfValues.length > 0) ||
40
+ index + 1 == arrayOfValues.length) {
41
+ keyboard.inline_keyboard.push(keyboardItemsArray);
42
+ keyboardItemsArray = [];
43
+ }
44
+ });
45
+ return { text, keyboard, device };
46
+ }
47
+ }
48
+ catch (e) {
49
+ (0, logging_1.errorLogger)('Error parsing dynSwitch:', e);
50
+ }
51
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.removeUserFromDynamicValue = exports.getDynamicValue = exports.setDynamicValue = void 0;
5
+ const utilities_1 = require("../lib/utilities");
6
+ const telegram_1 = require("./telegram");
7
+ const setDynamicValueObj = {};
8
+ const setDynamicValue = async (returnText, ack, id, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID, parse_mode, confirm) => {
9
+ const { substring } = (0, utilities_1.decomposeText)(returnText, '{setDynamicValue:', '}');
10
+ let array = substring.split(':');
11
+ array = isBraceDeleteEntry(array);
12
+ const text = array[1];
13
+ if (text) {
14
+ await (0, telegram_1.sendToTelegram)({
15
+ user: userToSend,
16
+ textToSend: text,
17
+ keyboard: undefined,
18
+ instance: telegramInstance,
19
+ resize_keyboard: resize_keyboard,
20
+ one_time_keyboard: one_time_keyboard,
21
+ userListWithChatID: userListWithChatID,
22
+ parse_mode: parse_mode,
23
+ });
24
+ }
25
+ setDynamicValueObj[userToSend] = {
26
+ id: id,
27
+ ack: ack,
28
+ returnText: text,
29
+ userToSend: userToSend,
30
+ parse_mode: parse_mode,
31
+ confirm: confirm,
32
+ telegramInstance: telegramInstance,
33
+ one_time_keyboard: one_time_keyboard,
34
+ resize_keyboard: resize_keyboard,
35
+ userListWithChatID: userListWithChatID,
36
+ valueType: array[2],
37
+ };
38
+ if (array[3] && array[3] != '') {
39
+ return { confirmText: array[3], id: array[4] };
40
+ }
41
+ return { confirmText: '', id: undefined };
42
+ };
43
+ exports.setDynamicValue = setDynamicValue;
44
+ const getDynamicValue = (userToSend) => {
45
+ if (setDynamicValueObj[userToSend]) {
46
+ return setDynamicValueObj[userToSend];
47
+ }
48
+ return null;
49
+ };
50
+ exports.getDynamicValue = getDynamicValue;
51
+ const removeUserFromDynamicValue = (userToSend) => {
52
+ if (setDynamicValueObj[userToSend]) {
53
+ delete setDynamicValueObj[userToSend];
54
+ return true;
55
+ }
56
+ return false;
57
+ };
58
+ exports.removeUserFromDynamicValue = removeUserFromDynamicValue;
59
+ function isBraceDeleteEntry(array) {
60
+ if (array[4] === '}') {
61
+ return array.slice(0, 4);
62
+ }
63
+ return array;
64
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getChart = getChart;
5
+ const main_1 = require("../main");
6
+ const logging_1 = require("./logging");
7
+ const telegram_1 = require("./telegram");
8
+ const global_1 = require("./global");
9
+ function getChart(echarts, directoryPicture, user, instanceTelegram, userListWithChatID, resize_keyboard, one_time_keyboard) {
10
+ try {
11
+ if (!echarts) {
12
+ return;
13
+ }
14
+ for (const echart of echarts) {
15
+ const splitPreset = echart.preset.split('.');
16
+ const instanceOfEchart = `${splitPreset[0]}.${splitPreset[1]}`;
17
+ if (!(0, global_1.checkDirectoryIsOk)(directoryPicture)) {
18
+ return;
19
+ }
20
+ main_1._this.sendTo(instanceOfEchart, {
21
+ preset: echart.preset,
22
+ renderer: 'jpg',
23
+ background: echart.background,
24
+ theme: echart.theme,
25
+ quality: 1.0,
26
+ fileOnDisk: directoryPicture + echart.filename,
27
+ }, (result) => {
28
+ (0, telegram_1.sendToTelegram)({
29
+ user: user,
30
+ textToSend: result.error || directoryPicture + echart.filename,
31
+ instance: instanceTelegram,
32
+ resize_keyboard: resize_keyboard,
33
+ one_time_keyboard: one_time_keyboard,
34
+ userListWithChatID: userListWithChatID,
35
+ parse_mode: 'false',
36
+ }).catch((e) => {
37
+ (0, logging_1.errorLogger)('Error send to telegram: ', e);
38
+ });
39
+ });
40
+ }
41
+ }
42
+ catch (e) {
43
+ (0, logging_1.errorLogger)('Error get chart:', e);
44
+ }
45
+ }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getState = getState;
5
+ const telegram_1 = require("./telegram");
6
+ const action_1 = require("./action");
7
+ const jsonTable_1 = require("./jsonTable");
8
+ const utilities_1 = require("../lib/utilities");
9
+ const global_1 = require("./global");
10
+ const main_1 = require("../main");
11
+ const time_1 = require("../lib/time");
12
+ const string_1 = require("../lib/string");
13
+ function getState(part, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID) {
14
+ let text = '';
15
+ let i = 1;
16
+ // Parse Mode ist nur immer im ersten Element
17
+ const parse_mode = part.getData?.[0].parse_mode || 'false';
18
+ part.getData?.forEach(async (element) => {
19
+ try {
20
+ main_1._this.log.debug(`Get Value ID: ${element.id}`);
21
+ const specifiedSelektor = 'functions=';
22
+ const id = element.id;
23
+ let textToSend = '';
24
+ if (id.indexOf(specifiedSelektor) != -1) {
25
+ await (0, action_1.idBySelector)(id, element.text, userToSend, element.newline, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID);
26
+ return;
27
+ }
28
+ if (element.text.includes('binding:')) {
29
+ main_1._this.log.debug('Binding');
30
+ await (0, action_1.bindingFunc)(element.text, userToSend, telegramInstance, one_time_keyboard, resize_keyboard, userListWithChatID, parse_mode);
31
+ return;
32
+ }
33
+ await main_1._this.getForeignStateAsync(id).then(async (value) => {
34
+ if (!(0, global_1.isDefined)(value)) {
35
+ main_1._this.log.error('The state is empty!');
36
+ return;
37
+ }
38
+ const valueForJson = value.val?.toString() ?? '';
39
+ main_1._this.log.debug(`State: ${(0, string_1.jsonString)(value)}`);
40
+ let val = valueForJson.replace(/\\/g, '').replace(/"/g, '');
41
+ let newline = '';
42
+ if (element.newline === 'true') {
43
+ newline = '\n';
44
+ }
45
+ if (element.text) {
46
+ textToSend = element.text.toString();
47
+ if (element.text.includes('{time.lc') || element.text.includes('{time.ts')) {
48
+ textToSend = (await (0, utilities_1.processTimeIdLc)(element.text, id)) || '';
49
+ val = '';
50
+ }
51
+ if (textToSend.includes('{time}')) {
52
+ textToSend = (0, time_1.processTimeValue)(textToSend, value);
53
+ val = '';
54
+ }
55
+ if (textToSend.includes('math:')) {
56
+ const result = (0, action_1.calcValue)(textToSend, val);
57
+ if (result) {
58
+ textToSend = result.textToSend;
59
+ val = result.val;
60
+ main_1._this.log.debug(`TextToSend: ${textToSend} val: ${val}`);
61
+ }
62
+ }
63
+ if (textToSend.includes('round:')) {
64
+ const result = (0, action_1.roundValue)(val, textToSend);
65
+ if (result) {
66
+ main_1._this.log.debug(`The Value was rounded ${JSON.stringify(val)} to ${JSON.stringify(result.val)}`);
67
+ val = result.val;
68
+ textToSend = result.textToSend;
69
+ }
70
+ }
71
+ if (textToSend.includes('{json')) {
72
+ if ((0, global_1.decomposeText)(textToSend, '{json', '}').substring.includes('TextTable')) {
73
+ const result = (0, jsonTable_1.createTextTableFromJson)(valueForJson, textToSend);
74
+ if (result) {
75
+ await (0, telegram_1.sendToTelegram)({
76
+ user: userToSend,
77
+ textToSend: result,
78
+ keyboard: undefined,
79
+ instance: telegramInstance,
80
+ resize_keyboard: one_time_keyboard,
81
+ one_time_keyboard: resize_keyboard,
82
+ userListWithChatID: userListWithChatID,
83
+ parse_mode: parse_mode,
84
+ });
85
+ return;
86
+ }
87
+ main_1._this.log.debug('Cannot create a Text-Table');
88
+ }
89
+ else {
90
+ const result = (0, jsonTable_1.createKeyboardFromJson)(valueForJson, textToSend, element.id, userToSend);
91
+ if (valueForJson && valueForJson.length > 0) {
92
+ if (result && result.text && result.keyboard) {
93
+ (0, telegram_1.sendToTelegramSubmenu)(userToSend, result.text, result.keyboard, telegramInstance, userListWithChatID, parse_mode);
94
+ }
95
+ return;
96
+ }
97
+ await (0, telegram_1.sendToTelegram)({
98
+ user: userToSend,
99
+ textToSend: 'The state is empty!',
100
+ keyboard: undefined,
101
+ instance: telegramInstance,
102
+ resize_keyboard: one_time_keyboard,
103
+ one_time_keyboard: resize_keyboard,
104
+ userListWithChatID: userListWithChatID,
105
+ parse_mode: parse_mode,
106
+ });
107
+ main_1._this.log.debug('The state is empty!');
108
+ return;
109
+ }
110
+ }
111
+ const { val: _val, textToSend: _text, error } = (0, utilities_1.changeValue)(textToSend, val);
112
+ val = _val;
113
+ textToSend = _text;
114
+ if (!error) {
115
+ main_1._this.log.debug(`Value Changed to: ${textToSend}`);
116
+ }
117
+ else {
118
+ main_1._this.log.debug(`No Change`);
119
+ }
120
+ if (textToSend.indexOf('&&') != -1) {
121
+ text += `${textToSend.replace('&&', val.toString())}${newline}`;
122
+ }
123
+ else {
124
+ text += `${textToSend} ${val}${newline}`;
125
+ }
126
+ }
127
+ else {
128
+ text += `${val} ${newline}`;
129
+ }
130
+ main_1._this.log.debug(`Text: ${text}`);
131
+ if (i == part.getData?.length) {
132
+ if (userToSend) {
133
+ await (0, telegram_1.sendToTelegram)({
134
+ user: userToSend,
135
+ textToSend: text,
136
+ keyboard: undefined,
137
+ instance: telegramInstance,
138
+ resize_keyboard: one_time_keyboard,
139
+ one_time_keyboard: resize_keyboard,
140
+ userListWithChatID: userListWithChatID,
141
+ parse_mode: parse_mode,
142
+ });
143
+ }
144
+ }
145
+ i++;
146
+ });
147
+ }
148
+ catch (error) {
149
+ error({
150
+ array: [
151
+ { text: 'Error GetData:', val: error.message },
152
+ { text: 'Stack:', val: error.stack },
153
+ ],
154
+ });
155
+ }
156
+ });
157
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.isFalsy = exports.isTruthy = exports.isString = exports.deepCopy = exports.deleteDoubleEntriesInArray = exports.isDefined = void 0;
5
+ exports.decomposeText = decomposeText;
6
+ exports.checkDirectoryIsOk = checkDirectoryIsOk;
7
+ exports.parseJSON = parseJSON;
8
+ const logging_1 = require("./logging");
9
+ const main_1 = require("../main");
10
+ const isDefined = (value) => value !== undefined && value !== null;
11
+ exports.isDefined = isDefined;
12
+ const deleteDoubleEntriesInArray = (arr) => arr.filter((item, index) => arr.indexOf(item) === index);
13
+ exports.deleteDoubleEntriesInArray = deleteDoubleEntriesInArray;
14
+ function decomposeText(text, searchValue, secondValue) {
15
+ const startindex = text.indexOf(searchValue);
16
+ const endindex = text.indexOf(secondValue, startindex);
17
+ const substring = text.substring(startindex, endindex + secondValue.length);
18
+ const textWithoutSubstring = text.replace(substring, '').trim();
19
+ return {
20
+ startindex: startindex,
21
+ endindex: endindex,
22
+ substring: substring,
23
+ textWithoutSubstring: textWithoutSubstring,
24
+ };
25
+ }
26
+ const deepCopy = (obj) => {
27
+ try {
28
+ if (!obj) {
29
+ return undefined;
30
+ }
31
+ return JSON.parse(JSON.stringify(obj));
32
+ }
33
+ catch (err) {
34
+ console.error(`Error deepCopy: ${JSON.stringify(err)}`);
35
+ }
36
+ };
37
+ exports.deepCopy = deepCopy;
38
+ const isString = (value) => typeof value === 'string';
39
+ exports.isString = isString;
40
+ const isTruthy = (value) => ['1', 1, true, 'true'].includes(value);
41
+ exports.isTruthy = isTruthy;
42
+ const isFalsy = (value) => ['0', 0, false, 'false', undefined, null].includes(value);
43
+ exports.isFalsy = isFalsy;
44
+ function checkDirectoryIsOk(directory) {
45
+ if (['', null, undefined].includes(directory)) {
46
+ main_1._this.log.error('No directory to save the picture. Please add a directory in the settings with full read and write permissions.');
47
+ return false;
48
+ }
49
+ return true;
50
+ }
51
+ function parseJSON(value) {
52
+ try {
53
+ return JSON.parse(value);
54
+ }
55
+ catch (error) {
56
+ (0, logging_1.errorLogger)('Error parseJson: ', error);
57
+ return undefined;
58
+ }
59
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.httpRequest = httpRequest;
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const telegram_1 = require("./telegram");
10
+ const path_1 = __importDefault(require("path"));
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const logging_1 = require("./logging");
13
+ const global_1 = require("./global");
14
+ const main_1 = require("../main");
15
+ async function httpRequest(parts, userToSend, instanceTelegram, resize_keyboard, one_time_keyboard, userListWithChatID, directoryPicture) {
16
+ if (!parts.httpRequest) {
17
+ return;
18
+ }
19
+ for (const part of parts.httpRequest) {
20
+ const { url, password, user } = part;
21
+ const method = 'get';
22
+ main_1._this.log.debug(`URL: ${url}`);
23
+ try {
24
+ //prettier-ignore
25
+ const response = await (0, axios_1.default)(user && password
26
+ ? {
27
+ method: method,
28
+ url: url,
29
+ responseType: "arraybuffer",
30
+ auth: {
31
+ username: user,
32
+ password: password,
33
+ },
34
+ }
35
+ : {
36
+ method: method,
37
+ url: url,
38
+ responseType: "arraybuffer",
39
+ });
40
+ if (!part.filename) {
41
+ return;
42
+ }
43
+ if (!(0, global_1.checkDirectoryIsOk)(directoryPicture)) {
44
+ return;
45
+ }
46
+ const imagePath = path_1.default.join(directoryPicture, part.filename);
47
+ fs_1.default.writeFileSync(imagePath, Buffer.from(response.data), 'binary');
48
+ main_1._this.log.debug(`Pic saved: ${imagePath}`);
49
+ await (0, telegram_1.sendToTelegram)({
50
+ user: userToSend,
51
+ textToSend: imagePath,
52
+ instance: instanceTelegram,
53
+ resize_keyboard: resize_keyboard,
54
+ one_time_keyboard: one_time_keyboard,
55
+ userListWithChatID: userListWithChatID,
56
+ parse_mode: 'false',
57
+ });
58
+ }
59
+ catch (e) {
60
+ (0, logging_1.errorLogger)('Error http request:', e);
61
+ }
62
+ }
63
+ return true;
64
+ }
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createKeyboardFromJson = void 0;
5
+ exports.createTextTableFromJson = createTextTableFromJson;
6
+ const global_1 = require("./global");
7
+ const logging_1 = require("./logging");
8
+ const main_1 = require("../main");
9
+ const string_1 = require("../lib/string");
10
+ const lastText = {};
11
+ const createKeyboardFromJson = (val, text, id, user) => {
12
+ try {
13
+ if (text) {
14
+ lastText[user] = text;
15
+ }
16
+ else {
17
+ text = lastText[user];
18
+ }
19
+ const array = (0, global_1.decomposeText)(text, '{json:', '}').substring.split(';');
20
+ const headline = array[2];
21
+ const itemArray = array[1].replace('[', '').replace(']', '').replace(/"/g, '').split(',');
22
+ let idShoppingList = false;
23
+ if (array.length > 3 && array[3] == 'shoppinglist') {
24
+ idShoppingList = true;
25
+ }
26
+ main_1._this.log.debug(`Val: ${val} with type: ${typeof val}`);
27
+ const valArray = (0, global_1.parseJSON)(val);
28
+ if (!valArray) {
29
+ return;
30
+ }
31
+ const keyboard = { inline_keyboard: [] };
32
+ valArray.forEach((element, index) => {
33
+ const firstRow = [];
34
+ const rowArray = [];
35
+ itemArray.forEach(item => {
36
+ if (index == 0) {
37
+ const btnText = item.split(':')[1];
38
+ if (btnText.length > 0) {
39
+ firstRow.push({ text: btnText, callback_data: '1' });
40
+ }
41
+ }
42
+ if (idShoppingList) {
43
+ const value = element.buttondelete;
44
+ const valueDeleteLinkArray = (0, global_1.decomposeText)(value, "('", "')")
45
+ .substring.replace("('", '')
46
+ .replace(",true')", '')
47
+ .split('.');
48
+ const instanceAlexa = valueDeleteLinkArray[1];
49
+ const valueDeleteId = valueDeleteLinkArray[5];
50
+ const instanceShoppingListID = `${id.split('.')[1]}.${id.split('.')[2]}`;
51
+ rowArray.push({
52
+ text: element[item.split(':')[0]],
53
+ callback_data: `sList:${instanceShoppingListID}:${instanceAlexa}:${valueDeleteId}:`,
54
+ });
55
+ }
56
+ else {
57
+ rowArray.push({ text: element[item.split(':')[0]], callback_data: '1' });
58
+ }
59
+ });
60
+ if (index == 0) {
61
+ keyboard.inline_keyboard.push(firstRow);
62
+ }
63
+ keyboard.inline_keyboard.push(rowArray);
64
+ });
65
+ main_1._this.log.debug(`Keyboard: ${(0, string_1.jsonString)(keyboard)}`);
66
+ return { text: headline, keyboard };
67
+ }
68
+ catch (err) {
69
+ (0, logging_1.errorLogger)('Error createKeyboardFromJson:', err);
70
+ }
71
+ };
72
+ exports.createKeyboardFromJson = createKeyboardFromJson;
73
+ function createTextTableFromJson(val, textToSend) {
74
+ try {
75
+ if (!val) {
76
+ return;
77
+ }
78
+ const substring = (0, global_1.decomposeText)(textToSend, '{json:', '}').substring;
79
+ const array = substring.split(';');
80
+ const itemArray = array[1].replace('[', '').replace(']', '').replace(/"/g, '').split(',');
81
+ const valArray = JSON.parse(val);
82
+ // Array für die Größte Länge der Items
83
+ const lengthArray = [];
84
+ // Trägt für jedes Item einen Eintrag im lengthArray ein
85
+ itemArray.forEach(element => {
86
+ lengthArray.push(element.split(':')[1].length);
87
+ });
88
+ valArray.forEach(element => {
89
+ itemArray.forEach((item, index) => {
90
+ if (lengthArray[index] < element[item.split(':')[0]].toString().length) {
91
+ lengthArray[index] = element[item.split(':')[0]].toString().length;
92
+ }
93
+ });
94
+ });
95
+ main_1._this.log.debug(`Length of rows: ${(0, string_1.jsonString)(lengthArray)}`);
96
+ const headline = array[2];
97
+ let textTable = textToSend.replace(substring, '').trim();
98
+ if (textTable != '') {
99
+ textTable += ' \n\n';
100
+ }
101
+ textTable += ` ${headline} \n\``;
102
+ const enlargeColumn = 1;
103
+ const reduce = lengthArray.length == 1 ? 2 : 0;
104
+ const lineLength = lengthArray.reduce((a, b) => a + b, 0) + 5 - reduce + enlargeColumn * lengthArray.length;
105
+ // Breakline
106
+ textTable += `${'-'.repeat(lineLength)} \n`;
107
+ valArray.forEach((element, elementIndex) => {
108
+ itemArray.forEach((item, index) => {
109
+ // TableHead
110
+ if (elementIndex == 0 && index == 0) {
111
+ textTable += '|';
112
+ itemArray.forEach((item2, i) => {
113
+ if (item2.split(':')[1].length > 0) {
114
+ textTable += ` ${item2
115
+ .split(':')[1]
116
+ .toString()
117
+ .padEnd(lengthArray[i] + enlargeColumn, ' ')}|`;
118
+ if (i == itemArray.length - 1) {
119
+ textTable += '\n';
120
+ // Breakline
121
+ textTable += `${'-'.repeat(lineLength)} \n`;
122
+ }
123
+ }
124
+ else {
125
+ textTable = textTable.slice(0, -1);
126
+ }
127
+ });
128
+ }
129
+ // TableBody
130
+ if (index == 0) {
131
+ textTable += '|';
132
+ }
133
+ textTable += ` ${element[item.split(':')[0]].toString().padEnd(lengthArray[index] + enlargeColumn, ' ')}|`;
134
+ if (index == itemArray.length - 1) {
135
+ textTable += '\n';
136
+ }
137
+ });
138
+ });
139
+ // Breakline
140
+ textTable += '-'.repeat(lineLength);
141
+ textTable += '`';
142
+ return textTable;
143
+ }
144
+ catch (e) {
145
+ (0, logging_1.errorLogger)('Error createTextTableFromJson:', e);
146
+ }
147
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.errorLogger = void 0;
5
+ const main_1 = require("../main");
6
+ const errorLogger = (title, e) => {
7
+ main_1._this.log.error(title);
8
+ main_1._this.log.error(`Error message: ${e.message}`);
9
+ main_1._this.log.error(`Error stack: ${e.stack}`);
10
+ main_1._this.log.error(`Server response: ${e?.response?.status}`);
11
+ main_1._this.log.error(`Server data: ${e?.response?.data}`);
12
+ };
13
+ exports.errorLogger = errorLogger;