{
	"name": "Morning list of today’s sprkly posts",
	"nodes": [
		{
			"id": "4cff595c-b398-4311-87c5-f833638a5f78",
			"name": "Read me first",
			"type": "n8n-nodes-base.stickyNote",
			"typeVersion": 1,
			"position": [
				-1080,
				60
			],
			"parameters": {
				"content": "## Morning list of today’s sprkly posts\nEach morning one Telegram message lists the posts going out in the next 24 hours.\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=daily-queue-digest-to-telegram\n- A Telegram bot and your chat ID\n\n### Set it up\n1. Add your sprkly key to **Get account names** and **Get scheduled posts**.\n2. Add your bot to **Send to Telegram**. Put your chat ID in **Settings**.\n3. In **Settings**, set your time zone. Set the same one 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- Run the workflow once. You get the list, or a note that nothing is set.",
				"height": 702,
				"width": 560,
				"color": 4
			}
		},
		{
			"id": "e0af03c0-7b12-4aa8-9e65-4927e521faa7",
			"name": "Note: read the queue",
			"type": "n8n-nodes-base.stickyNote",
			"typeVersion": 1,
			"position": [
				-440,
				60
			],
			"parameters": {
				"content": "## Read the queue\nGets your accounts and every scheduled post, then keeps the posts set for the next 24 hours.",
				"height": 520,
				"width": 1120,
				"color": 7
			}
		},
		{
			"id": "526f57fb-e160-4b56-96eb-1feefcfdd74a",
			"name": "Note: send the digest",
			"type": "n8n-nodes-base.stickyNote",
			"typeVersion": 1,
			"position": [
				700,
				60
			],
			"parameters": {
				"content": "## Send the digest\nOne message, sorted by time. It lists up to 40 posts and counts the rest.",
				"height": 520,
				"width": 480,
				"color": 7
			}
		},
		{
			"id": "d2eee679-af0a-4a5d-884f-c1e33edffbf5",
			"name": "Every morning",
			"type": "n8n-nodes-base.scheduleTrigger",
			"typeVersion": 1.3,
			"position": [
				-400,
				320
			],
			"parameters": {
				"rule": {
					"interval": [
						{
							"field": "days",
							"triggerAtHour": 8
						}
					]
				}
			}
		},
		{
			"id": "8a830d44-dd69-44a6-8f81-1823cf866d5d",
			"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"
						},
						{
							"id": "f2",
							"name": "timeZone",
							"type": "string",
							"value": "UTC"
						}
					]
				},
				"includeOtherFields": true,
				"options": {}
			}
		},
		{
			"id": "e8f424b9-fd7c-498e-abea-a737348cea24",
			"name": "Get account names",
			"type": "n8n-nodes-sprkly.sprkly",
			"typeVersion": 1.1,
			"position": [
				40,
				320
			],
			"parameters": {
				"resource": "account",
				"operation": "getAll",
				"returnAll": true
			},
			"executeOnce": true,
			"alwaysOutputData": true
		},
		{
			"id": "a5bdf922-23d3-496d-ab3c-60a1bf03c731",
			"name": "Get scheduled posts",
			"type": "n8n-nodes-sprkly.sprkly",
			"typeVersion": 1.1,
			"position": [
				260,
				320
			],
			"parameters": {
				"resource": "post",
				"operation": "getAll",
				"returnAll": true,
				"filters": {
					"status": "scheduled"
				},
				"simplify": true
			},
			"executeOnce": true,
			"alwaysOutputData": true
		},
		{
			"id": "9805c162-cfc8-4d9c-bb1b-1209c81fbcd2",
			"name": "Next 24 hours only",
			"type": "n8n-nodes-base.filter",
			"typeVersion": 2.2,
			"position": [
				480,
				320
			],
			"parameters": {
				"conditions": {
					"options": {
						"caseSensitive": true,
						"leftValue": "",
						"typeValidation": "loose",
						"version": 2
					},
					"conditions": [
						{
							"id": "next-24-hours",
							"leftValue": "={{ !!$json.scheduledTime && DateTime.fromISO($json.scheduledTime).toMillis() >= $now.toMillis() && DateTime.fromISO($json.scheduledTime).toMillis() < $now.plus({ hours: 24 }).toMillis() }}",
							"rightValue": "",
							"operator": {
								"type": "boolean",
								"operation": "true",
								"singleValue": true
							}
						}
					],
					"combinator": "and"
				},
				"looseTypeValidation": true,
				"options": {}
			},
			"alwaysOutputData": true
		},
		{
			"id": "435facb4-b836-40d2-84c2-704df22a335f",
			"name": "Write the digest",
			"type": "n8n-nodes-base.set",
			"typeVersion": 3.4,
			"position": [
				740,
				320
			],
			"parameters": {
				"assignments": {
					"assignments": [
						{
							"id": "f1",
							"name": "message",
							"type": "string",
							"value": "={{ $('Next 24 hours only').all().filter(p => p.json.id).sort((a, b) => DateTime.fromISO(a.json.scheduledTime).toMillis() - DateTime.fromISO(b.json.scheduledTime).toMillis()).length === 0 ? 'Nothing is going out in the next 24 hours.' : 'Going out in the next 24 hours: ' + $('Next 24 hours only').all().filter(p => p.json.id).sort((a, b) => DateTime.fromISO(a.json.scheduledTime).toMillis() - DateTime.fromISO(b.json.scheduledTime).toMillis()).length + '\\n\\n' + $('Next 24 hours only').all().filter(p => p.json.id).sort((a, b) => DateTime.fromISO(a.json.scheduledTime).toMillis() - DateTime.fromISO(b.json.scheduledTime).toMillis()).slice(0, 40).map(p => DateTime.fromISO(p.json.scheduledTime).setZone($('Settings').first().json.timeZone || 'UTC').toFormat('ccc HH:mm') + '  ' + String((p.json.platforms || [])[0] || '') + ' ' + (($('Get account names').all().find(a => a.json.id === (p.json.profileIds || [])[0]) || { json: {} }).json.handle || 'unknown account') + ': ' + (String(p.json.caption || '').length > 60 ? String(p.json.caption).slice(0, 57) + '...' : String(p.json.caption || '(no caption)'))).join('\\n') + ($('Next 24 hours only').all().filter(p => p.json.id).sort((a, b) => DateTime.fromISO(a.json.scheduledTime).toMillis() - DateTime.fromISO(b.json.scheduledTime).toMillis()).length > 40 ? '\\n...and ' + ($('Next 24 hours only').all().filter(p => p.json.id).sort((a, b) => DateTime.fromISO(a.json.scheduledTime).toMillis() - DateTime.fromISO(b.json.scheduledTime).toMillis()).length - 40) + ' more' : '') + '\\n\\nhttps://sprkly.app/schedule?utm_source=n8n&utm_medium=workflow&utm_campaign=daily-queue-digest-to-telegram' }}"
						}
					]
				},
				"includeOtherFields": false,
				"options": {}
			},
			"executeOnce": true
		},
		{
			"id": "2a530f39-abda-4aa1-bd97-e0f3bc676133",
			"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": "479d0a79-3619-400e-acfd-a3d832382a87",
			"name": "When this workflow fails",
			"type": "n8n-nodes-base.errorTrigger",
			"typeVersion": 1,
			"position": [
				-1040,
				842
			],
			"parameters": {}
		},
		{
			"id": "532a3697-f732-4f52-bbf3-6d6f6e966b58",
			"name": "Write the failure alert",
			"type": "n8n-nodes-base.set",
			"typeVersion": 3.4,
			"position": [
				-820,
				842
			],
			"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": "52967e83-cc28-4819-9f34-810e7081ec7b",
			"name": "Send the failure alert",
			"type": "n8n-nodes-base.telegram",
			"typeVersion": 1.2,
			"position": [
				-600,
				842
			],
			"parameters": {
				"chatId": "={{ $json.telegramChatId }}",
				"text": "={{ $json.message }}",
				"additionalFields": {
					"appendAttribution": false
				}
			}
		}
	],
	"connections": {
		"Every morning": {
			"main": [
				[
					{
						"node": "Settings",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Settings": {
			"main": [
				[
					{
						"node": "Get account names",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Get account names": {
			"main": [
				[
					{
						"node": "Get scheduled posts",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Get scheduled posts": {
			"main": [
				[
					{
						"node": "Next 24 hours only",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Next 24 hours only": {
			"main": [
				[
					{
						"node": "Write the digest",
						"type": "main",
						"index": 0
					}
				]
			]
		},
		"Write the digest": {
			"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"
	}
}
