{
	"name": "Reminder when posts wait for your OK",
	"nodes": [
		{
			"id": "4d3d146b-5fa4-4bf6-bb3f-b611174bcee8",
			"name": "Read me first",
			"type": "n8n-nodes-base.stickyNote",
			"typeVersion": 1,
			"position": [
				-1080,
				60
			],
			"parameters": {
				"content": "## Reminder when posts wait for your OK\nEach morning a Telegram message tells you when posts wait for your OK in sprkly.\n\n### You need\n- The sprkly node: Settings, Community nodes, install `n8n-nodes-sprkly` (self-hosted n8n)\n- A sprkly API key: https://sprkly.app/docs/api?utm_source=n8n&utm_medium=workflow&utm_campaign=posts-waiting-for-approval-reminder\n- A Telegram bot and your chat ID\n\n### Set it up\n1. Add your sprkly key to **Get posts waiting for approval**.\n2. Add your bot to **Send to Telegram**. Put your chat ID in **Settings**.\n3. Set your time zone in Workflow settings.\n4. Failure alert: put your chat ID in **Write the failure alert** and your bot in **Send the failure alert**. Then in Workflow settings, set Error workflow to this workflow.\n\n### Test it\n- Hold one post for approval in sprkly. Run the workflow once.\n- You get one message with the count and a link.",
				"height": 650,
				"width": 560,
				"color": 4
			}
		},
		{
			"id": "254afe84-8bd3-44d5-bca5-9113fff2c36d",
			"name": "Note: count waiting posts",
			"type": "n8n-nodes-base.stickyNote",
			"typeVersion": 1,
			"position": [
				-440,
				60
			],
			"parameters": {
				"content": "## Count waiting posts\nGets every post with the status Pending Approval and counts them.",
				"height": 520,
				"width": 900,
				"color": 7
			}
		},
		{
			"id": "d51041c7-cf51-4d4b-b4ff-116827b32bd4",
			"name": "Note: remind when any",
			"type": "n8n-nodes-base.stickyNote",
			"typeVersion": 1,
			"position": [
				480,
				60
			],
			"parameters": {
				"content": "## Remind when any wait\nA message goes out only when at least one post waits.",
				"height": 520,
				"width": 480,
				"color": 7
			}
		},
		{
			"id": "88366395-b893-49c8-89d4-4f9544b1ca22",
			"name": "Every morning",
			"type": "n8n-nodes-base.scheduleTrigger",
			"typeVersion": 1.3,
			"position": [
				-400,
				320
			],
			"parameters": {
				"rule": {
					"interval": [
						{
							"field": "days",
							"triggerAtHour": 9
						}
					]
				}
			}
		},
		{
			"id": "5054d2ed-ba98-4c19-af36-212dfc71176a",
			"name": "Settings",
			"type": "n8n-nodes-base.set",
			"typeVersion": 3.4,
			"position": [
				-180,
				320
			],
			"parameters": {
				"assignments": {
					"assignments": [
						{
							"id": "f1",
							"name": "telegramChatId",
							"type": "string",
							"value": "YOUR_CHAT_ID"
						}
					]
				},
				"includeOtherFields": true,
				"options": {}
			}
		},
		{
			"id": "761a8d59-7345-439b-8198-b77f3ce1af6e",
			"name": "Get posts waiting for approval",
			"type": "n8n-nodes-sprkly.sprkly",
			"typeVersion": 1.1,
			"position": [
				40,
				320
			],
			"parameters": {
				"resource": "post",
				"operation": "getAll",
				"returnAll": true,
				"filters": {
					"status": "pending_approval"
				},
				"simplify": true
			},
			"executeOnce": true,
			"alwaysOutputData": true
		},
		{
			"id": "1c4a7de4-cd4b-4099-bf41-0e79f4f0e3b9",
			"name": "Count waiting posts",
			"type": "n8n-nodes-base.set",
			"typeVersion": 3.4,
			"position": [
				260,
				320
			],
			"parameters": {
				"assignments": {
					"assignments": [
						{
							"id": "f1",
							"name": "waiting",
							"type": "number",
							"value": "={{ $('Get posts waiting for approval').all().filter(p => p.json.id).length }}"
						}
					]
				},
				"includeOtherFields": false,
				"options": {}
			},
			"executeOnce": true
		},
		{
			"id": "0e650c67-47f4-4a02-8bb6-60959ba4abe2",
			"name": "Any waiting?",
			"type": "n8n-nodes-base.if",
			"typeVersion": 2.2,
			"position": [
				520,
				320
			],
			"parameters": {
				"conditions": {
					"options": {
						"caseSensitive": true,
						"leftValue": "",
						"typeValidation": "loose",
						"version": 2
					},
					"conditions": [
						{
							"id": "any-waiting",
							"leftValue": "={{ $json.waiting }}",
							"rightValue": 0,
							"operator": {
								"type": "number",
								"operation": "gt"
							}
						}
					],
					"combinator": "and"
				},
				"looseTypeValidation": true,
				"options": {}
			}
		},
		{
			"id": "498fec5a-f690-437a-bd4c-929796334e43",
			"name": "Write the message",
			"type": "n8n-nodes-base.set",
			"typeVersion": 3.4,
			"position": [
				740,
				320
			],
			"parameters": {
				"assignments": {
					"assignments": [
						{
							"id": "f1",
							"name": "message",
							"type": "string",
							"value": "={{ ($json.waiting === 1 ? '1 post is' : $json.waiting + ' posts are') + ' waiting for your OK in sprkly. They will not go out until you approve them.\\n\\nCheck them here: https://sprkly.app/schedule?utm_source=n8n&utm_medium=workflow&utm_campaign=posts-waiting-for-approval-reminder&status=pending' }}"
						}
					]
				},
				"includeOtherFields": true,
				"options": {}
			}
		},
		{
			"id": "859f6fa5-e466-4e61-b9a1-a950945839ea",
			"name": "Send to Telegram",
			"type": "n8n-nodes-base.telegram",
			"typeVersion": 1.2,
			"position": [
				960,
				320
			],
			"parameters": {
				"chatId": "={{ $('Settings').first().json.telegramChatId }}",
				"text": "={{ $json.message }}",
				"additionalFields": {
					"appendAttribution": false
				}
			}
		},
		{
			"id": "fc20ee7c-6bff-47a7-9fec-8975d84c472d",
			"name": "When this workflow fails",
			"type": "n8n-nodes-base.errorTrigger",
			"typeVersion": 1,
			"position": [
				-1040,
				790
			],
			"parameters": {}
		},
		{
			"id": "02664268-52af-450f-bf8b-1d9b8217fb10",
			"name": "Write the failure alert",
			"type": "n8n-nodes-base.set",
			"typeVersion": 3.4,
			"position": [
				-820,
				790
			],
			"parameters": {
				"assignments": {
					"assignments": [
						{
							"id": "f1",
							"name": "telegramChatId",
							"type": "string",
							"value": "YOUR_TELEGRAM_CHAT_ID"
						},
						{
							"id": "f2",
							"name": "message",
							"type": "string",
							"value": "={{ 'A workflow stopped.\\n\\nWorkflow: ' + (($json.workflow || {}).name || 'unknown') + '\\nFailed step: ' + (($json.execution || {}).lastNodeExecuted || 'unknown') + '\\nWhy: ' + String((($json.execution || {}).error || {}).message || 'n8n did not give a reason.').slice(0, 300) + (($json.execution || {}).url ? '\\nOpen the run: ' + $json.execution.url : '') }}"
						}
					]
				},
				"includeOtherFields": false,
				"options": {}
			}
		},
		{
			"id": "f9193f82-0c45-4614-94cc-fed6aed2f53b",
			"name": "Send the failure alert",
			"type": "n8n-nodes-base.telegram",
			"typeVersion": 1.2,
			"position": [
				-600,
				790
			],
			"parameters": {
				"chatId": "={{ $json.telegramChatId }}",
				"text": "={{ $json.message }}",
				"additionalFields": {
					"appendAttribution": false
				}
			}
		}
	],
	"connections": {
		"Every morning": {
			"main": [
				[
					{
						"node": "Settings",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Settings": {
			"main": [
				[
					{
						"node": "Get posts waiting for approval",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Get posts waiting for approval": {
			"main": [
				[
					{
						"node": "Count waiting posts",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Count waiting posts": {
			"main": [
				[
					{
						"node": "Any waiting?",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Any waiting?": {
			"main": [
				[
					{
						"node": "Write the message",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Write the message": {
			"main": [
				[
					{
						"node": "Send to Telegram",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"When this workflow fails": {
			"main": [
				[
					{
						"node": "Write the failure alert",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Write the failure alert": {
			"main": [
				[
					{
						"node": "Send the failure alert",
						"type": "main",
						"index": 0
					}
				]
			]
		}
	},
	"pinData": {},
	"active": false,
	"settings": {
		"executionOrder": "v1"
	}
}
