hay guys im in need of your help again i made this flow for a schedule that both sends a message to telegram bot and my alexa but i made it to confusing for my zelf and am now lost
the flow works amazingly except one function node and im unable to figure it out, i hope you guys can set me on the right track or know of a way to simplefy my flow, the problem node i have is named "Check Fallback & Delete Stages" it should delete the inline keyboard but it dossent, here is my full flow
[
{
"id": "1f443c27123414a2",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Send Stage2 Message",
"func": "var awake = flow.get(\"awake\") || false;\nif (awake) return null;\n\nvar chatId = xxxxxxxxxx;\nvar now = new Date();\nvar timeString = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); // Format as HH:MM\n\nvar inlineKeyboard = {\n inline_keyboard: [\n [\n { \"text\": \"I'm Up\", \"callback_data\": \"stage2_yes\" },\n { \"text\": \"Later\", \"callback_data\": \"stage2_no\" }\n ]\n ]\n};\n\nmsg.payload = {\n chatId: chatId,\n type: \"message\"
,\n content: `It's ${timeString}, You Need To Wake Up!`,\n options: { reply_markup: JSON.stringify(inlineKeyboard) }\n};\n\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 4060,
"wires": [
[
"6862b5047772ee42"
]
]
},
{
"id": "6862b5047772ee42",
"type": "telegram sender",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Wake up",
"bot": "",
"haserroroutput": false,
"outputs": 1,
"x": 540,
"y": 4060,
"wires": [
[
"475bf6a4e1951f1c"
]
]
},
{
"id": "475bf6a4e1951f1c",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Store Stage MessageId",
"func": "if (msg.payload && msg.payload.sentMessageId) {\n flow.set(\"stage1MessageId\", msg.payload.sentMessageId);\n} \nelse if (!flow.get(\"stage2MessageId\")) {\n flow.set(\"stage2MessageId\", new Date().getTime());\n}\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 730,
"y": 4060,
"wires": [
[
"a46ec1914e81e040"
]
]
},
{
"id": "a46ec1914e81e040",
"type": "delay",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "",
"pauseType": "delay",
"timeout": "15",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 320,
"y": 4120,
"wires": [
[
"e63f054526e795c4"
]
]
},
{
"id": "e63f054526e795c4",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Check Fallback & Delete Stages",
"func": "var awake = flow.get(\"awake\") || false;\n\nif (!awake) {\n var stage1MsgId = flow.get(\"stage2MessageId\");\n\n if (stage1MsgId) {\n // Delete stage2 message\n msg.payload = {\n chatId: xxxxxxxxxx,\n type: \"deleteMessage\",\n content: stage1MsgId\n };\n return [msg, null];\n } else {\n msg.payload = {\n chatId: xxxxxxxxxx,\n type: \"deleteMessage\",\n content: stage1MsgId\n };\n return [null, msg];\n }\n}\n\n// If awake is true, return null\nreturn null;\n",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 530,
"y": 4120,
"wires": [
[
"9e4880dc45827b73"
],
[
"0359043f261b7cec",
"9e4880dc45827b73"
]
]
},
{
"id": "9e4880dc45827b73",
"type": "telegram sender",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Send Fallback Alert / Delete",
"bot": "",
"haserroroutput": false,
"outputs": 1,
"x": 800,
"y": 4120,
"wires": [
[]
]
},
{
"id": "54f8ccd4acfd74ed",
"type": "cronplus",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "time keeper",
"outputField": "payload",
"timeZone": "",
"storeName": "",
"commandResponseMsgOutput": "output1",
"defaultLocation": "",
"defaultLocationType": "default",
"outputs": 1,
"options": [
{
"name": "reset",
"topic": "topic2",
"payloadType": "default",
"payload": "",
"expressionType": "cron",
"expression": "0 0 7 ? * MON,TUE,WED,THU,FRI,SAT,SUN *",
"location": "",
"offset": "0",
"solarType": "all",
"solarEvents": "sunrise,sunset"
}
],
"x": 210,
"y": 3940,
"wires": [
[
"1f443c27123414a2",
"fdb4e06535e3bd88"
]
]
},
{
"id": "fdb4e06535e3bd88",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Retrieve States",
"func": "// Get the current time\nvar now = new Date();\nvar timeString = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); // Format HH:MM\n\n// Construct the wake-up message\nvar message = `You need to get up! It's ${timeString}.`;\n\n// Pass the message to the next node\nmsg.payload = message;\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 340,
"y": 4000,
"wires": [
[
"7be45b81ea36811d"
]
]
},
{
"id": "a802a78fd3eb825c",
"type": "telegram event",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Callback Query Event",
"bot": "",
"event": "callback_query",
"autoanswer": true,
"x": 220,
"y": 4200,
"wires": [
[
"53b93cdb2ccd9886"
]
]
},
{
"id": "6da30a83cfeea442",
"type": "telegram sender",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Send Confirmation",
"bot": "",
"haserroroutput": false,
"outputs": 1,
"x": 830,
"y": 4200,
"wires": [
[
"691ad392789c6c24"
]
]
},
{
"id": "f4d791086afc5de1",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "done clicked",
"func": "var awake = flow.get(\"awake\") || false;\nif (awake) return null;\n\nmsg.payload = {\n chatId: xxxxxxxxxx,\n type: \"message\",\n content: \"Good Morning \",\n};\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 650,
"y": 4200,
"wires": [
[
"6da30a83cfeea442",
"152c67cb8eba06b9"
]
]
},
{
"id": "91623ac492d60da4",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "later clicked",
"func": "var awake = flow.get(\"awake\") || false;\nif (awake) return null;\nmsg.payload = {\n chatId: xxxxxxxxxx,\n type: \"message\",\n content: \"ill remind you again in 5 minutes\",\n};\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 650,
"y": 4260,
"wires": [
[
"6da30a83cfeea442",
"4f8119002d6205cc",
"e82141bd60368ec9"
]
]
},
{
"id": "691ad392789c6c24",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Store Stage MessageId",
"func": "if (msg.payload && msg.payload.sentMessageId) {\n flow.set(\"stage1MessageId\", msg.payload.sentMessageId);\n} \nelse if (!flow.get(\"stage2MessageId\")) {\n flow.set(\"stage2MessageId\", new Date().getTime());\n}\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 890,
"y": 4260,
"wires": [
[
"e3283cc9eef514da"
]
]
},
{
"id": "e3283cc9eef514da",
"type": "delay",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "",
"pauseType": "delay",
"timeout": "10",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 1080,
"y": 4260,
"wires": [
[
"55563e0d4068caab"
]
]
},
{
"id": "55563e0d4068caab",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Check Fallback & Delete Trash",
"func": "var awake = flow.get(\"awake\") || false;\nif (!awake) {\n // Retrieve message id variables\n var stage1MsgId = flow.get(\"stage1MessageId\");\n if (stage1MsgId) {\n // Delete stage1 message\n msg.payload = {\n chatId: xxxxxxxxxx,\n type: \"deleteMessage\",\n content: stage1MsgId\n };\n return [msg, null]; // Send to output 1\n }\n}\nreturn null;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 4320,
"wires": [
[
"ab91bc36be1e7551"
]
]
},
{
"id": "ab91bc36be1e7551",
"type": "telegram sender",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Send Confirmation",
"bot": "",
"haserroroutput": false,
"outputs": 1,
"x": 930,
"y": 4320,
"wires": [
[]
]
},
{
"id": "4f8119002d6205cc",
"type": "delay",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "",
"pauseType": "delay",
"timeout": "5",
"timeoutUnits": "minutes",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 180,
"y": 4120,
"wires": [
[
"1f443c27123414a2",
"fdb4e06535e3bd88"
]
]
},
{
"id": "7be45b81ea36811d",
"type": "link out",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Passthrough to office",
"mode": "link",
"links": [
"29ad8057789a6185"
],
"x": 540,
"y": 4000,
"wires": [],
"l": true
},
{
"id": "53b93cdb2ccd9886",
"type": "function",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "Process Callback Query ",
"func": "var data = msg.payload.content;\nvar stage1MsgId = flow.get(\"stage1MessageId\"); // Ensure this variable is set in your flow\n\nif (data.indexOf(\"stage2_yes\") > -1) { \n // Stage 2 button \"Yes\"\n flow.set(\"awake\", false);\n node.status({ fill: \"green\", shape: \"dot\", text: \"User is awake2\" });\n msg.payload = {\n chatId: xxxxxxxxxx,\n type: \"deleteMessage\",\n content: stage1MsgId\n };\n return [msg, null];\n\n} else if (data.indexOf(\"stage2_no\") > -1) { \n // Stage 2 button \"No\"\n flow.set(\"awake\", false);\n node.status({ fill: \"yellow\", shape: \"dot\", text: \"User snoozed2\" });\n msg.payload = {\n chatId: xxxxxxxxxx,\n type: \"deleteMessage\",\n content: stage1MsgId\n };\n return [null, msg];\n}\n\n// If no condition is met, do nothing\nreturn null;\n",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 450,
"y": 4200,
"wires": [
[
"f4d791086afc5de1"
],
[
"91623ac492d60da4"
]
]
},
{
"id": "152c67cb8eba06b9",
"type": "change",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "Good Morning",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 200,
"y": 4260,
"wires": [
[
"7be45b81ea36811d"
]
]
},
{
"id": "e82141bd60368ec9",
"type": "change",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ill remind you again in 5 minutes",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 200,
"y": 4320,
"wires": [
[
"7be45b81ea36811d"
]
]
},
{
"id": "0359043f261b7cec",
"type": "delay",
"z": "35ec89c426fd1652",
"g": "b3a04bf2ba8dda81",
"name": "",
"pauseType": "delay",
"timeout": "15",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 720,
"y": 4000,
"wires": [
[
"fdb4e06535e3bd88",
"1f443c27123414a2"
]
]
}
]