{ "kind": "open-flow-workflow", "version": 1, "name": "Archive Old Unstarred Gmail", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_72e514bbc3070384": { "name": "Weekdays at midnight UTC", "kind": "cron", "cronTimes": [ { "type": "cron", "expression": "0 0 * * 1-5", "timezone": "UTC" } ] }, "n_e7f336257fee9113": { "inputs": { "scheduledAt": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_72e514bbc3070384", "output": "scheduledAt" } ] } }, "name": "Choose old unstarred inbox messages", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "scheduledAt" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "query" } ], "name": "Choose old unstarred inbox messages", "moduleId": "n_f24bbb1c592a17c9", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_e9e2c9fe5f4e9a0d": { "inputs": { "query": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e7f336257fee9113", "output": "query" } ] }, "previous": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e9e2c9fe5f4e9a0d", "output": "state" } ] } }, "name": "Read all matching messages", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "query" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previous" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" } ], "name": "Read all matching messages", "moduleId": "n_23326dfefe920a53", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [ { "action": "gmail.fetch_emails" } ] } ] } }, "n_17c5e22f205f5639": { "inputs": {}, "name": "More message pages?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "more", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_e9e2c9fe5f4e9a0d", "output": "more" } }, "operator": "isTrue" } ] } ] } ] }, "n_0d548638f822b704": { "inputs": { "collected": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e9e2c9fe5f4e9a0d", "output": "state" } ] }, "previous": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d548638f822b704", "output": "state" } ] } }, "name": "Prepare the next archive batch", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "collected" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previous" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "array", "items": { "type": "string", "description": "An array item." }, "minItems": 1, "maxItems": 1000, "description": "Message IDs to modify in bulk." }, "nullable": false, "handle": "ids" } ], "name": "Prepare the next archive batch", "moduleId": "n_0ea0c3bc53a94bb7", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_26d5947ba8bd127c": { "inputs": {}, "name": "More messages to archive?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "archive", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_0d548638f822b704", "output": "more" } }, "operator": "isTrue" } ] } ] } ] }, "n_d110b86951f1b3ba": { "inputs": { "messageIds": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0d548638f822b704", "output": "ids" } ] }, "removeLabelIds": { "kind": "value", "value": [ "INBOX" ] } }, "name": "Remove the inbox label", "kind": "task", "task": { "inputs": [ { "description": "Message IDs to modify in bulk.", "jsonSchema": { "type": "array", "items": { "type": "string", "description": "An array item." }, "minItems": 1, "maxItems": 1000, "description": "Message IDs to modify in bulk." }, "nullable": false, "handle": "messageIds" }, { "description": "Gmail user ID. Omit to use the connected mailbox.", "jsonSchema": { "type": "string", "description": "Gmail user ID. Omit to use the connected mailbox." }, "nullable": true, "handle": "userId", "value": null }, { "description": "Label IDs to add.", "jsonSchema": { "type": "array", "items": { "type": "string", "description": "An array item." }, "description": "Label IDs to add." }, "nullable": true, "handle": "addLabelIds", "value": null }, { "description": "Label IDs to remove.", "jsonSchema": { "type": "array", "items": { "type": "string", "description": "An array item." }, "description": "Label IDs to remove." }, "nullable": true, "handle": "removeLabelIds", "value": null } ], "outputs": [ { "description": "Whether the Gmail operation completed successfully.", "jsonSchema": { "type": "boolean", "description": "Whether the Gmail operation completed successfully." }, "nullable": false, "handle": "success" } ], "name": "Remove the inbox label", "executor": { "kind": "connector", "action": "gmail.batch_modify_messages" } } }, "n_9d4289f0add59d37": { "inputs": { "success": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d110b86951f1b3ba", "output": "success" } ] } }, "name": "Confirm archive", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "boolean", "description": "Whether the Gmail operation completed successfully." }, "nullable": false, "handle": "success" } ], "outputs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "ok" } ], "name": "Confirm archive", "moduleId": "n_8cc3403a606bbcc9", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } } }, "edges": [ { "source": "n_72e514bbc3070384", "target": "n_e7f336257fee9113" }, { "source": "n_e7f336257fee9113", "target": "n_e9e2c9fe5f4e9a0d" }, { "source": "n_e9e2c9fe5f4e9a0d", "target": "n_17c5e22f205f5639" }, { "source": "n_17c5e22f205f5639", "target": "n_e9e2c9fe5f4e9a0d", "sourceHandle": "more" }, { "source": "n_17c5e22f205f5639", "target": "n_0d548638f822b704", "sourceHandle": "otherwise" }, { "source": "n_0d548638f822b704", "target": "n_26d5947ba8bd127c" }, { "source": "n_26d5947ba8bd127c", "target": "n_d110b86951f1b3ba", "sourceHandle": "archive" }, { "source": "n_d110b86951f1b3ba", "target": "n_9d4289f0add59d37" }, { "source": "n_9d4289f0add59d37", "target": "n_0d548638f822b704" } ] } }, "modules": { "n_f24bbb1c592a17c9": { "name": "Choose old unstarred inbox messages", "imports": [], "source": "export default function archiveQuery({scheduledAt}){const time=Date.parse(scheduledAt);if(!Number.isFinite(time))throw Error('Invalid schedule time');return{query:'in:inbox -is:starred before:'+Math.floor((time-86400000)/1000)};}\n" }, "n_23326dfefe920a53": { "name": "Read all matching messages", "imports": [], "source": "export default async function collect({query,previous},context){const s=previous??{ids:[],cursor:null,seen:[]};if(!Array.isArray(s.ids)||!Array.isArray(s.seen))throw Error('Invalid page state');const r=await context.actions.call('gmail.fetch_emails',{query,maxResults:100,detail:'summary',...(s.cursor?{pageToken:s.cursor}:{})});if(!Array.isArray(r.messages))throw Error('Invalid Gmail page');const ids=[...s.ids],known=new Set(ids);for(const m of r.messages){if(!m||typeof m.messageId!=='string'||!m.messageId||!Array.isArray(m.labelIds)||m.labelIds.some(x=>typeof x!=='string'))throw Error('Invalid Gmail message');if(m.labelIds.includes('INBOX')&&!m.labelIds.includes('STARRED')&&!known.has(m.messageId)){known.add(m.messageId);ids.push(m.messageId)}}const cursor=r.nextPageToken;if(cursor!==null&&(typeof cursor!=='string'||!cursor||s.seen.includes(cursor)))throw Error('Invalid or repeated Gmail page token');return{state:{ids,cursor,seen:cursor?[...s.seen,cursor]:s.seen},more:cursor!==null};}\n" }, "n_0ea0c3bc53a94bb7": { "name": "Prepare the next archive batch", "imports": [], "source": "export default function nextArchive({collected,previous}){const ids=collected?.ids,index=previous?.index??0;if(!Array.isArray(ids)||!Number.isInteger(index)||index<0)throw Error('Invalid archive state');if(index>=ids.length)return{state:{index},more:false,ids:['']};return{state:{index:index+1000},more:true,ids:ids.slice(index,index+1000)};}\n" }, "n_8cc3403a606bbcc9": { "name": "Confirm archive", "imports": [], "source": "export default function confirm({success}){if(success!==true)throw Error('Archive was not confirmed');return{ok:true};}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }