diff --git a/build/lib/action.js b/build/lib/action.js index 55082aa8..a50ee043 100644 --- a/build/lib/action.js +++ b/build/lib/action.js @@ -482,18 +482,16 @@ const checkEvent = async (dataObject, id, state, menuData, userListWithChatID2, }; const getUserToSendFromUserListWithChatID = (userListWithChatID2, chatID) => { let userToSend2 = null; - if (!chatID) { - return null; - } - userListWithChatID2.forEach((element) => { - if (element.chatID == chatID.val) { + for (const element of userListWithChatID2) { + if (element.chatID == chatID) { userToSend2 = element.name; + (0, import_logging.debug)([ + { text: "User and ChatID:", val: element }, + { text: "User:", val: userToSend2 } + ]); + break; } - (0, import_logging.debug)([ - { text: "User and ChatID:", val: element }, - { text: "User:", val: userToSend2 } - ]); - }); + } return userToSend2; }; const getMenusWithUserToSend = (menusWithUsers, userToSend2) => { diff --git a/build/lib/action.js.map b/build/lib/action.js.map index 58e6c184..543ea512 100644 --- a/build/lib/action.js.map +++ b/build/lib/action.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../src/lib/action.ts"], - "sourcesContent": ["import { sendToTelegram } from './telegram.js';\nimport { decomposeText } from './global';\nimport { callSubMenu } from './subMenu.js';\nimport { sendNav } from './sendNav.js';\nimport { backMenuFunc } from './backMenu.js';\nimport { debug, error } from './logging.js';\nimport TelegramMenu from '../main.js';\nimport type {\n UserListWithChatId,\n BooleanString,\n BindingObject,\n EditArrayButtons,\n GeneratedNavMenu,\n Newline,\n NewObjectNavStructure,\n Actions,\n GenerateActionsArrayOfEntries,\n Switch,\n UserObjectActions,\n GenerateActionsNewObject,\n NewObjectNavStructureKey,\n Part,\n DataObject,\n MenuData,\n UserInGroup,\n MenusWithUsers,\n} from './telegram-menu.js';\n\nconst bindingFunc = async (\n text: string,\n userToSend: string,\n telegramInstance: string,\n one_time_keyboard: boolean,\n resize_keyboard: boolean,\n userListWithChatID: UserListWithChatId[],\n parse_mode: BooleanString,\n): Promise => {\n const _this = TelegramMenu.getInstance();\n let value;\n\n try {\n const substring = decomposeText(text, 'binding:', '}').substring;\n const arrayOfItems = substring.replace('binding:{', '').replace('}', '').split(';');\n const bindingObject: BindingObject = {\n values: {},\n };\n\n for (let item of arrayOfItems) {\n if (!item.includes('?')) {\n const key = item.split(':')[0];\n const id = item.split(':')[1];\n\n const result = await _this.getForeignStateAsync(id);\n if (result) {\n bindingObject.values[key] = result.val?.toString() || '';\n }\n } else {\n Object.keys(bindingObject.values).forEach(function (key) {\n item = item.replace(key, bindingObject.values[key]);\n });\n\n value = eval(item);\n }\n }\n await sendToTelegram(\n userToSend,\n value,\n undefined,\n telegramInstance,\n one_time_keyboard,\n resize_keyboard,\n userListWithChatID,\n parse_mode,\n );\n } catch (e: any) {\n error([\n { text: 'Error:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n }\n};\n\nfunction calcValue(\n _this: TelegramMenu,\n textToSend: string,\n val: string,\n): { textToSend: string; val: string } | undefined {\n const { substring } = decomposeText(textToSend, '{math:', '}');\n const mathValue = substring.replace('{math:', '').replace('}', '');\n try {\n val = eval(val + mathValue);\n textToSend = textToSend.replace(substring, '');\n\n return { textToSend: textToSend, val: val };\n } catch (e: any) {\n error([\n { text: 'Error Eval:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n }\n}\n\nfunction checkValueForOneLine(text: string): string {\n if (!text.includes('&&')) {\n return `${text}&&`;\n }\n return text;\n}\n\nfunction editArrayButtons(val: EditArrayButtons[], _this: TelegramMenu): GeneratedNavMenu[] | null {\n const newVal: GeneratedNavMenu[] = [];\n try {\n val.forEach(element => {\n let value = '';\n if (typeof element.value === 'string') {\n value = checkValueForOneLine(element.value);\n }\n let array: string[] | string[][] = [];\n if (value.indexOf('&&') != -1) {\n array = value.split('&&');\n }\n\n if (array.length > 1) {\n array.forEach(function (element, index: number) {\n if (typeof element === 'string') {\n let navArray = element.split(',');\n navArray = navArray.map(item => item.trim());\n array[index] = navArray;\n }\n });\n } else if (typeof element.value === 'string') {\n array = element.value.split(',');\n array.forEach(function (element, index: number) {\n array[index] = [element.trim()];\n });\n }\n\n newVal.push({ call: element.call, text: element.text, parse_mode: element.parse_mode, nav: array });\n });\n\n return newVal;\n } catch (err: any) {\n error([\n { text: 'Error EditArray:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n return null;\n }\n}\n\nconst idBySelector = async (\n _this: TelegramMenu,\n selector: string,\n text: string,\n userToSend: string,\n newline: Newline,\n telegramInstance: string,\n one_time_keyboard: boolean,\n resize_keyboard: boolean,\n userListWithChatID: UserListWithChatId[],\n): Promise => {\n let text2Send = '';\n try {\n if (!selector.includes('functions')) {\n return;\n }\n\n const functions = selector.replace('functions=', '');\n let enums: string[] | undefined = [];\n const result = await _this.getEnumsAsync();\n\n if (!result || !result['enum.functions'][`enum.functions.${functions}`]) {\n return;\n }\n enums = result['enum.functions'][`enum.functions.${functions}`].common.members;\n if (!enums) {\n return;\n }\n const promises = enums.map(async (id: string) => {\n const value = await _this.getForeignStateAsync(id);\n if (value && value.val !== undefined && value.val !== null) {\n let newText = text;\n let res;\n\n if (text.includes('{common.name}')) {\n res = await _this.getForeignObjectAsync(id);\n _this.log.debug(`Name ${JSON.stringify(res?.common.name)}`);\n\n if (res && res.common.name) {\n newText = newText.replace('{common.name}', res.common.name as string);\n }\n }\n if (text.includes('&&')) {\n text2Send += newText.replace('&&', value.val as string);\n } else if (text.includes('&&')) {\n text2Send += newText.replace('&&', value.val as string);\n } else {\n text2Send += newText;\n text2Send += ` ${value.val}`;\n }\n }\n if (newline === 'true') {\n text2Send += ' \\n';\n } else {\n text2Send += ' ';\n }\n _this.log.debug(`text2send ${JSON.stringify(text2Send)}`);\n });\n Promise.all(promises)\n .then(() => {\n sendToTelegram(\n userToSend,\n text2Send,\n undefined,\n telegramInstance,\n one_time_keyboard,\n resize_keyboard,\n userListWithChatID,\n '',\n ).catch(e => {\n error([\n { text: 'Error SendToTelegram:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n });\n debug([\n { text: 'TextToSend:', val: text2Send },\n { text: 'UserToSend:', val: userToSend },\n ]);\n })\n .catch(e => {\n error([\n { text: 'Error Promise:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n });\n } catch (error: any) {\n error([\n { text: 'Error idBySelector:', val: error.message },\n { text: 'Stack:', val: error.stack },\n ]);\n }\n};\n\nfunction generateNewObjectStructure(val: GeneratedNavMenu[] | null): NewObjectNavStructure | null {\n try {\n if (!val) {\n return null;\n }\n const obj: NewObjectNavStructure = {};\n val.forEach(function (element) {\n const call = element.call;\n obj[call] = {\n nav: element.nav,\n text: element.text,\n parse_mode:\n element.parse_mode == 'true' || element.parse_mode == 'false' ? element.parse_mode : 'false',\n };\n });\n return obj;\n } catch (err: any) {\n error([\n { text: 'Error GenerateNewObjectStructure:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n return null;\n }\n}\n\nfunction generateActions(\n action: Actions,\n userObject: NewObjectNavStructure,\n): { obj: NewObjectNavStructure; ids: string[] } | undefined {\n try {\n const arrayOfEntries: GenerateActionsArrayOfEntries[] = [\n {\n objName: 'echarts',\n name: 'echarts',\n loop: 'preset',\n elements: [\n { name: 'preset' },\n { name: 'echartInstance' },\n { name: 'background' },\n { name: 'theme' },\n { name: 'filename' },\n ],\n },\n {\n objName: 'loc',\n name: 'location',\n loop: 'latitude',\n elements: [{ name: 'latitude' }, { name: 'longitude' }, { name: 'parse_mode', key: 0 }],\n },\n {\n objName: 'pic',\n name: 'sendPic',\n loop: 'IDs',\n elements: [\n { name: 'id', value: 'IDs' },\n { name: 'fileName' },\n { name: 'delay', value: 'picSendDelay' },\n ],\n },\n {\n objName: 'get',\n name: 'getData',\n loop: 'IDs',\n elements: [\n { name: 'id', value: 'IDs' },\n { name: 'text', type: 'text' },\n { name: 'newline', value: 'newline_checkbox' },\n { name: 'parse_mode', key: 0 },\n ],\n },\n {\n objName: 'httpRequest',\n name: 'httpRequest',\n loop: 'url',\n elements: [{ name: 'url' }, { name: 'user' }, { name: 'password' }, { name: 'filename' }],\n },\n ];\n\n const listOfSetStateIds: string[] = [];\n action.set.forEach(function (element, key) {\n if (key == 0) {\n userObject[element.trigger[0]] = { switch: [] };\n }\n userObject[element.trigger[0]] = { switch: [] };\n element.IDs.forEach(function (id: string, index: number) {\n listOfSetStateIds.push(id);\n const toggle = element.switch_checkbox[index] === 'true';\n let value;\n\n if (element.values[index] === 'true' || element.values[index] === 'false') {\n value = element.values[index] === 'true';\n } else {\n value = element.values[index];\n }\n const newObj: Switch = {\n id: element.IDs[index],\n value: value.toString(),\n toggle: toggle,\n confirm: element.confirm[index],\n returnText: element.returnText[index],\n ack: element.ack ? element.ack[index] : 'false',\n parse_mode: element.parse_mode ? element.parse_mode[0] : 'false',\n };\n if (userObject[element.trigger[0]] && userObject[element.trigger[0]]?.switch) {\n userObject[element.trigger[0]].switch!.push(newObj);\n }\n });\n });\n\n arrayOfEntries.forEach(item => {\n if (action[item.objName as keyof Actions]) {\n action[item.objName as keyof Actions].forEach(function (element, index: number) {\n userObject[element.trigger[0]] = { [item.name]: [] };\n if (index == 0) {\n userObject[element.trigger[0]] = { [item.name as keyof UserObjectActions]: [] };\n }\n\n (element[item.loop as keyof typeof element] as string[]).forEach(function (\n id: string,\n key: number,\n ) {\n const newObj: GenerateActionsNewObject = {};\n item.elements.forEach(elementItem => {\n const name = elementItem.name;\n const value = elementItem.value ? elementItem.value : elementItem.name;\n const newKey = elementItem.key ? elementItem.key : key;\n let val: string | boolean;\n\n if (!element[value as keyof typeof element]) {\n val = false;\n } else {\n val = element[value as keyof typeof element][newKey] || 'false';\n }\n\n if (elementItem.type == 'text' && typeof val === 'string') {\n newObj[name as keyof GenerateActionsNewObject] = val.replace(/&/g, '&') as any;\n } else {\n newObj[name as keyof GenerateActionsNewObject] = val as any;\n }\n });\n if (item.name && typeof item.name === 'string') {\n userObject[element.trigger as NewObjectNavStructureKey][item?.name as keyof Part].push(\n newObj,\n );\n }\n });\n });\n }\n });\n\n return { obj: userObject, ids: listOfSetStateIds };\n } catch (err: any) {\n error([\n { text: 'Error generateActions:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n }\n}\n\nfunction roundValue(val: string, textToSend: string): { val: string; textToSend: string } | undefined {\n try {\n const floatedNumber = parseFloat(val);\n const { substring, textWithoutSubstring } = decomposeText(textToSend, '{round:', '}');\n\n const decimalPlaces = substring.split(':')[1].replace('}', '');\n const floatedString = floatedNumber.toFixed(parseInt(decimalPlaces));\n return { val: floatedString, textToSend: textWithoutSubstring };\n } catch (err: any) {\n error([\n { text: 'Error roundValue:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n }\n}\n\nconst exchangePlaceholderWithValue = (textToSend: string, text: string | number): string => {\n let searchString = '';\n if (textToSend.includes('&&')) {\n searchString = '&&';\n } else if (textToSend.includes('&&')) {\n searchString = '&&';\n }\n searchString !== '' && textToSend.toString().indexOf(searchString) != -1\n ? (textToSend = textToSend.replace(searchString, text.toString()))\n : (textToSend += ` ${text}`);\n\n return textToSend;\n};\n\nconst adjustValueType = (value: keyof NewObjectNavStructure, valueType: string): boolean | string | number => {\n if (valueType == 'number') {\n if (!parseFloat(value as string)) {\n error([{ text: 'Error: Value is not a number:', val: value }]);\n return false;\n }\n return parseFloat(value as string);\n }\n if (valueType == 'boolean') {\n if (value == 'true') {\n return true;\n }\n error([{ text: 'Error: Value is not a boolean:', val: value }]);\n return false;\n }\n return value;\n};\n\nconst checkEvent = async (\n dataObject: DataObject,\n id: string,\n state: ioBroker.State,\n menuData: MenuData,\n userListWithChatID: UserListWithChatId[],\n instanceTelegram: string,\n resize_keyboard: boolean,\n one_time_keyboard: boolean,\n usersInGroup: UserInGroup,\n): Promise => {\n const menuArray: string[] = [];\n let ok = false;\n let calledNav = '';\n Object.keys(dataObject.action).forEach(menu => {\n if (dataObject.action[menu] && dataObject.action[menu].events) {\n dataObject.action[menu].events.forEach(event => {\n if (event.ID[0] == id && event.ack[0] == state.ack.toString()) {\n if ((state.val == true || state.val == 'true') && event.condition == 'true') {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n } else if ((state.val == false || state.val == 'false') && event.condition[0] == 'false') {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n } else if (typeof state.val == 'number' && state.val == parseInt(event.condition[0])) {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n } else if (state.val == event.condition[0]) {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n }\n }\n });\n }\n });\n if (ok) {\n if (menuArray.length >= 1) {\n for (const menu of menuArray) {\n if (usersInGroup[menu] && menuData.data[menu][calledNav as keyof DataObject]) {\n for (const user of usersInGroup[menu]) {\n const part = menuData.data[menu][calledNav as keyof DataObject];\n const menus = Object.keys(menuData.data);\n if (part.nav) {\n backMenuFunc(calledNav, part.nav, user);\n }\n if (part && part.nav && JSON.stringify(part?.nav[0]).includes('menu:')) {\n await callSubMenu(\n JSON.stringify(part?.nav[0]),\n menuData,\n user,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n part,\n menuData.data,\n menus,\n null,\n );\n } else {\n await sendNav(\n part,\n user,\n instanceTelegram,\n userListWithChatID,\n resize_keyboard,\n one_time_keyboard,\n );\n }\n }\n }\n }\n }\n }\n\n return ok;\n};\n\nconst getUserToSendFromUserListWithChatID = (\n userListWithChatID: UserListWithChatId[],\n chatID: ioBroker.State | undefined | null,\n): string | null => {\n let userToSend: string | null = null;\n\n if (!chatID) {\n return null;\n }\n\n userListWithChatID.forEach(element => {\n if (element.chatID == chatID.val) {\n userToSend = element.name;\n }\n\n debug([\n { text: 'User and ChatID:', val: element },\n { text: 'User:', val: userToSend },\n ]);\n });\n\n return userToSend;\n};\nconst getMenusWithUserToSend = (menusWithUsers: MenusWithUsers, userToSend: string): NewObjectNavStructureKey[] => {\n const menus: NewObjectNavStructureKey[] = [];\n for (const key in menusWithUsers) {\n if (menusWithUsers[key].includes(userToSend)) {\n menus.push(key);\n }\n }\n return menus;\n};\n\nexport {\n editArrayButtons,\n idBySelector,\n generateNewObjectStructure,\n generateActions,\n calcValue,\n roundValue,\n bindingFunc,\n exchangePlaceholderWithValue,\n adjustValueType,\n checkEvent,\n getUserToSendFromUserListWithChatID,\n getMenusWithUserToSend,\n};\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA+B;AAC/B,oBAA8B;AAC9B,qBAA4B;AAC5B,qBAAwB;AACxB,sBAA6B;AAC7B,qBAA6B;AAC7B,kBAAyB;AAsBzB,MAAM,cAAc,OAChB,MACA,YACA,kBACA,mBACA,iBACA,oBACA,eACgB;AApCpB;AAqCI,QAAM,QAAQ,YAAAA,QAAa,YAAY;AACvC,MAAI;AAEJ,MAAI;AACA,UAAM,gBAAY,6BAAc,MAAM,YAAY,GAAG,EAAE;AACvD,UAAM,eAAe,UAAU,QAAQ,aAAa,EAAE,EAAE,QAAQ,KAAK,EAAE,EAAE,MAAM,GAAG;AAClF,UAAM,gBAA+B;AAAA,MACjC,QAAQ,CAAC;AAAA,IACb;AAEA,aAAS,QAAQ,cAAc;AAC3B,UAAI,CAAC,KAAK,SAAS,GAAG,GAAG;AACrB,cAAM,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC;AAC7B,cAAM,KAAK,KAAK,MAAM,GAAG,EAAE,CAAC;AAE5B,cAAM,SAAS,MAAM,MAAM,qBAAqB,EAAE;AAClD,YAAI,QAAQ;AACR,wBAAc,OAAO,GAAG,MAAI,YAAO,QAAP,mBAAY,eAAc;AAAA,QAC1D;AAAA,MACJ,OAAO;AACH,eAAO,KAAK,cAAc,MAAM,EAAE,QAAQ,SAAU,KAAK;AACrD,iBAAO,KAAK,QAAQ,KAAK,cAAc,OAAO,GAAG,CAAC;AAAA,QACtD,CAAC;AAED,gBAAQ,KAAK,IAAI;AAAA,MACrB;AAAA,IACJ;AACA,cAAM;AAAA,MACF;AAAA,MACA;AAA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A;AAAA,gBACA;AAAA,gBACAC;AAAA,gBACAD;AAAA,gBACAE;AAAA,gBACA;AAAA,gBACA,SAAS;AAAA,gBACT;AAAA,gBACA;AAAA,cACJ;AAAA,YACJ,OAAO;AACH,wBAAM;AAAA,gBACF;AAAA,gBACA;AAAA,gBACA;AAAA,gBACAA;AAAA,gBACAD;AAAA,gBACAD;AAAA,cACJ;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;AAEA,MAAM,sCAAsC,CACxCE,qBACA,WACgB;AAChB,MAAIJ,cAA4B;AAEhC,MAAI,CAAC,QAAQ;AACT,WAAO;AAAA,EACX;AAEA,EAAAI,oBAAmB,QAAQ,aAAW;AAClC,QAAI,QAAQ,UAAU,OAAO,KAAK;AAC9B,MAAAJ,cAAa,QAAQ;AAAA,IACzB;AAEA,8BAAM;AAAA,MACF,EAAE,MAAM,oBAAoB,KAAK,QAAQ;AAAA,MACzC,EAAE,MAAM,SAAS,KAAKA,YAAW;AAAA,IACrC,CAAC;AAAA,EACL,CAAC;AAED,SAAOA;AACX;AACA,MAAM,yBAAyB,CAAC,gBAAgCA,gBAAmD;AAC/G,QAAM,QAAoC,CAAC;AAC3C,aAAW,OAAO,gBAAgB;AAC9B,QAAI,eAAe,GAAG,EAAE,SAASA,WAAU,GAAG;AAC1C,YAAM,KAAK,GAAG;AAAA,IAClB;AAAA,EACJ;AACA,SAAO;AACX;", + "sourcesContent": ["import { sendToTelegram } from './telegram.js';\nimport { decomposeText } from './global';\nimport { callSubMenu } from './subMenu.js';\nimport { sendNav } from './sendNav.js';\nimport { backMenuFunc } from './backMenu.js';\nimport { debug, error } from './logging.js';\nimport TelegramMenu from '../main.js';\nimport type {\n UserListWithChatId,\n BooleanString,\n BindingObject,\n EditArrayButtons,\n GeneratedNavMenu,\n Newline,\n NewObjectNavStructure,\n Actions,\n GenerateActionsArrayOfEntries,\n Switch,\n UserObjectActions,\n GenerateActionsNewObject,\n NewObjectNavStructureKey,\n Part,\n DataObject,\n MenuData,\n UserInGroup,\n MenusWithUsers,\n} from './telegram-menu.js';\n\nconst bindingFunc = async (\n text: string,\n userToSend: string,\n telegramInstance: string,\n one_time_keyboard: boolean,\n resize_keyboard: boolean,\n userListWithChatID: UserListWithChatId[],\n parse_mode: BooleanString,\n): Promise => {\n const _this = TelegramMenu.getInstance();\n let value;\n\n try {\n const substring = decomposeText(text, 'binding:', '}').substring;\n const arrayOfItems = substring.replace('binding:{', '').replace('}', '').split(';');\n const bindingObject: BindingObject = {\n values: {},\n };\n\n for (let item of arrayOfItems) {\n if (!item.includes('?')) {\n const key = item.split(':')[0];\n const id = item.split(':')[1];\n\n const result = await _this.getForeignStateAsync(id);\n if (result) {\n bindingObject.values[key] = result.val?.toString() || '';\n }\n } else {\n Object.keys(bindingObject.values).forEach(function (key) {\n item = item.replace(key, bindingObject.values[key]);\n });\n\n value = eval(item);\n }\n }\n await sendToTelegram(\n userToSend,\n value,\n undefined,\n telegramInstance,\n one_time_keyboard,\n resize_keyboard,\n userListWithChatID,\n parse_mode,\n );\n } catch (e: any) {\n error([\n { text: 'Error:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n }\n};\n\nfunction calcValue(\n _this: TelegramMenu,\n textToSend: string,\n val: string,\n): { textToSend: string; val: string } | undefined {\n const { substring } = decomposeText(textToSend, '{math:', '}');\n const mathValue = substring.replace('{math:', '').replace('}', '');\n try {\n val = eval(val + mathValue);\n textToSend = textToSend.replace(substring, '');\n\n return { textToSend: textToSend, val: val };\n } catch (e: any) {\n error([\n { text: 'Error Eval:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n }\n}\n\nfunction checkValueForOneLine(text: string): string {\n if (!text.includes('&&')) {\n return `${text}&&`;\n }\n return text;\n}\n\nfunction editArrayButtons(val: EditArrayButtons[], _this: TelegramMenu): GeneratedNavMenu[] | null {\n const newVal: GeneratedNavMenu[] = [];\n try {\n val.forEach(element => {\n let value = '';\n if (typeof element.value === 'string') {\n value = checkValueForOneLine(element.value);\n }\n let array: string[] | string[][] = [];\n if (value.indexOf('&&') != -1) {\n array = value.split('&&');\n }\n\n if (array.length > 1) {\n array.forEach(function (element, index: number) {\n if (typeof element === 'string') {\n let navArray = element.split(',');\n navArray = navArray.map(item => item.trim());\n array[index] = navArray;\n }\n });\n } else if (typeof element.value === 'string') {\n array = element.value.split(',');\n array.forEach(function (element, index: number) {\n array[index] = [element.trim()];\n });\n }\n\n newVal.push({ call: element.call, text: element.text, parse_mode: element.parse_mode, nav: array });\n });\n\n return newVal;\n } catch (err: any) {\n error([\n { text: 'Error EditArray:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n return null;\n }\n}\n\nconst idBySelector = async (\n _this: TelegramMenu,\n selector: string,\n text: string,\n userToSend: string,\n newline: Newline,\n telegramInstance: string,\n one_time_keyboard: boolean,\n resize_keyboard: boolean,\n userListWithChatID: UserListWithChatId[],\n): Promise => {\n let text2Send = '';\n try {\n if (!selector.includes('functions')) {\n return;\n }\n\n const functions = selector.replace('functions=', '');\n let enums: string[] | undefined = [];\n const result = await _this.getEnumsAsync();\n\n if (!result || !result['enum.functions'][`enum.functions.${functions}`]) {\n return;\n }\n enums = result['enum.functions'][`enum.functions.${functions}`].common.members;\n if (!enums) {\n return;\n }\n const promises = enums.map(async (id: string) => {\n const value = await _this.getForeignStateAsync(id);\n if (value && value.val !== undefined && value.val !== null) {\n let newText = text;\n let res;\n\n if (text.includes('{common.name}')) {\n res = await _this.getForeignObjectAsync(id);\n _this.log.debug(`Name ${JSON.stringify(res?.common.name)}`);\n\n if (res && res.common.name) {\n newText = newText.replace('{common.name}', res.common.name as string);\n }\n }\n if (text.includes('&&')) {\n text2Send += newText.replace('&&', value.val as string);\n } else if (text.includes('&&')) {\n text2Send += newText.replace('&&', value.val as string);\n } else {\n text2Send += newText;\n text2Send += ` ${value.val}`;\n }\n }\n if (newline === 'true') {\n text2Send += ' \\n';\n } else {\n text2Send += ' ';\n }\n _this.log.debug(`text2send ${JSON.stringify(text2Send)}`);\n });\n Promise.all(promises)\n .then(() => {\n sendToTelegram(\n userToSend,\n text2Send,\n undefined,\n telegramInstance,\n one_time_keyboard,\n resize_keyboard,\n userListWithChatID,\n '',\n ).catch(e => {\n error([\n { text: 'Error SendToTelegram:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n });\n debug([\n { text: 'TextToSend:', val: text2Send },\n { text: 'UserToSend:', val: userToSend },\n ]);\n })\n .catch(e => {\n error([\n { text: 'Error Promise:', val: e.message },\n { text: 'Stack:', val: e.stack },\n ]);\n });\n } catch (error: any) {\n error([\n { text: 'Error idBySelector:', val: error.message },\n { text: 'Stack:', val: error.stack },\n ]);\n }\n};\n\nfunction generateNewObjectStructure(val: GeneratedNavMenu[] | null): NewObjectNavStructure | null {\n try {\n if (!val) {\n return null;\n }\n const obj: NewObjectNavStructure = {};\n val.forEach(function (element) {\n const call = element.call;\n obj[call] = {\n nav: element.nav,\n text: element.text,\n parse_mode:\n element.parse_mode == 'true' || element.parse_mode == 'false' ? element.parse_mode : 'false',\n };\n });\n return obj;\n } catch (err: any) {\n error([\n { text: 'Error GenerateNewObjectStructure:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n return null;\n }\n}\n\nfunction generateActions(\n action: Actions,\n userObject: NewObjectNavStructure,\n): { obj: NewObjectNavStructure; ids: string[] } | undefined {\n try {\n const arrayOfEntries: GenerateActionsArrayOfEntries[] = [\n {\n objName: 'echarts',\n name: 'echarts',\n loop: 'preset',\n elements: [\n { name: 'preset' },\n { name: 'echartInstance' },\n { name: 'background' },\n { name: 'theme' },\n { name: 'filename' },\n ],\n },\n {\n objName: 'loc',\n name: 'location',\n loop: 'latitude',\n elements: [{ name: 'latitude' }, { name: 'longitude' }, { name: 'parse_mode', key: 0 }],\n },\n {\n objName: 'pic',\n name: 'sendPic',\n loop: 'IDs',\n elements: [\n { name: 'id', value: 'IDs' },\n { name: 'fileName' },\n { name: 'delay', value: 'picSendDelay' },\n ],\n },\n {\n objName: 'get',\n name: 'getData',\n loop: 'IDs',\n elements: [\n { name: 'id', value: 'IDs' },\n { name: 'text', type: 'text' },\n { name: 'newline', value: 'newline_checkbox' },\n { name: 'parse_mode', key: 0 },\n ],\n },\n {\n objName: 'httpRequest',\n name: 'httpRequest',\n loop: 'url',\n elements: [{ name: 'url' }, { name: 'user' }, { name: 'password' }, { name: 'filename' }],\n },\n ];\n\n const listOfSetStateIds: string[] = [];\n action.set.forEach(function (element, key) {\n if (key == 0) {\n userObject[element.trigger[0]] = { switch: [] };\n }\n userObject[element.trigger[0]] = { switch: [] };\n element.IDs.forEach(function (id: string, index: number) {\n listOfSetStateIds.push(id);\n const toggle = element.switch_checkbox[index] === 'true';\n let value;\n\n if (element.values[index] === 'true' || element.values[index] === 'false') {\n value = element.values[index] === 'true';\n } else {\n value = element.values[index];\n }\n const newObj: Switch = {\n id: element.IDs[index],\n value: value.toString(),\n toggle: toggle,\n confirm: element.confirm[index],\n returnText: element.returnText[index],\n ack: element.ack ? element.ack[index] : 'false',\n parse_mode: element.parse_mode ? element.parse_mode[0] : 'false',\n };\n if (userObject[element.trigger[0]] && userObject[element.trigger[0]]?.switch) {\n userObject[element.trigger[0]].switch!.push(newObj);\n }\n });\n });\n\n arrayOfEntries.forEach(item => {\n if (action[item.objName as keyof Actions]) {\n action[item.objName as keyof Actions].forEach(function (element, index: number) {\n userObject[element.trigger[0]] = { [item.name]: [] };\n if (index == 0) {\n userObject[element.trigger[0]] = { [item.name as keyof UserObjectActions]: [] };\n }\n\n (element[item.loop as keyof typeof element] as string[]).forEach(function (\n id: string,\n key: number,\n ) {\n const newObj: GenerateActionsNewObject = {};\n item.elements.forEach(elementItem => {\n const name = elementItem.name;\n const value = elementItem.value ? elementItem.value : elementItem.name;\n const newKey = elementItem.key ? elementItem.key : key;\n let val: string | boolean;\n\n if (!element[value as keyof typeof element]) {\n val = false;\n } else {\n val = element[value as keyof typeof element][newKey] || 'false';\n }\n\n if (elementItem.type == 'text' && typeof val === 'string') {\n newObj[name as keyof GenerateActionsNewObject] = val.replace(/&/g, '&') as any;\n } else {\n newObj[name as keyof GenerateActionsNewObject] = val as any;\n }\n });\n if (item.name && typeof item.name === 'string') {\n userObject[element.trigger as NewObjectNavStructureKey][item?.name as keyof Part].push(\n newObj,\n );\n }\n });\n });\n }\n });\n\n return { obj: userObject, ids: listOfSetStateIds };\n } catch (err: any) {\n error([\n { text: 'Error generateActions:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n }\n}\n\nfunction roundValue(val: string, textToSend: string): { val: string; textToSend: string } | undefined {\n try {\n const floatedNumber = parseFloat(val);\n const { substring, textWithoutSubstring } = decomposeText(textToSend, '{round:', '}');\n\n const decimalPlaces = substring.split(':')[1].replace('}', '');\n const floatedString = floatedNumber.toFixed(parseInt(decimalPlaces));\n return { val: floatedString, textToSend: textWithoutSubstring };\n } catch (err: any) {\n error([\n { text: 'Error roundValue:', val: err.message },\n { text: 'Stack:', val: err.stack },\n ]);\n }\n}\n\nconst exchangePlaceholderWithValue = (textToSend: string, text: string | number): string => {\n let searchString = '';\n if (textToSend.includes('&&')) {\n searchString = '&&';\n } else if (textToSend.includes('&&')) {\n searchString = '&&';\n }\n searchString !== '' && textToSend.toString().indexOf(searchString) != -1\n ? (textToSend = textToSend.replace(searchString, text.toString()))\n : (textToSend += ` ${text}`);\n\n return textToSend;\n};\n\nconst adjustValueType = (value: keyof NewObjectNavStructure, valueType: string): boolean | string | number => {\n if (valueType == 'number') {\n if (!parseFloat(value as string)) {\n error([{ text: 'Error: Value is not a number:', val: value }]);\n return false;\n }\n return parseFloat(value as string);\n }\n if (valueType == 'boolean') {\n if (value == 'true') {\n return true;\n }\n error([{ text: 'Error: Value is not a boolean:', val: value }]);\n return false;\n }\n return value;\n};\n\nconst checkEvent = async (\n dataObject: DataObject,\n id: string,\n state: ioBroker.State,\n menuData: MenuData,\n userListWithChatID: UserListWithChatId[],\n instanceTelegram: string,\n resize_keyboard: boolean,\n one_time_keyboard: boolean,\n usersInGroup: UserInGroup,\n): Promise => {\n const menuArray: string[] = [];\n let ok = false;\n let calledNav = '';\n Object.keys(dataObject.action).forEach(menu => {\n if (dataObject.action[menu] && dataObject.action[menu].events) {\n dataObject.action[menu].events.forEach(event => {\n if (event.ID[0] == id && event.ack[0] == state.ack.toString()) {\n if ((state.val == true || state.val == 'true') && event.condition == 'true') {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n } else if ((state.val == false || state.val == 'false') && event.condition[0] == 'false') {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n } else if (typeof state.val == 'number' && state.val == parseInt(event.condition[0])) {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n } else if (state.val == event.condition[0]) {\n ok = true;\n menuArray.push(menu);\n calledNav = event.menu[0];\n }\n }\n });\n }\n });\n if (ok) {\n if (menuArray.length >= 1) {\n for (const menu of menuArray) {\n if (usersInGroup[menu] && menuData.data[menu][calledNav as keyof DataObject]) {\n for (const user of usersInGroup[menu]) {\n const part = menuData.data[menu][calledNav as keyof DataObject];\n const menus = Object.keys(menuData.data);\n if (part.nav) {\n backMenuFunc(calledNav, part.nav, user);\n }\n if (part && part.nav && JSON.stringify(part?.nav[0]).includes('menu:')) {\n await callSubMenu(\n JSON.stringify(part?.nav[0]),\n menuData,\n user,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n part,\n menuData.data,\n menus,\n null,\n );\n } else {\n await sendNav(\n part,\n user,\n instanceTelegram,\n userListWithChatID,\n resize_keyboard,\n one_time_keyboard,\n );\n }\n }\n }\n }\n }\n }\n\n return ok;\n};\n\nconst getUserToSendFromUserListWithChatID = (\n userListWithChatID: UserListWithChatId[],\n chatID: string,\n): string | null => {\n let userToSend: string | null = null;\n\n for (const element of userListWithChatID) {\n if (element.chatID == chatID) {\n userToSend = element.name;\n debug([\n { text: 'User and ChatID:', val: element },\n { text: 'User:', val: userToSend },\n ]);\n break;\n }\n }\n\n return userToSend;\n};\nconst getMenusWithUserToSend = (menusWithUsers: MenusWithUsers, userToSend: string): NewObjectNavStructureKey[] => {\n const menus: NewObjectNavStructureKey[] = [];\n for (const key in menusWithUsers) {\n if (menusWithUsers[key].includes(userToSend)) {\n menus.push(key);\n }\n }\n return menus;\n};\n\nexport {\n editArrayButtons,\n idBySelector,\n generateNewObjectStructure,\n generateActions,\n calcValue,\n roundValue,\n bindingFunc,\n exchangePlaceholderWithValue,\n adjustValueType,\n checkEvent,\n getUserToSendFromUserListWithChatID,\n getMenusWithUserToSend,\n};\n"], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA+B;AAC/B,oBAA8B;AAC9B,qBAA4B;AAC5B,qBAAwB;AACxB,sBAA6B;AAC7B,qBAA6B;AAC7B,kBAAyB;AAsBzB,MAAM,cAAc,OAChB,MACA,YACA,kBACA,mBACA,iBACA,oBACA,eACgB;AApCpB;AAqCI,QAAM,QAAQ,YAAAA,QAAa,YAAY;AACvC,MAAI;AAEJ,MAAI;AACA,UAAM,gBAAY,6BAAc,MAAM,YAAY,GAAG,EAAE;AACvD,UAAM,eAAe,UAAU,QAAQ,aAAa,EAAE,EAAE,QAAQ,KAAK,EAAE,EAAE,MAAM,GAAG;AAClF,UAAM,gBAA+B;AAAA,MACjC,QAAQ,CAAC;AAAA,IACb;AAEA,aAAS,QAAQ,cAAc;AAC3B,UAAI,CAAC,KAAK,SAAS,GAAG,GAAG;AACrB,cAAM,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC;AAC7B,cAAM,KAAK,KAAK,MAAM,GAAG,EAAE,CAAC;AAE5B,cAAM,SAAS,MAAM,MAAM,qBAAqB,EAAE;AAClD,YAAI,QAAQ;AACR,wBAAc,OAAO,GAAG,MAAI,YAAO,QAAP,mBAAY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AAS,IAAI;AACvC,gBAAI,KAAK,KAAK;AACV,gDAAa,WAAW,KAAK,KAAK,IAAI;AAAA,YAC1C;AACA,gBAAI,QAAQ,KAAK,OAAO,KAAK,UAAU,6BAAM,IAAI,EAAE,EAAE,SAAS,OAAO,GAAG;AACpE,wBAAM;AAAA,gBACF,KAAK,UAAU,6BAAM,IAAI,EAAE;AAAA,gBAC3B;AAAA,gBACA;AAAA,gBACA;AAAA,gBACAC;AAAA,gBACAD;AAAA,gBACAE;AAAA,gBACA;AAAA,gBACA,SAAS;AAAA,gBACT;AAAA,gBACA;AAAA,cACJ;AAAA,YACJ,OAAO;AACH,wBAAM;AAAA,gBACF;AAAA,gBACA;AAAA,gBACA;AAAA,gBACAA;AAAA,gBACAD;AAAA,gBACAD;AAAA,cACJ;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;AAEA,MAAM,sCAAsC,CACxCE,qBACA,WACgB;AAChB,MAAIJ,cAA4B;AAEhC,aAAW,WAAWI,qBAAoB;AACtC,QAAI,QAAQ,UAAU,QAAQ;AAC1B,MAAAJ,cAAa,QAAQ;AACrB,gCAAM;AAAA,QACF,EAAE,MAAM,oBAAoB,KAAK,QAAQ;AAAA,QACzC,EAAE,MAAM,SAAS,KAAKA,YAAW;AAAA,MACrC,CAAC;AACD;AAAA,IACJ;AAAA,EACJ;AAEA,SAAOA;AACX;AACA,MAAM,yBAAyB,CAAC,gBAAgCA,gBAAmD;AAC/G,QAAM,QAAoC,CAAC;AAC3C,aAAW,OAAO,gBAAgB;AAC9B,QAAI,eAAe,GAAG,EAAE,SAASA,WAAU,GAAG;AAC1C,YAAM,KAAK,GAAG;AAAA,IAClB;AAAA,EACJ;AACA,SAAO;AACX;", "names": ["TelegramMenu", "text", "val", "_this", "value", "element", "item", "userToSend", "telegramInstance", "one_time_keyboard", "resize_keyboard", "userListWithChatID", "error", "textToSend", "substring"] } diff --git a/build/main.js b/build/main.js index db3ceb21..2ff13a39 100644 --- a/build/main.js +++ b/build/main.js @@ -156,19 +156,20 @@ class TelegramMenu extends utils.Adapter { ); } this.on("stateChange", async (id, state) => { - let userToSend = null; + this.log.debug(`${id} ${JSON.stringify(state)}`); const setStateIdsToListenTo = (0, import_processData.getStateIdsToListenTo)(); if (id === infoConnectionOfTelegram) { isTelegramActive = await (0, import_connection.checkIsTelegramActive)(infoConnectionOfTelegram); if (!isTelegramActive) { + this.log.debug("Telegram is not active"); return; } } - if (id == `${instanceTelegram}.communicate.requestChatId`) { - const chatID = await this.getForeignStateAsync(`${instanceTelegram}.communicate.requestChatId`); - userToSend = (0, import_action.getUserToSendFromUserListWithChatID)(userListWithChatID, chatID); - chatID ? (0, import_logging.debug)([{ text: "ChatID found" }]) : (0, import_logging.debug)([{ text: "ChatID not found" }]); + const obj2 = await this.getChatIDFromState(instanceTelegram, userListWithChatID); + if (!obj2) { + return; } + const { chatID, userToSend } = obj2; if (state && typeof state.val == "string" && state.val.includes("sList:")) { await (0, import_shoppingList.shoppingListSubscribeStateAndDeleteItem)( state.val, @@ -177,10 +178,12 @@ class TelegramMenu extends utils.Adapter { resize_keyboard, one_time_keyboard ); + this.log.debug("Shopping List was found and deleted"); return; } if (id.includes("alexa-shoppinglist") && !id.includes("add_position") && userToSend) { await (0, import_shoppingList.deleteMessageAndSendNewShoppingList)(instanceTelegram, userListWithChatID, userToSend); + this.log.debug("Shopping List was found and deleted"); return; } if (state && await (0, import_action.checkEvent)( @@ -194,12 +197,20 @@ class TelegramMenu extends utils.Adapter { one_time_keyboard, menusWithUsers )) { + this.log.info("Event was found"); return; } + this.log.debug(`ID: ${chatID}`); + this.log.debug(`User vor Abfrage: ${userToSend}`); if ((id == botSendMessageID || id == requestMessageID) && state) { + this.log.debug("Save messageIds"); await (0, import_messageIds.saveMessageIds)(state, instanceTelegram); - } else if (state && typeof state.val === "string" && state.val != "" && id == telegramID && (state == null ? void 0 : state.ack) && userToSend) { - const value = state.val; + } else if (this.isMenuToSend(state, id, telegramID, userToSend)) { + let value = state == null ? void 0 : state.val; + if (!value || !userToSend) { + return; + } + value = value.toString(); const calledValue = value.slice(value.indexOf("]") + 1, value.length); const menus = (0, import_action.getMenusWithUserToSend)(menusWithUsers, userToSend); const dataFound = await (0, import_processData.checkEveryMenuForData)({ @@ -319,6 +330,26 @@ class TelegramMenu extends utils.Adapter { await this.subscribeForeignStatesAsync(telegramID); await this.subscribeForeignStatesAsync(`${instanceTelegram}.info.connection`); } + isMenuToSend(state, id, telegramID, userToSend) { + this.log.debug(`User in Abfrage: ${userToSend}`); + return !!(state && typeof state.val === "string" && state.val != "" && id == telegramID && (state == null ? void 0 : state.ack) && userToSend); + } + async getChatIDFromState(instanceTelegram, userListWithChatID) { + const chatID = await this.getForeignStateAsync(`${instanceTelegram}.communicate.requestChatId`); + this.log.debug(`ChatID nach Abfrage: ${chatID == null ? void 0 : chatID.val}`); + if (!(chatID == null ? void 0 : chatID.val)) { + (0, import_logging.debug)([{ text: "ChatID not found" }]); + return; + } + (0, import_logging.debug)([{ text: "ChatID found" }]); + const userToSend = (0, import_action.getUserToSendFromUserListWithChatID)(userListWithChatID, chatID.val.toString()); + this.log.debug(JSON.stringify(`User to send: ${userToSend}`)); + if (!userToSend) { + this.log.debug("User to send not found"); + return; + } + return { chatID: chatID.val.toString(), userToSend }; + } /** * Is called when adapter shuts down - callback has to be called under any circumstances! * diff --git a/build/main.js.map b/build/main.js.map index 403f53f1..29a4aec8 100644 --- a/build/main.js.map +++ b/build/main.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/main.ts"], - "sourcesContent": ["'use strict';\n/*\n * Created with @iobroker/create-adapter v2.3.0\n */\n\n// The adapter-core module gives you access to the core ioBroker functions\n// you need to create an adapter\nimport * as utils from '@iobroker/adapter-core';\n\nimport {\n generateActions,\n generateNewObjectStructure,\n editArrayButtons,\n getUserToSendFromUserListWithChatID,\n getMenusWithUserToSend,\n exchangePlaceholderWithValue,\n checkEvent,\n} from './lib/action.js';\nimport { _subscribeForeignStatesAsync } from './lib/subscribeStates.js';\nimport { sendToTelegram } from './lib/telegram.js';\nimport { decomposeText, changeValue } from './lib/utilities.js';\nimport { createState } from './lib/createState.js';\nimport { saveMessageIds } from './lib/messageIds.js';\nimport { adapterStartMenuSend } from './lib/adapterStartMenuSend.js';\nimport { getStateIdsToListenTo, checkEveryMenuForData, getTimeouts } from './lib/processData.js';\nimport { shoppingListSubscribeStateAndDeleteItem, deleteMessageAndSendNewShoppingList } from './lib/shoppingList.js';\nimport { debug, error } from './lib/logging.js';\n\nimport type {\n Checkboxes,\n ListOfMenus,\n IsUserActiveCheckbox,\n MenusWithUsers,\n UserListWithChatId,\n DataObject,\n StartSides,\n MenuData,\n GeneratedActions,\n SetStateIds,\n NewObjectNavStructureKey,\n} from './lib/telegram-menu.js';\nimport type { BooleanString } from '@/types/app.js';\nimport { checkIsTelegramActive } from './lib/connection.js';\n\nconst timeoutKey = '0';\nlet subscribeForeignStateIds: string[];\n\nexport default class TelegramMenu extends utils.Adapter {\n private static instance: TelegramMenu;\n /**\n * @param [options] - Adapter options\n */\n public constructor(options: Partial = {}) {\n super({\n ...options,\n name: 'telegram-menu',\n });\n this.on('ready', this.onReady.bind(this));\n this.on('unload', this.onUnload.bind(this));\n TelegramMenu.instance = this;\n }\n public static getInstance(): TelegramMenu {\n return TelegramMenu.instance;\n }\n private async onReady(): Promise {\n await this.setState('info.connection', false, true);\n await createState(this);\n\n let instanceTelegram: string = this.config.instance;\n if (!instanceTelegram || instanceTelegram.length == 0) {\n instanceTelegram = 'telegram.0';\n }\n const telegramID = `${instanceTelegram}.communicate.request`;\n const botSendMessageID = `${instanceTelegram}.communicate.botSendMessageId`;\n const requestMessageID = `${instanceTelegram}.communicate.requestMessageId`;\n const infoConnectionOfTelegram = `${instanceTelegram}.info.connection`;\n\n const checkboxes: Checkboxes = this.config.checkbox as Checkboxes;\n const one_time_keyboard: boolean = checkboxes.oneTiKey;\n const resize_keyboard: boolean = checkboxes.resKey;\n const checkboxNoEntryFound: boolean = checkboxes.checkboxNoValueFound;\n const sendMenuAfterRestart: boolean = checkboxes.sendMenuAfterRestart;\n let listOfMenus: ListOfMenus = [];\n if (this.config.usersInGroup) {\n listOfMenus = Object.keys(this.config.usersInGroup);\n }\n const token = this.config.tokenGrafana;\n const directoryPicture: string = this.config.directory;\n const isUserActiveCheckbox: IsUserActiveCheckbox = this.config.userActiveCheckbox;\n const menusWithUsers: MenusWithUsers = this.config.usersInGroup;\n const textNoEntryFound: string = this.config.textNoEntry;\n const userListWithChatID: UserListWithChatId[] = this.config.userListWithChatID;\n const dataObject: DataObject = this.config.data as DataObject;\n const startSides: StartSides = {};\n\n const menuData: MenuData = {\n data: {},\n } as MenuData;\n\n Object.keys(menusWithUsers).forEach(element => {\n startSides[element] = dataObject.nav[element][0].call;\n });\n\n await this.getForeignObject(infoConnectionOfTelegram, async (err, obj) => {\n try {\n if (err || obj == null) {\n this.log.error(`The State ${infoConnectionOfTelegram} was not found! ${err}`);\n return;\n }\n\n let isTelegramActive = await checkIsTelegramActive(infoConnectionOfTelegram);\n const nav = dataObject.nav;\n const action = dataObject.action;\n\n this.log.info('Telegram was found');\n\n for (const name in nav) {\n const value = editArrayButtons(nav[name], this);\n\n const newObjectStructure = generateNewObjectStructure(value);\n if (newObjectStructure) {\n menuData.data[name] = newObjectStructure;\n }\n\n const generatedActions: GeneratedActions | undefined = generateActions(\n action[name],\n menuData.data[name],\n );\n if (generatedActions) {\n menuData.data[name] = generatedActions?.obj;\n subscribeForeignStateIds = generatedActions?.ids;\n } else {\n debug([{ text: 'No Actions generated!' }]);\n }\n\n if (subscribeForeignStateIds && subscribeForeignStateIds?.length > 0) {\n await _subscribeForeignStatesAsync(subscribeForeignStateIds);\n } else {\n debug([{ text: 'Nothing to Subscribe!' }]);\n }\n\n // Subscribe Events\n if (dataObject.action[name] && dataObject.action[name].events) {\n //TODO: ist event.id string oder string[]?\n dataObject.action[name].events.forEach(async (event: { ID: any }): Promise => {\n await _subscribeForeignStatesAsync([event.ID]);\n });\n }\n debug([\n { text: 'Menu: ', val: name },\n { text: 'Array Buttons: ', val: value },\n { text: 'Gen. Actions: ', val: menuData.data[name] },\n ]);\n }\n debug([\n { text: 'Checkbox', val: checkboxes },\n { text: 'MenuList', val: listOfMenus },\n ]);\n\n if (sendMenuAfterRestart) {\n await adapterStartMenuSend(\n listOfMenus,\n startSides,\n isUserActiveCheckbox,\n menusWithUsers,\n menuData,\n userListWithChatID,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n );\n }\n\n this.on('stateChange', async (id, state) => {\n let userToSend: string | null = null;\n const setStateIdsToListenTo: SetStateIds[] = getStateIdsToListenTo();\n\n if (id === infoConnectionOfTelegram) {\n isTelegramActive = await checkIsTelegramActive(infoConnectionOfTelegram);\n if (!isTelegramActive) {\n return;\n }\n }\n\n if (id == `${instanceTelegram}.communicate.requestChatId`) {\n const chatID = await this.getForeignStateAsync(`${instanceTelegram}.communicate.requestChatId`);\n userToSend = getUserToSendFromUserListWithChatID(userListWithChatID, chatID);\n\n chatID ? debug([{ text: 'ChatID found' }]) : debug([{ text: 'ChatID not found' }]);\n }\n\n if (state && typeof state.val == 'string' && state.val.includes('sList:')) {\n await shoppingListSubscribeStateAndDeleteItem(\n state.val,\n instanceTelegram,\n userListWithChatID,\n resize_keyboard,\n one_time_keyboard,\n );\n return;\n }\n if (id.includes('alexa-shoppinglist') && !id.includes('add_position') && userToSend) {\n await deleteMessageAndSendNewShoppingList(instanceTelegram, userListWithChatID, userToSend);\n return;\n }\n\n if (\n state &&\n (await checkEvent(\n dataObject,\n id,\n state,\n menuData,\n userListWithChatID,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n menusWithUsers,\n ))\n ) {\n return;\n }\n\n if ((id == botSendMessageID || id == requestMessageID) && state) {\n await saveMessageIds(state, instanceTelegram);\n } else if (\n state &&\n typeof state.val === 'string' &&\n state.val != '' &&\n id == telegramID &&\n state?.ack &&\n userToSend\n ) {\n const value = state.val;\n const calledValue = value.slice(value.indexOf(']') + 1, value.length);\n const menus: NewObjectNavStructureKey[] = getMenusWithUserToSend(menusWithUsers, userToSend);\n\n const dataFound = await checkEveryMenuForData({\n menuData,\n calledValue,\n userToSend,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n menus,\n isUserActiveCheckbox,\n token,\n directoryPicture,\n timeoutKey,\n });\n\n debug([\n { text: 'Groups with searched User:', val: menus },\n { text: 'Data found:', val: dataFound },\n ]);\n\n if (!dataFound && checkboxNoEntryFound && userToSend) {\n debug([{ text: 'No Entry found' }]);\n await sendToTelegram(\n userToSend,\n textNoEntryFound,\n undefined,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n '',\n );\n }\n } else if (\n state &&\n setStateIdsToListenTo &&\n setStateIdsToListenTo.find((element: { id: string }) => element.id == id)\n ) {\n debug([{ text: 'State, which is listen to was changed:', val: id }]);\n\n setStateIdsToListenTo.forEach((element, key: number) => {\n if (element.id == id) {\n debug([{ text: 'Send Value:', val: element }]);\n\n if (\n element.confirm != 'false' &&\n !state?.ack &&\n element.returnText.includes('{confirmSet:')\n ) {\n const substring = decomposeText(\n element.returnText,\n '{confirmSet:',\n '}',\n ).substring.split(':');\n let text = '';\n if (state.val) {\n text =\n substring[2] && substring[2].includes('noValue')\n ? substring[1]\n : exchangePlaceholderWithValue(substring[1], state.val as string);\n }\n\n sendToTelegram(\n element.userToSend,\n text,\n undefined,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n element.parse_mode as BooleanString,\n ).catch((e: { message: any; stack: any }) => {\n error([\n { text: 'Error SendToTelegram' },\n { val: e.message },\n { text: 'Error', val: e.stack },\n ]);\n });\n } else if (element.confirm != 'false' && state?.ack) {\n debug([{ text: 'User:', val: element.userToSend }]);\n let textToSend = element.returnText;\n\n if (textToSend.includes('{confirmSet:')) {\n const substring = decomposeText(textToSend, '{confirmSet:', '}').substring;\n textToSend = textToSend.replace(substring, '');\n }\n\n // Wenn eine R\u00FCckgabe des Value an den User nicht gew\u00FCnscht ist soll value durch einen leeren String ersetzt werden\n let value: string | number = '';\n // Change set value in another Value, like true => on, false => off\n let valueChange: string | number = '';\n const resultChange = changeValue(textToSend, state.val as string);\n if (resultChange) {\n valueChange = resultChange.val;\n textToSend = resultChange.textToSend;\n }\n\n if (textToSend?.toString().includes('{novalue}')) {\n value = '';\n textToSend = textToSend.replace('{novalue}', '');\n } else if (state.val || state.val == false) {\n value = state.val?.toString();\n }\n\n valueChange ? (value = valueChange) : value;\n textToSend = exchangePlaceholderWithValue(textToSend, value);\n\n sendToTelegram(\n element.userToSend,\n textToSend,\n undefined,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n element.parse_mode as BooleanString,\n ).catch((e: { message: any; stack: any }) => {\n error([\n { text: 'Error sendToTelegram' },\n { val: e.message },\n { text: 'Error', val: e.stack },\n ]);\n });\n\n setStateIdsToListenTo.splice(key, 1);\n }\n }\n });\n }\n });\n } catch (e: any) {\n error([{ text: 'Error onReady' }, { val: e.message }, { text: 'Error', val: e.stack }]);\n }\n });\n\n await this.subscribeForeignStatesAsync(botSendMessageID);\n await this.subscribeForeignStatesAsync(requestMessageID);\n await this.subscribeForeignStatesAsync(`${instanceTelegram}.communicate.requestChatId`);\n await this.subscribeForeignStatesAsync(telegramID);\n await this.subscribeForeignStatesAsync(`${instanceTelegram}.info.connection`);\n }\n\n /**\n * Is called when adapter shuts down - callback has to be called under any circumstances!\n *\n * @param callback - Is called when adapter has closed all connections and released all resources\n */\n private onUnload(callback: () => void): void {\n const timeouts = getTimeouts();\n try {\n // Here you must clear all timeouts or intervals that may still be active\n timeouts.forEach((element: { timeout: string | number | NodeJS.Timeout | undefined }) => {\n clearTimeout(element.timeout);\n });\n\n callback();\n } catch (e: any) {\n this.log.error(`Error onUnload ${e}`);\n callback();\n }\n }\n\n onMessage(obj: ioBroker.Message): void {\n if (typeof obj === 'object' && obj.message) {\n if (obj.command === 'send') {\n // e.g. send email or pushover or whatever\n this.log.info('send command');\n\n // Send response in callback if required\n if (obj.callback) {\n this.sendTo(obj.from, obj.command, 'Message received', obj.callback);\n }\n }\n }\n }\n}\n\nif (require.main !== module) {\n // Export the constructor in compact mode\n /**\n * @param [options] - Adapter options\n */\n module.exports = (options: Partial> | undefined) =>\n new TelegramMenu(options);\n} else {\n // otherwise start the instance directly\n new TelegramMenu();\n}\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,YAAuB;AAEvB,oBAQO;AACP,6BAA6C;AAC7C,sBAA+B;AAC/B,uBAA2C;AAC3C,yBAA4B;AAC5B,wBAA+B;AAC/B,kCAAqC;AACrC,yBAA0E;AAC1E,0BAA6F;AAC7F,qBAA6B;AAgB7B,wBAAsC;AAEtC,MAAM,aAAa;AACnB,IAAI;AAEJ,MAAO,qBAAmC,MAAM,QAAQ;AAAA,EACpD,OAAe;AAAA;AAAA;AAAA;AAAA,EAIR,YAAY,UAAyC,CAAC,GAAG;AAC5D,UAAM;AAAA,MACF,GAAG;AAAA,MACH,MAAM;AAAA,IACV,CAAC;AACD,SAAK,GAAG,SAAS,KAAK,QAAQ,KAAK,IAAI,CAAC;AACxC,SAAK,GAAG,UAAU,KAAK,SAAS,KAAK,IAAI,CAAC;AAC1C,iBAAa,WAAW;AAAA,EAC5B;AAAA,EACA,OAAc,cAA4B;AACtC,WAAO,aAAa;AAAA,EACxB;AAAA,EACA,MAAc,UAAyB;AACnC,UAAM,KAAK,SAAS,mBAAmB,OAAO,IAAI;AAClD,cAAM,gCAAY,IAAI;AAEtB,QAAI,mBAA2B,KAAK,OAAO;AAC3C,QAAI,CAAC,oBAAoB,iBAAiB,UAAU,GAAG;AACnD,yBAAmB;AAAA,IACvB;AACA,UAAM,aAAa,GAAG,gBAAgB;AACtC,UAAM,mBAAmB,GAAG,gBAAgB;AAC5C,UAAM,m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A,UACL;AAAA,QACJ,CAAC;AAAA,MACL,SAAS,GAAQ;AACb,kCAAM,CAAC,EAAE,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,QAAQ,GAAG,EAAE,MAAM,SAAS,KAAK,EAAE,MAAM,CAAC,CAAC;AAAA,MAC1F;AAAA,IACJ,CAAC;AAED,UAAM,KAAK,4BAA4B,gBAAgB;AACvD,UAAM,KAAK,4BAA4B,gBAAgB;AACvD,UAAM,KAAK,4BAA4B,GAAG,gBAAgB,4BAA4B;AACtF,UAAM,KAAK,4BAA4B,UAAU;AACjD,UAAM,KAAK,4BAA4B,GAAG,gBAAgB,kBAAkB;AAAA,EAChF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,SAAS,UAA4B;AACzC,UAAM,eAAW,gCAAY;AAC7B,QAAI;AAEA,eAAS,QAAQ,CAAC,YAAuE;AACrF,qBAAa,QAAQ,OAAO;AAAA,MAChC,CAAC;AAED,eAAS;AAAA,IACb,SAAS,GAAQ;AACb,WAAK,IAAI,MAAM,mBAAmB,CAAC,EAAE;AACrC,eAAS;AAAA,IACb;AAAA,EACJ;AAAA,EAEA,UAAU,KAA6B;AACnC,QAAI,OAAO,QAAQ,YAAY,IAAI,SAAS;AACxC,UAAI,IAAI,YAAY,QAAQ;AAExB,aAAK,IAAI,KAAK,cAAc;AAG5B,YAAI,IAAI,UAAU;AACd,eAAK,OAAO,IAAI,MAAM,IAAI,SAAS,oBAAoB,IAAI,QAAQ;AAAA,QACvE;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,IAAI,QAAQ,SAAS,QAAQ;AAKzB,SAAO,UAAU,CAAC,YACd,IAAI,aAAa,OAAO;AAChC,OAAO;AAEH,MAAI,aAAa;AACrB;", - "names": [] + "sourcesContent": ["'use strict';\n/*\n * Created with @iobroker/create-adapter v2.3.0\n */\n\n// The adapter-core module gives you access to the core ioBroker functions\n// you need to create an adapter\nimport * as utils from '@iobroker/adapter-core';\n\nimport {\n generateActions,\n generateNewObjectStructure,\n editArrayButtons,\n getUserToSendFromUserListWithChatID,\n getMenusWithUserToSend,\n exchangePlaceholderWithValue,\n checkEvent,\n} from './lib/action.js';\nimport { _subscribeForeignStatesAsync } from './lib/subscribeStates.js';\nimport { sendToTelegram } from './lib/telegram.js';\nimport { decomposeText, changeValue } from './lib/utilities.js';\nimport { createState } from './lib/createState.js';\nimport { saveMessageIds } from './lib/messageIds.js';\nimport { adapterStartMenuSend } from './lib/adapterStartMenuSend.js';\nimport { getStateIdsToListenTo, checkEveryMenuForData, getTimeouts } from './lib/processData.js';\nimport { shoppingListSubscribeStateAndDeleteItem, deleteMessageAndSendNewShoppingList } from './lib/shoppingList.js';\nimport { debug, error } from './lib/logging.js';\n\nimport type {\n Checkboxes,\n ListOfMenus,\n IsUserActiveCheckbox,\n MenusWithUsers,\n UserListWithChatId,\n DataObject,\n StartSides,\n MenuData,\n GeneratedActions,\n SetStateIds,\n NewObjectNavStructureKey,\n} from './lib/telegram-menu.js';\nimport type { BooleanString } from '@/types/app.js';\nimport { checkIsTelegramActive } from './lib/connection.js';\n\nconst timeoutKey = '0';\nlet subscribeForeignStateIds: string[];\n\nexport default class TelegramMenu extends utils.Adapter {\n private static instance: TelegramMenu;\n /**\n * @param [options] - Adapter options\n */\n public constructor(options: Partial = {}) {\n super({\n ...options,\n name: 'telegram-menu',\n });\n this.on('ready', this.onReady.bind(this));\n this.on('unload', this.onUnload.bind(this));\n TelegramMenu.instance = this;\n }\n public static getInstance(): TelegramMenu {\n return TelegramMenu.instance;\n }\n private async onReady(): Promise {\n await this.setState('info.connection', false, true);\n await createState(this);\n\n let instanceTelegram: string = this.config.instance;\n if (!instanceTelegram || instanceTelegram.length == 0) {\n instanceTelegram = 'telegram.0';\n }\n const telegramID = `${instanceTelegram}.communicate.request`;\n const botSendMessageID = `${instanceTelegram}.communicate.botSendMessageId`;\n const requestMessageID = `${instanceTelegram}.communicate.requestMessageId`;\n const infoConnectionOfTelegram = `${instanceTelegram}.info.connection`;\n\n const checkboxes: Checkboxes = this.config.checkbox as Checkboxes;\n const one_time_keyboard: boolean = checkboxes.oneTiKey;\n const resize_keyboard: boolean = checkboxes.resKey;\n const checkboxNoEntryFound: boolean = checkboxes.checkboxNoValueFound;\n const sendMenuAfterRestart: boolean = checkboxes.sendMenuAfterRestart;\n let listOfMenus: ListOfMenus = [];\n if (this.config.usersInGroup) {\n listOfMenus = Object.keys(this.config.usersInGroup);\n }\n const token = this.config.tokenGrafana;\n const directoryPicture: string = this.config.directory;\n const isUserActiveCheckbox: IsUserActiveCheckbox = this.config.userActiveCheckbox;\n const menusWithUsers: MenusWithUsers = this.config.usersInGroup;\n const textNoEntryFound: string = this.config.textNoEntry;\n const userListWithChatID: UserListWithChatId[] = this.config.userListWithChatID;\n const dataObject: DataObject = this.config.data as DataObject;\n const startSides: StartSides = {};\n\n const menuData: MenuData = {\n data: {},\n } as MenuData;\n\n Object.keys(menusWithUsers).forEach(element => {\n startSides[element] = dataObject.nav[element][0].call;\n });\n\n await this.getForeignObject(infoConnectionOfTelegram, async (err, obj) => {\n try {\n if (err || obj == null) {\n this.log.error(`The State ${infoConnectionOfTelegram} was not found! ${err}`);\n return;\n }\n\n let isTelegramActive = await checkIsTelegramActive(infoConnectionOfTelegram);\n const nav = dataObject.nav;\n const action = dataObject.action;\n\n this.log.info('Telegram was found');\n\n for (const name in nav) {\n const value = editArrayButtons(nav[name], this);\n\n const newObjectStructure = generateNewObjectStructure(value);\n if (newObjectStructure) {\n menuData.data[name] = newObjectStructure;\n }\n\n const generatedActions: GeneratedActions | undefined = generateActions(\n action[name],\n menuData.data[name],\n );\n if (generatedActions) {\n menuData.data[name] = generatedActions?.obj;\n subscribeForeignStateIds = generatedActions?.ids;\n } else {\n debug([{ text: 'No Actions generated!' }]);\n }\n\n if (subscribeForeignStateIds && subscribeForeignStateIds?.length > 0) {\n await _subscribeForeignStatesAsync(subscribeForeignStateIds);\n } else {\n debug([{ text: 'Nothing to Subscribe!' }]);\n }\n\n // Subscribe Events\n if (dataObject.action[name] && dataObject.action[name].events) {\n //TODO: ist event.id string oder string[]?\n dataObject.action[name].events.forEach(async (event: { ID: any }): Promise => {\n await _subscribeForeignStatesAsync([event.ID]);\n });\n }\n debug([\n { text: 'Menu: ', val: name },\n { text: 'Array Buttons: ', val: value },\n { text: 'Gen. Actions: ', val: menuData.data[name] },\n ]);\n }\n debug([\n { text: 'Checkbox', val: checkboxes },\n { text: 'MenuList', val: listOfMenus },\n ]);\n\n if (sendMenuAfterRestart) {\n await adapterStartMenuSend(\n listOfMenus,\n startSides,\n isUserActiveCheckbox,\n menusWithUsers,\n menuData,\n userListWithChatID,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n );\n }\n\n this.on('stateChange', async (id, state) => {\n this.log.debug(`${id} ` + ` ${JSON.stringify(state)}`);\n\n const setStateIdsToListenTo: SetStateIds[] = getStateIdsToListenTo();\n\n if (id === infoConnectionOfTelegram) {\n isTelegramActive = await checkIsTelegramActive(infoConnectionOfTelegram);\n if (!isTelegramActive) {\n this.log.debug('Telegram is not active');\n return;\n }\n }\n\n const obj = await this.getChatIDFromState(instanceTelegram, userListWithChatID);\n if (!obj) {\n return;\n }\n const { chatID, userToSend } = obj;\n\n if (state && typeof state.val == 'string' && state.val.includes('sList:')) {\n await shoppingListSubscribeStateAndDeleteItem(\n state.val,\n instanceTelegram,\n userListWithChatID,\n resize_keyboard,\n one_time_keyboard,\n );\n this.log.debug('Shopping List was found and deleted');\n return;\n }\n if (id.includes('alexa-shoppinglist') && !id.includes('add_position') && userToSend) {\n await deleteMessageAndSendNewShoppingList(instanceTelegram, userListWithChatID, userToSend);\n this.log.debug('Shopping List was found and deleted');\n return;\n }\n\n if (\n state &&\n (await checkEvent(\n dataObject,\n id,\n state,\n menuData,\n userListWithChatID,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n menusWithUsers,\n ))\n ) {\n this.log.info('Event was found');\n return;\n }\n this.log.debug(`ID: ${chatID}`);\n this.log.debug(`User vor Abfrage: ${userToSend}`);\n\n if ((id == botSendMessageID || id == requestMessageID) && state) {\n this.log.debug('Save messageIds');\n await saveMessageIds(state, instanceTelegram);\n } else if (this.isMenuToSend(state, id, telegramID, userToSend)) {\n let value = state?.val;\n if (!value || !userToSend) {\n return;\n }\n value = value.toString();\n const calledValue = value.slice(value.indexOf(']') + 1, value.length);\n const menus: NewObjectNavStructureKey[] = getMenusWithUserToSend(menusWithUsers, userToSend);\n\n const dataFound = await checkEveryMenuForData({\n menuData,\n calledValue,\n userToSend,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n menus,\n isUserActiveCheckbox,\n token,\n directoryPicture,\n timeoutKey,\n });\n\n debug([\n { text: 'Groups with searched User:', val: menus },\n { text: 'Data found:', val: dataFound },\n ]);\n\n if (!dataFound && checkboxNoEntryFound && userToSend) {\n debug([{ text: 'No Entry found' }]);\n await sendToTelegram(\n userToSend,\n textNoEntryFound,\n undefined,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n '',\n );\n }\n } else if (\n state &&\n setStateIdsToListenTo &&\n setStateIdsToListenTo.find((element: { id: string }) => element.id == id)\n ) {\n debug([{ text: 'State, which is listen to was changed:', val: id }]);\n\n setStateIdsToListenTo.forEach((element, key: number) => {\n if (element.id == id) {\n debug([{ text: 'Send Value:', val: element }]);\n\n if (\n element.confirm != 'false' &&\n !state?.ack &&\n element.returnText.includes('{confirmSet:')\n ) {\n const substring = decomposeText(\n element.returnText,\n '{confirmSet:',\n '}',\n ).substring.split(':');\n let text = '';\n if (state.val) {\n text =\n substring[2] && substring[2].includes('noValue')\n ? substring[1]\n : exchangePlaceholderWithValue(substring[1], state.val as string);\n }\n\n sendToTelegram(\n element.userToSend,\n text,\n undefined,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n element.parse_mode as BooleanString,\n ).catch((e: { message: any; stack: any }) => {\n error([\n { text: 'Error SendToTelegram' },\n { val: e.message },\n { text: 'Error', val: e.stack },\n ]);\n });\n } else if (element.confirm != 'false' && state?.ack) {\n debug([{ text: 'User:', val: element.userToSend }]);\n let textToSend = element.returnText;\n\n if (textToSend.includes('{confirmSet:')) {\n const substring = decomposeText(textToSend, '{confirmSet:', '}').substring;\n textToSend = textToSend.replace(substring, '');\n }\n\n // Wenn eine R\u00FCckgabe des Value an den User nicht gew\u00FCnscht ist soll value durch einen leeren String ersetzt werden\n let value: string | number = '';\n // Change set value in another Value, like true => on, false => off\n let valueChange: string | number = '';\n const resultChange = changeValue(textToSend, state.val as string);\n if (resultChange) {\n valueChange = resultChange.val;\n textToSend = resultChange.textToSend;\n }\n\n if (textToSend?.toString().includes('{novalue}')) {\n value = '';\n textToSend = textToSend.replace('{novalue}', '');\n } else if (state.val || state.val == false) {\n value = state.val?.toString();\n }\n\n valueChange ? (value = valueChange) : value;\n textToSend = exchangePlaceholderWithValue(textToSend, value);\n\n sendToTelegram(\n element.userToSend,\n textToSend,\n undefined,\n instanceTelegram,\n resize_keyboard,\n one_time_keyboard,\n userListWithChatID,\n element.parse_mode as BooleanString,\n ).catch((e: { message: any; stack: any }) => {\n error([\n { text: 'Error sendToTelegram' },\n { val: e.message },\n { text: 'Error', val: e.stack },\n ]);\n });\n\n setStateIdsToListenTo.splice(key, 1);\n }\n }\n });\n }\n });\n } catch (e: any) {\n error([{ text: 'Error onReady' }, { val: e.message }, { text: 'Error', val: e.stack }]);\n }\n });\n\n await this.subscribeForeignStatesAsync(botSendMessageID);\n await this.subscribeForeignStatesAsync(requestMessageID);\n await this.subscribeForeignStatesAsync(`${instanceTelegram}.communicate.requestChatId`);\n await this.subscribeForeignStatesAsync(telegramID);\n await this.subscribeForeignStatesAsync(`${instanceTelegram}.info.connection`);\n }\n\n private isMenuToSend(\n state: ioBroker.State | null | undefined,\n id: string,\n telegramID: string,\n userToSend: string | null,\n ): boolean {\n this.log.debug(`User in Abfrage: ${userToSend}`);\n\n return !!(\n state &&\n typeof state.val === 'string' &&\n state.val != '' &&\n id == telegramID &&\n state?.ack &&\n userToSend\n );\n }\n\n private async getChatIDFromState(\n instanceTelegram: string,\n userListWithChatID: UserListWithChatId[],\n ): Promise<{ chatID: string; userToSend: string } | undefined> {\n const chatID = await this.getForeignStateAsync(`${instanceTelegram}.communicate.requestChatId`);\n this.log.debug(`ChatID nach Abfrage: ${chatID?.val}`);\n if (!chatID?.val) {\n debug([{ text: 'ChatID not found' }]);\n return;\n }\n debug([{ text: 'ChatID found' }]);\n\n const userToSend = getUserToSendFromUserListWithChatID(userListWithChatID, chatID.val.toString());\n this.log.debug(JSON.stringify(`User to send: ${userToSend}`));\n if (!userToSend) {\n this.log.debug('User to send not found');\n return;\n }\n return { chatID: chatID.val.toString(), userToSend };\n }\n\n /**\n * Is called when adapter shuts down - callback has to be called under any circumstances!\n *\n * @param callback - Is called when adapter has closed all connections and released all resources\n */\n private onUnload(callback: () => void): void {\n const timeouts = getTimeouts();\n try {\n // Here you must clear all timeouts or intervals that may still be active\n timeouts.forEach((element: { timeout: string | number | NodeJS.Timeout | undefined }) => {\n clearTimeout(element.timeout);\n });\n\n callback();\n } catch (e: any) {\n this.log.error(`Error onUnload ${e}`);\n callback();\n }\n }\n\n onMessage(obj: ioBroker.Message): void {\n if (typeof obj === 'object' && obj.message) {\n if (obj.command === 'send') {\n // e.g. send email or pushover or whatever\n this.log.info('send command');\n\n // Send response in callback if required\n if (obj.callback) {\n this.sendTo(obj.from, obj.command, 'Message received', obj.callback);\n }\n }\n }\n }\n}\n\nif (require.main !== module) {\n // Export the constructor in compact mode\n /**\n * @param [options] - Adapter options\n */\n module.exports = (options: Partial> | undefined) =>\n new TelegramMenu(options);\n} else {\n // otherwise start the instance directly\n new TelegramMenu();\n}\n"], + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,YAAuB;AAEvB,oBAQO;AACP,6BAA6C;AAC7C,sBAA+B;AAC/B,uBAA2C;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AAS;AAAA,IACb;AAAA,EACJ;AAAA,EAEA,UAAU,KAA6B;AACnC,QAAI,OAAO,QAAQ,YAAY,IAAI,SAAS;AACxC,UAAI,IAAI,YAAY,QAAQ;AAExB,aAAK,IAAI,KAAK,cAAc;AAG5B,YAAI,IAAI,UAAU;AACd,eAAK,OAAO,IAAI,MAAM,IAAI,SAAS,oBAAoB,IAAI,QAAQ;AAAA,QACvE;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,IAAI,QAAQ,SAAS,QAAQ;AAKzB,SAAO,UAAU,CAAC,YACd,IAAI,aAAa,OAAO;AAChC,OAAO;AAEH,MAAI,aAAa;AACrB;", + "names": ["obj"] } diff --git a/src/lib/action.ts b/src/lib/action.ts index 382004e1..f6c1b3fb 100644 --- a/src/lib/action.ts +++ b/src/lib/action.ts @@ -533,24 +533,20 @@ const checkEvent = async ( const getUserToSendFromUserListWithChatID = ( userListWithChatID: UserListWithChatId[], - chatID: ioBroker.State | undefined | null, + chatID: string, ): string | null => { let userToSend: string | null = null; - if (!chatID) { - return null; - } - - userListWithChatID.forEach(element => { - if (element.chatID == chatID.val) { + for (const element of userListWithChatID) { + if (element.chatID == chatID) { userToSend = element.name; + debug([ + { text: 'User and ChatID:', val: element }, + { text: 'User:', val: userToSend }, + ]); + break; } - - debug([ - { text: 'User and ChatID:', val: element }, - { text: 'User:', val: userToSend }, - ]); - }); + } return userToSend; }; diff --git a/src/main.ts b/src/main.ts index 882d1b8e..d3835168 100644 --- a/src/main.ts +++ b/src/main.ts @@ -172,22 +172,23 @@ export default class TelegramMenu extends utils.Adapter { } this.on('stateChange', async (id, state) => { - let userToSend: string | null = null; + this.log.debug(`${id} ` + ` ${JSON.stringify(state)}`); + const setStateIdsToListenTo: SetStateIds[] = getStateIdsToListenTo(); if (id === infoConnectionOfTelegram) { isTelegramActive = await checkIsTelegramActive(infoConnectionOfTelegram); if (!isTelegramActive) { + this.log.debug('Telegram is not active'); return; } } - if (id == `${instanceTelegram}.communicate.requestChatId`) { - const chatID = await this.getForeignStateAsync(`${instanceTelegram}.communicate.requestChatId`); - userToSend = getUserToSendFromUserListWithChatID(userListWithChatID, chatID); - - chatID ? debug([{ text: 'ChatID found' }]) : debug([{ text: 'ChatID not found' }]); + const obj = await this.getChatIDAndUserToSend(instanceTelegram, userListWithChatID); + if (!obj) { + return; } + const { userToSend } = obj; if (state && typeof state.val == 'string' && state.val.includes('sList:')) { await shoppingListSubscribeStateAndDeleteItem( @@ -197,10 +198,12 @@ export default class TelegramMenu extends utils.Adapter { resize_keyboard, one_time_keyboard, ); + this.log.debug('Shopping List was found and deleted'); return; } if (id.includes('alexa-shoppinglist') && !id.includes('add_position') && userToSend) { await deleteMessageAndSendNewShoppingList(instanceTelegram, userListWithChatID, userToSend); + this.log.debug('Shopping List was found and deleted'); return; } @@ -218,20 +221,19 @@ export default class TelegramMenu extends utils.Adapter { menusWithUsers, )) ) { + this.log.info('Event was found'); return; } if ((id == botSendMessageID || id == requestMessageID) && state) { + this.log.debug('Save messageIds'); await saveMessageIds(state, instanceTelegram); - } else if ( - state && - typeof state.val === 'string' && - state.val != '' && - id == telegramID && - state?.ack && - userToSend - ) { - const value = state.val; + } else if (this.isMenuToSend(state, id, telegramID, userToSend)) { + let value = state?.val; + if (!value || !userToSend) { + return; + } + value = value.toString(); const calledValue = value.slice(value.indexOf(']') + 1, value.length); const menus: NewObjectNavStructureKey[] = getMenusWithUserToSend(menusWithUsers, userToSend); @@ -377,6 +379,44 @@ export default class TelegramMenu extends utils.Adapter { await this.subscribeForeignStatesAsync(`${instanceTelegram}.info.connection`); } + private isMenuToSend( + state: ioBroker.State | null | undefined, + id: string, + telegramID: string, + userToSend: string | null, + ): boolean { + this.log.debug(`User in Abfrage: ${userToSend}`); + + return !!( + state && + typeof state.val === 'string' && + state.val != '' && + id == telegramID && + state?.ack && + userToSend + ); + } + + private async getChatIDAndUserToSend( + instanceTelegram: string, + userListWithChatID: UserListWithChatId[], + ): Promise<{ chatID: string; userToSend: string } | undefined> { + const chatID = await this.getForeignStateAsync(`${instanceTelegram}.communicate.requestChatId`); + + if (!chatID?.val) { + debug([{ text: 'ChatID not found' }]); + return; + } + + const userToSend = getUserToSendFromUserListWithChatID(userListWithChatID, chatID.val.toString()); + this.log.debug(JSON.stringify(`User to send: ${userToSend}`)); + if (!userToSend) { + this.log.debug('User to send not found'); + return; + } + return { chatID: chatID.val.toString(), userToSend }; + } + /** * Is called when adapter shuts down - callback has to be called under any circumstances! *