-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtask.flow.ts
More file actions
217 lines (200 loc) · 8.85 KB
/
Copy pathtask.flow.ts
File metadata and controls
217 lines (200 loc) · 8.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import type { Flow } from '@objectstack/spec/automation';
/** Task Reminder Flow — scheduled flow to send reminders for upcoming tasks */
export const TaskReminderFlow: Flow = {
name: 'task_reminder',
label: 'Task Reminder Notification',
description: 'Automated flow to send reminders for tasks approaching their due date',
type: 'schedule',
// A scheduled run has no trigger user, so it must declare its elevation: this
// daily sweep reads every user's tasks to remind them. (ADR-0049 / #1888)
runAs: 'system',
variables: [
{ name: 'tasksToRemind', type: 'record_collection', isInput: false, isOutput: false },
],
nodes: [
{ id: 'start', type: 'start', label: 'Start (Daily 8 AM)', config: { schedule: '0 8 * * *', objectName: 'todo_task' } },
{
id: 'get_upcoming_tasks', type: 'get_record', label: 'Get Tasks Due Tomorrow',
config: { objectName: 'todo_task', filter: { due_date: '{tomorrow}', is_completed: false }, outputVariable: 'tasksToRemind', getAll: true },
},
{
id: 'loop_tasks', type: 'loop', label: 'Loop Through Tasks',
config: { collection: '{tasksToRemind}', iteratorVariable: 'currentTask' },
},
{
id: 'send_reminder', type: 'script', label: 'Send Reminder Email',
config: {
actionType: 'email',
inputs: {
to: '{currentTask.owner.email}',
subject: 'Task Due Tomorrow: {currentTask.subject}',
template: 'task_reminder_email',
data: { taskSubject: '{currentTask.subject}', dueDate: '{currentTask.due_date}', priority: '{currentTask.priority}' },
},
},
},
{ id: 'end', type: 'end', label: 'End' },
],
edges: [
{ id: 'e1', source: 'start', target: 'get_upcoming_tasks', type: 'default' },
{ id: 'e2', source: 'get_upcoming_tasks', target: 'loop_tasks', type: 'default' },
{ id: 'e3', source: 'loop_tasks', target: 'send_reminder', type: 'default' },
{ id: 'e4', source: 'send_reminder', target: 'end', type: 'default' },
],
};
/** Overdue Task Escalation Flow */
export const OverdueEscalationFlow: Flow = {
name: 'overdue_escalation',
label: 'Overdue Task Escalation',
description: 'Escalates tasks that have been overdue for more than 3 days',
type: 'schedule',
// A scheduled run has no trigger user; this daily sweep reads + escalates every
// user's overdue tasks, so it must run elevated. (ADR-0049 / #1888)
runAs: 'system',
variables: [
{ name: 'overdueTasks', type: 'record_collection', isInput: false, isOutput: false },
],
nodes: [
{ id: 'start', type: 'start', label: 'Start (Daily 9 AM)', config: { schedule: '0 9 * * *', objectName: 'todo_task' } },
{
id: 'get_overdue_tasks', type: 'get_record', label: 'Get Severely Overdue Tasks',
config: {
objectName: 'todo_task',
filter: { due_date: { $lt: '{3_days_ago}' }, is_completed: false, is_overdue: true },
outputVariable: 'overdueTasks', getAll: true,
},
},
{
id: 'loop_overdue', type: 'loop', label: 'Loop Through Overdue Tasks',
config: { collection: '{overdueTasks}', iteratorVariable: 'currentTask' },
},
{
id: 'update_priority', type: 'update_record', label: 'Escalate Priority',
config: {
objectName: 'todo_task',
filter: { id: '{currentTask.id}' },
fields: { priority: 'urgent', tags: ['important', 'follow_up'] },
},
},
{
id: 'notify_owner', type: 'script', label: 'Notify Task Owner',
config: {
actionType: 'email',
inputs: {
to: '{currentTask.owner.email}',
subject: 'URGENT: Task Overdue - {currentTask.subject}',
template: 'overdue_escalation_email',
data: { taskSubject: '{currentTask.subject}', dueDate: '{currentTask.due_date}', daysOverdue: '{currentTask.days_overdue}' },
},
},
},
{ id: 'end', type: 'end', label: 'End' },
],
edges: [
{ id: 'e1', source: 'start', target: 'get_overdue_tasks', type: 'default' },
{ id: 'e2', source: 'get_overdue_tasks', target: 'loop_overdue', type: 'default' },
{ id: 'e3', source: 'loop_overdue', target: 'update_priority', type: 'default' },
{ id: 'e4', source: 'update_priority', target: 'notify_owner', type: 'default' },
{ id: 'e5', source: 'notify_owner', target: 'end', type: 'default' },
],
};
/** Task Completion Flow */
export const TaskCompletionFlow: Flow = {
name: 'task_completion',
label: 'Task Completion Process',
description: 'Flow triggered when a task is marked as complete',
type: 'record_change',
variables: [
{ name: 'taskId', type: 'text', isInput: true, isOutput: false },
{ name: 'completedTask', type: 'record', isInput: false, isOutput: false },
],
nodes: [
{ id: 'start', type: 'start', label: 'Start', config: { objectName: 'todo_task', triggerCondition: 'record.status != previous.status && record.status == "completed"' } },
{
id: 'get_task', type: 'get_record', label: 'Get Completed Task',
config: { objectName: 'todo_task', filter: { id: '{taskId}' }, outputVariable: 'completedTask' },
},
{
id: 'check_recurring', type: 'decision', label: 'Is Recurring Task?',
config: { condition: 'vars.completedTask.is_recurring == true' },
},
{
id: 'create_next_task', type: 'create_record', label: 'Create Next Recurring Task',
config: {
objectName: 'todo_task',
fields: {
subject: '{completedTask.subject}', description: '{completedTask.description}',
priority: '{completedTask.priority}', category: '{completedTask.category}',
owner: '{completedTask.owner}', is_recurring: true,
recurrence_type: '{completedTask.recurrence_type}',
recurrence_interval: '{completedTask.recurrence_interval}',
due_date: 'DATEADD({completedTask.due_date}, {completedTask.recurrence_interval}, "{completedTask.recurrence_type}")',
status: 'not_started', is_completed: false,
},
outputVariable: 'newTaskId',
},
},
{ id: 'end', type: 'end', label: 'End' },
],
edges: [
{ id: 'e1', source: 'start', target: 'get_task', type: 'default' },
{ id: 'e2', source: 'get_task', target: 'check_recurring', type: 'default' },
{ id: 'e3', source: 'check_recurring', target: 'create_next_task', type: 'default', condition: 'vars.completedTask.is_recurring == true', label: 'Yes' },
{ id: 'e4', source: 'check_recurring', target: 'end', type: 'default', condition: 'vars.completedTask.is_recurring != true', label: 'No' },
{ id: 'e5', source: 'create_next_task', target: 'end', type: 'default' },
],
};
/** Quick Add Task Flow — screen flow for quickly adding tasks */
export const QuickAddTaskFlow: Flow = {
name: 'quick_add_task',
label: 'Quick Add Task',
description: 'Screen flow for quickly creating a new task',
type: 'screen',
variables: [
{ name: 'subject', type: 'text', isInput: true, isOutput: false },
{ name: 'priority', type: 'text', isInput: true, isOutput: false },
{ name: 'dueDate', type: 'date', isInput: true, isOutput: false },
{ name: 'newTaskId', type: 'text', isInput: false, isOutput: true },
],
nodes: [
{ id: 'start', type: 'start', label: 'Start' },
{
id: 'screen_1', type: 'screen', label: 'Task Details',
config: {
fields: [
{ name: 'subject', label: 'Task Subject', type: 'text', required: true },
{ name: 'priority', label: 'Priority', type: 'select', options: ['low', 'normal', 'high', 'urgent'], defaultValue: 'normal' },
{ name: 'dueDate', label: 'Due Date', type: 'date', required: false },
{ name: 'category', label: 'Category', type: 'select', options: ['personal', 'work', 'shopping', 'health', 'finance', 'other'] },
],
},
},
{
id: 'create_task', type: 'create_record', label: 'Create Task',
config: {
objectName: 'todo_task',
fields: { subject: '{subject}', priority: '{priority}', due_date: '{dueDate}', category: '{category}', status: 'not_started', owner: '{$User.Id}' },
outputVariable: 'newTaskId',
},
},
{
id: 'success_screen', type: 'screen', label: 'Success',
config: {
message: 'Task "{subject}" created successfully!',
buttons: [
{ label: 'Create Another', action: 'restart' },
{ label: 'View Task', action: 'navigate', target: '/task/{newTaskId.id}' },
{ label: 'Done', action: 'finish' },
],
},
},
{ id: 'end', type: 'end', label: 'End' },
],
edges: [
{ id: 'e1', source: 'start', target: 'screen_1', type: 'default' },
{ id: 'e2', source: 'screen_1', target: 'create_task', type: 'default' },
{ id: 'e3', source: 'create_task', target: 'success_screen', type: 'default' },
{ id: 'e4', source: 'success_screen', target: 'end', type: 'default' },
],
};