@periskope/types 0.6.308 → 0.6.310

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2210 +1,2304 @@
1
- import { Merge, OverrideProperties } from 'type-fest';
2
- import { Tables } from './supabase.types';
3
- import {
4
- ChatRuleInfoType,
5
- MessageRuleInfoType,
6
- ReactionRuleInfoType,
7
- SenderRuleInfoType,
8
- TicketRuleInfoType,
9
- } from './types';
10
-
11
- export type AppendTypes<T extends object, O extends string> = {
12
- [K in keyof T & string as `${K}${O}${keyof T[K] & string}`]: T[K][keyof T[K]];
13
- };
14
-
15
- export type TicketVariablesType = TicketRuleInfoType['ticket'];
16
-
17
- export type MessageVariablesType = MessageRuleInfoType['message'];
18
-
19
- export type SenderVariablesType = SenderRuleInfoType;
20
-
21
- export type ReactionVariablesType = ReactionRuleInfoType['reaction'];
22
-
23
- export type ChatVariablesType = ChatRuleInfoType;
24
-
25
- export type MessageRulesInfoType = Merge<
26
- AppendTypes<
27
- {
28
- message: MessageVariablesType;
29
- sender: SenderVariablesType;
30
- chat: ChatVariablesType;
31
- },
32
- '.'
33
- >,
34
- {
35
- rule: Tables<'tbl_automation_rules'>[];
36
- id: 'message.message_id';
37
- type: `message.${'created' | 'updated' | 'flagged' | 'deleted' | 'unflagged'}`;
38
- org_id: string;
39
- }
40
- >;
41
-
42
- export type TicketRulesInfoType = Merge<
43
- AppendTypes<
44
- {
45
- ticket: TicketVariablesType;
46
- message: MessageVariablesType;
47
- sender: SenderVariablesType;
48
- chat: ChatVariablesType;
49
- },
50
- '.'
51
- >,
52
- {
53
- id: 'ticket.ticket_id';
54
- type: `ticket.${'created' | 'updated' | 'closed'}`;
55
- org_id: string;
56
- rule: Tables<'tbl_automation_rules'>[];
57
- }
58
- >;
59
-
60
- export type ReactionRulesInfoType = Merge<
61
- AppendTypes<
62
- {
63
- reaction: ReactionVariablesType;
64
- message: MessageVariablesType;
65
- sender: SenderVariablesType;
66
- chat: ChatVariablesType;
67
- },
68
- '.'
69
- >,
70
- {
71
- rule: Tables<'tbl_automation_rules'>[];
72
- id: 'reaction.reaction_id';
73
- type: `reaction.added`;
74
- org_id: string;
75
- }
76
- >;
77
-
78
- export type ChatRulesInfoType = Merge<
79
- AppendTypes<
80
- {
81
- chat: ChatVariablesType;
82
- },
83
- '.'
84
- >,
85
- {
86
- rule: Tables<'tbl_automation_rules'>[];
87
- id: 'chat.chat_id';
88
- type: 'chat.created' | 'chat.label.updated';
89
- org_id: string;
90
- }
91
- >;
92
-
93
- export type RuleInfoType =
94
- | MessageRulesInfoType
95
- | ChatRulesInfoType
96
- | TicketRulesInfoType
97
- | ReactionRulesInfoType;
98
-
99
- export interface Filter {
100
- id: string;
101
- condition:
102
- | 'CONTAINS'
103
- | 'NCONTAINS'
104
- | 'EQ'
105
- | 'NEQ'
106
- | 'LT'
107
- | 'LTE'
108
- | 'GT'
109
- | 'GTE'
110
- | 'KNOWN'
111
- | 'NKNOWN'
112
- | 'IS'
113
- | 'NIS'
114
- | 'ON'
115
- | 'STARTS_WITH'
116
- | 'ENDS_WITH'; // Add other condition types as needed
117
- variable: string;
118
- value: string | string[];
119
- variable_type?: 'string' | 'number' | 'boolean' | 'day-time' | 'date' | 'day'; // Optional, like 'Date'
120
- }
121
-
122
- export const isFilter = (filter: any): filter is Filter => {
123
- return (
124
- typeof filter === 'object' &&
125
- 'id' in filter &&
126
- 'condition' in filter &&
127
- 'variable' in filter &&
128
- 'value' in filter
129
- );
130
- };
131
-
132
- export const FilterNameMap: Record<
133
- Filter['condition'],
134
- {
135
- name: string;
136
- input: boolean;
137
- }
138
- > = {
139
- EQ: {
140
- name: 'equals to',
141
- input: true,
142
- },
143
- NEQ: {
144
- name: 'not equals to',
145
- input: true,
146
- },
147
- CONTAINS: {
148
- name: 'contains',
149
- input: true,
150
- },
151
- NCONTAINS: {
152
- name: 'does not contain',
153
- input: true,
154
- },
155
- LT: {
156
- name: 'less than',
157
- input: true,
158
- },
159
- LTE: {
160
- name: 'less than or equals to',
161
- input: true,
162
- },
163
- GT: {
164
- name: 'greater than',
165
- input: true,
166
- },
167
- GTE: {
168
- name: 'greater than or equals to',
169
- input: true,
170
- },
171
- KNOWN: {
172
- name: 'is known',
173
- input: false,
174
- },
175
- NKNOWN: {
176
- name: 'is not known',
177
- input: false,
178
- },
179
- IS: {
180
- name: 'is',
181
- input: true,
182
- },
183
- NIS: {
184
- name: 'is not',
185
- input: true,
186
- },
187
- ON: {
188
- name: 'on',
189
- input: true,
190
- },
191
- STARTS_WITH: {
192
- name: 'starts with',
193
- input: true,
194
- },
195
- ENDS_WITH: {
196
- name: 'ends with',
197
- input: true,
198
- },
199
- };
200
-
201
- export type VariableNameValueType = {
202
- text: string;
203
- type:
204
- | 'string'
205
- | 'time'
206
- | 'boolean'
207
- | 'dropdown'
208
- | 'day-time'
209
- | 'number'
210
- | 'date';
211
- variable_type: 'string' | 'number' | 'boolean' | 'day-time' | 'date';
212
- value?:
213
- | string
214
- | {
215
- id: string;
216
- value: string | number | boolean;
217
- label: string;
218
- }[]
219
- | null;
220
- filters:
221
- | Partial<
222
- Record<
223
- Filter['condition'],
224
- {
225
- info?: string;
226
- }
227
- >
228
- >
229
- | Filter['condition'][];
230
- hidden?: boolean;
231
- placeholder?: string;
232
- info?: string;
233
- };
234
-
235
- export const MessageVariableNameMap: Record<
236
- keyof AppendTypes<{ message: MessageVariablesType }, '.'>,
237
- VariableNameValueType
238
- > = {
239
- 'message.body': {
240
- text: 'Message Body',
241
- type: 'string',
242
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
243
- placeholder: 'e.g. Test message',
244
- variable_type: 'string',
245
- },
246
- 'message.sender_phone': {
247
- text: 'Message Sender Phone',
248
- type: 'string',
249
- filters: ['EQ', 'NEQ'],
250
- placeholder: 'e.g. 919876543210',
251
- variable_type: 'string',
252
- },
253
- 'message.timestamp': {
254
- text: 'Message Timestamp',
255
- type: 'day-time',
256
- filters: {
257
- LT: {
258
- info: 'When message is received before mentioned time (UTC)',
259
- },
260
- LTE: {
261
- info: 'When message is received before mentioned time (UTC)',
262
- },
263
- GT: {
264
- info: 'When message is received after mentioned time (UTC)',
265
- },
266
- GTE: {
267
- info: 'When message is received on or after mentioned time (UTC)',
268
- },
269
- ON: {
270
- info: 'When message is received on mentioned days',
271
- },
272
- },
273
- variable_type: 'day-time',
274
- info: 'The timestamp when the message was received',
275
- },
276
- 'message.flag_status': {
277
- text: 'Message Flag Status',
278
- filters: ['IS'],
279
- type: 'boolean',
280
- variable_type: 'boolean',
281
- },
282
- 'message.has_quoted_msg': {
283
- text: 'Has Quoted Message',
284
- filters: ['IS'],
285
- type: 'boolean',
286
- variable_type: 'boolean',
287
- },
288
- 'message.media': {
289
- text: 'Has Media',
290
- type: 'boolean',
291
- filters: ['KNOWN', 'NKNOWN'],
292
- variable_type: 'boolean',
293
- },
294
- 'message.performed_by': {
295
- text: 'Message Sent By (email)',
296
- type: 'dropdown',
297
- value: 'org.members',
298
- filters: ['EQ', 'NEQ'],
299
- variable_type: 'string',
300
- },
301
- 'message.chat_id': {
302
- text: 'Chat ID',
303
- type: 'string',
304
- filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
305
- hidden: true,
306
- variable_type: 'string',
307
- },
308
- 'message.message_ticket_id': {
309
- text: 'Message Ticket ID',
310
- type: 'string',
311
- filters: ['EQ', 'NEQ'],
312
- hidden: true,
313
- variable_type: 'string',
314
- },
315
- 'message.message_id': {
316
- text: 'Message ID',
317
- type: 'string',
318
- filters: ['EQ', 'NEQ'],
319
- hidden: true,
320
- variable_type: 'string',
321
- },
322
- 'message.org_phone': {
323
- text: 'Org Phone',
324
- type: 'string',
325
- filters: ['EQ', 'NEQ'],
326
- hidden: true,
327
- variable_type: 'string',
328
- },
329
- 'message.org_id': {
330
- text: 'Org ID',
331
- type: 'string',
332
- filters: ['EQ', 'NEQ'],
333
- hidden: true,
334
- variable_type: 'string',
335
- },
336
- 'message.message_type': {
337
- text: 'Message Type',
338
- type: 'dropdown',
339
- value: [
340
- { id: 'text', value: 'chat', label: 'Text' },
341
- { id: 'image', value: 'image', label: 'Image' },
342
- { id: 'video', value: 'video', label: 'Video' },
343
- { id: 'audio', value: 'audio', label: 'Audio' },
344
- { id: 'audio', value: 'ptt', label: 'PTT (Audio voice message)' },
345
- { id: 'document', value: 'document', label: 'Document' },
346
- ],
347
- filters: ['EQ', 'NEQ'],
348
- variable_type: 'string',
349
- },
350
- 'message.author': {
351
- text: 'Message Author',
352
- type: 'string',
353
- filters: ['EQ', 'NEQ'],
354
- hidden: true,
355
- variable_type: 'string',
356
- },
357
- };
358
-
359
- export const SenderVariableNameMap: Record<
360
- keyof AppendTypes<{ sender: SenderVariablesType }, '.'>,
361
- VariableNameValueType
362
- > = {
363
- 'sender.is_internal': {
364
- text: 'Sender Is Internal',
365
- type: 'boolean',
366
- filters: ['IS'],
367
- variable_type: 'boolean',
368
- },
369
- 'sender.contact_name': {
370
- text: 'Sender Name',
371
- type: 'string',
372
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
373
- placeholder: 'e.g. John Doe',
374
- variable_type: 'string',
375
- },
376
- 'sender.contact_id': {
377
- text: 'Sender Phone',
378
- type: 'string',
379
- filters: ['EQ', 'NEQ'],
380
- placeholder: 'e.g. 919876543210',
381
- variable_type: 'string',
382
- },
383
- 'sender.org_id': {
384
- text: 'Org ID',
385
- type: 'string',
386
- filters: ['EQ', 'NEQ'],
387
- hidden: true,
388
- variable_type: 'string',
389
- },
390
- 'sender.labels': {
391
- text: 'Sender Contact Labels',
392
- type: 'dropdown',
393
- value: 'org.labels',
394
- filters: ['CONTAINS', 'NCONTAINS'],
395
- variable_type: 'string',
396
- },
397
- 'sender.is_admin': {
398
- text: 'Sender Is Admin',
399
- type: 'dropdown',
400
- filters: ['EQ', 'NEQ'],
401
- value: [
402
- {
403
- id: 'true',
404
- value: 'true',
405
- label: 'True',
406
- },
407
- {
408
- id: 'false',
409
- value: 'false',
410
- label: 'False',
411
- },
412
- ],
413
- variable_type: 'boolean',
414
- },
415
- };
416
-
417
- export const ChatVariableNameMap: Record<
418
- keyof AppendTypes<{ chat: ChatVariablesType }, '.'>,
419
- VariableNameValueType
420
- > = {
421
- 'chat.assigned_to': {
422
- text: 'Chat Assignee',
423
- type: 'dropdown',
424
- value: 'org.members',
425
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
426
- variable_type: 'string',
427
- },
428
- 'chat.chat_name': {
429
- text: 'Chat Name',
430
- type: 'string',
431
- filters: ['EQ', 'NEQ', 'CONTAINS', 'NCONTAINS'],
432
- placeholder: 'e.g. Support Chat',
433
- variable_type: 'string',
434
- },
435
- 'chat.org_phone': {
436
- text: 'Chat Org Phone',
437
- type: 'dropdown',
438
- value: 'org.org_phones',
439
- filters: ['EQ', 'NEQ'],
440
- variable_type: 'string',
441
- },
442
- 'chat.chat_type': {
443
- text: 'Chat Type',
444
- type: 'dropdown',
445
- value: [
446
- { id: 'user', value: 'user', label: 'User' },
447
- { id: 'group', value: 'group', label: 'Group' },
448
- ],
449
- filters: ['EQ', 'NEQ'],
450
- variable_type: 'string',
451
- },
452
- 'chat.members': {
453
- text: 'Chat Members',
454
- type: 'string',
455
- filters: ['CONTAINS', 'NCONTAINS'],
456
- placeholder: 'e.g. 919876543210',
457
- variable_type: 'string',
458
- },
459
- 'chat.labels': {
460
- text: 'Chat Labels',
461
- type: 'dropdown',
462
- value: 'org.labels',
463
- filters: ['CONTAINS', 'NCONTAINS'],
464
- variable_type: 'string',
465
- },
466
- 'chat.chat_id': {
467
- text: 'Chat ID',
468
- type: 'string',
469
- filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
470
- placeholder: 'e.g. 12027747916749@g.us',
471
- variable_type: 'string',
472
- },
473
- 'chat.chat_org_phones': {
474
- text: 'Chat Org Phones',
475
- type: 'dropdown',
476
- filters: ['CONTAINS', 'NCONTAINS'],
477
- hidden: true,
478
- variable_type: 'string',
479
- },
480
- 'chat.org_id': {
481
- text: 'Org ID',
482
- type: 'string',
483
- filters: [],
484
- hidden: true,
485
- variable_type: 'string',
486
- },
487
- 'chat.messages_admins_only': {
488
- text: 'Messages Admins Only (Chat Settings)',
489
- type: 'boolean',
490
- filters: ['EQ', 'NEQ'],
491
- value: [
492
- {
493
- id: 'true',
494
- value: 'true',
495
- label: 'True',
496
- },
497
- {
498
- id: 'false',
499
- value: 'false',
500
- label: 'False',
501
- },
502
- ],
503
- variable_type: 'boolean',
504
- },
505
- 'chat.info_admins_only': {
506
- text: 'Info Admins Only (Chat Settings)',
507
- type: 'boolean',
508
- filters: ['EQ', 'NEQ'],
509
- value: [
510
- {
511
- id: 'true',
512
- value: 'true',
513
- label: 'True',
514
- },
515
- {
516
- id: 'false',
517
- value: 'false',
518
- label: 'False',
519
- },
520
- ],
521
- variable_type: 'boolean',
522
- },
523
- 'chat.has_flagged_messages': {
524
- text: 'Chat Has Flagged Messages',
525
- type: 'boolean',
526
- filters: ['EQ', 'NEQ'],
527
- value: [
528
- {
529
- id: 'true',
530
- value: 'true',
531
- label: 'True',
532
- },
533
- {
534
- id: 'false',
535
- value: 'false',
536
- label: 'False',
537
- },
538
- ],
539
- variable_type: 'boolean',
540
- },
541
- 'chat.group_description': {
542
- text: 'Group Description',
543
- type: 'string',
544
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
545
- placeholder: 'e.g. Group description',
546
- variable_type: 'string',
547
- },
548
- 'chat.custom_properties': {
549
- text: 'Chat Custom Properties',
550
- type: 'dropdown',
551
- value: 'org.custom_properties',
552
- filters: ['EQ', 'NEQ'],
553
- hidden: true,
554
- variable_type: 'string',
555
- },
556
- 'chat.initiated_by': {
557
- text: 'Chat Initiated By',
558
- type: 'dropdown',
559
- value: 'org.members',
560
- filters: ['EQ', 'NEQ'],
561
- variable_type: 'string',
562
- hidden: true,
563
- },
564
- 'chat.created_at': {
565
- text: 'Chat Created At',
566
- type: 'day-time',
567
- filters: {
568
- LT: {
569
- info: 'When chat is created before mentioned time (UTC)',
570
- },
571
- LTE: {
572
- info: 'When chat is created before mentioned time (UTC)',
573
- },
574
- GT: {
575
- info: 'When chat is created after mentioned time (UTC)',
576
- },
577
- GTE: {
578
- info: 'When chat is created on or after mentioned time (UTC)',
579
- },
580
- ON: {
581
- info: 'When chat is created on mentioned days',
582
- },
583
- },
584
- variable_type: 'day-time',
585
- },
586
- };
587
-
588
- export const TicketVariableNameMap: Record<
589
- keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>,
590
- VariableNameValueType
591
- > = {
592
- 'ticket.subject': {
593
- text: 'Ticket Subject',
594
- type: 'string',
595
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
596
- placeholder: 'e.g. Test ticket',
597
- variable_type: 'string',
598
- },
599
- 'ticket.status': {
600
- text: 'Ticket Status',
601
- type: 'dropdown',
602
- value: [
603
- { id: 'open', value: 'open', label: 'Open' },
604
- { id: 'closed', value: 'closed', label: 'Closed' },
605
- { id: 'inprogress', value: 'inprogress', label: 'In progress' },
606
- ],
607
- filters: ['EQ', 'NEQ'],
608
- variable_type: 'string',
609
- },
610
- 'ticket.priority': {
611
- text: 'Ticket Priority',
612
- type: 'dropdown',
613
- value: [
614
- { id: '0', value: '0', label: 'No Priority' },
615
- { id: '1', value: '1', label: 'Low' },
616
- { id: '2', value: '2', label: 'Medium' },
617
- { id: '3', value: '3', label: 'High' },
618
- { id: '4', value: '4', label: 'Urgent' },
619
- ],
620
- filters: ['EQ', 'NEQ'],
621
- variable_type: 'string',
622
- },
623
- 'ticket.assignee': {
624
- text: 'Ticket Assignee',
625
- type: 'dropdown',
626
- value: 'org.members',
627
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
628
- variable_type: 'string',
629
- },
630
- 'ticket.labels': {
631
- text: 'Ticket Labels',
632
- type: 'dropdown',
633
- value: 'org.labels',
634
- filters: ['CONTAINS', 'NCONTAINS'],
635
- variable_type: 'string',
636
- },
637
- 'ticket.is_deleted': {
638
- text: 'Ticket Is Deleted',
639
- type: 'boolean',
640
- value: [
641
- {
642
- id: 'true',
643
- value: 'true',
644
- label: 'True',
645
- },
646
- {
647
- id: 'false',
648
- value: 'false',
649
- label: 'False',
650
- },
651
- ],
652
- filters: ['IS'],
653
- variable_type: 'boolean',
654
- },
655
- 'ticket.raised_by': {
656
- text: 'Ticket Raised By',
657
- type: 'dropdown',
658
- value: 'org.members',
659
- filters: ['EQ', 'NEQ'],
660
- variable_type: 'string',
661
- },
662
- 'ticket.due_date': {
663
- text: 'Ticket Due Date',
664
- type: 'date',
665
- filters: ['KNOWN', 'NKNOWN'],
666
- variable_type: 'date',
667
- hidden: true,
668
- },
669
- 'ticket.ticket_id': {
670
- text: 'Ticket ID',
671
- type: 'string',
672
- filters: ['EQ', 'NEQ'],
673
- hidden: true,
674
- variable_type: 'string',
675
- },
676
- 'ticket.org_id': {
677
- text: 'Org ID',
678
- type: 'string',
679
- filters: ['EQ', 'NEQ'],
680
- hidden: true,
681
- variable_type: 'string',
682
- },
683
- 'ticket.custom_properties': {
684
- text: 'Ticket Custom Properties',
685
- type: 'dropdown',
686
- value: 'org.custom_properties',
687
- filters: ['EQ', 'NEQ'],
688
- hidden: true,
689
- variable_type: 'string',
690
- },
691
- 'ticket.created_at': {
692
- text: 'Ticket Created At',
693
- type: 'day-time',
694
- filters: {
695
- LT: {
696
- info: 'When ticket is created before mentioned time (UTC)',
697
- },
698
- LTE: {
699
- info: 'When ticket is created before mentioned time (UTC)',
700
- },
701
- GT: {
702
- info: 'When ticket is created after mentioned time (UTC)',
703
- },
704
- GTE: {
705
- info: 'When ticket is created on or after mentioned time (UTC)',
706
- },
707
- ON: {
708
- info: 'When ticket is created on mentioned days',
709
- },
710
- },
711
- variable_type: 'day-time',
712
- },
713
- 'ticket.chat_id': {
714
- text: 'Chat ID',
715
- type: 'string',
716
- filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
717
- hidden: true,
718
- variable_type: 'string',
719
- },
720
- };
721
-
722
- export const ReactionVariableNameMap: Record<
723
- keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>,
724
- VariableNameValueType
725
- > = {
726
- 'reaction.reaction': {
727
- text: 'Reaction',
728
- type: 'string',
729
- filters: ['EQ', 'NEQ'],
730
- placeholder: 'e.g. 👍',
731
- variable_type: 'string',
732
- },
733
- 'reaction.sender_id': {
734
- text: 'Reaction Sender Phone',
735
- type: 'string',
736
- filters: ['EQ', 'NEQ'],
737
- placeholder: 'e.g. 919876543210',
738
- variable_type: 'string',
739
- },
740
- 'reaction.message_id': {
741
- text: 'Reaction Message ID',
742
- type: 'string',
743
- filters: ['EQ', 'NEQ'],
744
- hidden: true,
745
- variable_type: 'string',
746
- },
747
- 'reaction.chat_id': {
748
- text: 'Chat ID',
749
- type: 'string',
750
- filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
751
- hidden: true,
752
- variable_type: 'string',
753
- },
754
- 'reaction.reaction_id': {
755
- text: 'Reaction ID',
756
- type: 'string',
757
- filters: ['EQ', 'NEQ'],
758
- hidden: true,
759
- variable_type: 'string',
760
- },
761
- };
762
-
763
- export enum FilterConditionMap {
764
- 'CONTAINS' = 'contains',
765
- 'NCONTAINS' = 'does not contain',
766
- 'EQ' = '=',
767
- 'NEQ' = '<>',
768
- 'LT' = '<',
769
- 'LTE' = '<=',
770
- 'GT' = '>',
771
- 'GTE' = '>=',
772
- 'KNOWN' = 'is known',
773
- 'NKNOWN' = 'is not known',
774
- 'IS' = '=',
775
- 'NIS' = '<>',
776
- 'ON' = 'on',
777
- 'STARTS_WITH' = 'starts with',
778
- 'ENDS_WITH' = 'ends with',
779
- }
780
-
781
- interface FilterGroup {
782
- filters: Filter[];
783
- condition: 'allOf' | 'anyOf';
784
- }
785
-
786
- export interface Conditions {
787
- filters: FilterGroup[];
788
- condition: 'allOf' | 'anyOf';
789
- variables: string[];
790
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
791
- org_phones: string[];
792
- allow_messages_from_org_phones?: boolean;
793
- }
794
-
795
- export type SendMessageAction = {
796
- id: string;
797
- type: 'send_message';
798
- metadata: {
799
- message: string;
800
- media?: {
801
- url: string;
802
- type: 'image' | 'video' | 'audio' | 'document';
803
- name: string;
804
- };
805
- maintain_flag_status: 'true' | 'false';
806
- debounce_messages: 'true' | 'false';
807
- debounce_message_time:
808
- | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
809
- | null
810
- | undefined;
811
- };
812
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
813
- };
814
-
815
- export type NotifyHttpAction = {
816
- id: string;
817
- type: 'notify_http';
818
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
819
- metadata: {
820
- url: string;
821
- };
822
- };
823
-
824
- export type CreateTicketAction = {
825
- id: string;
826
- type: 'create_ticket';
827
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
828
- metadata: {
829
- priority?: '0' | '1' | '2' | '3' | '4';
830
- label?: string;
831
- append_to_latest_ticket?: 'true' | 'false';
832
- round_robin?: 'true' | 'false';
833
- assignee?: string;
834
- rr_check_for?: 'shift_time' | 'user_status' | 'shift_time user_status';
835
- };
836
- };
837
-
838
- export type FlagMessageAction = {
839
- id: string;
840
- type: 'flag_message';
841
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
842
- metadata: {
843
- flag: 'true' | 'false';
844
- };
845
- };
846
-
847
- export type AssignTicketAction = {
848
- id: string;
849
- type: 'assign_ticket';
850
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
851
- metadata: {
852
- assignee: string;
853
- round_robin: 'true' | 'false';
854
- rr_check_for?: 'shift_time' | 'user_status' | 'shift_time user_status';
855
- };
856
- };
857
-
858
- export type CloseTicketAction = {
859
- id: string;
860
- type: 'close_ticket';
861
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
862
- metadata: {
863
- closing_note: string;
864
- };
865
- };
866
-
867
- export type AddChatLabelAction = {
868
- id: string;
869
- type: 'add_chat_label';
870
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
871
- metadata: {
872
- label: string;
873
- };
874
- };
875
-
876
- export type AddTicketLabelAction = {
877
- id: string;
878
- type: 'add_ticket_label';
879
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
880
- metadata: {
881
- label: string;
882
- };
883
- };
884
-
885
- export type AssignChatAction = {
886
- id: string;
887
- type: 'assign_chat';
888
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
889
- metadata: {
890
- assignee: string;
891
- round_robin: 'true' | 'false';
892
- rr_check_for?: 'shift_time' | 'user_status' | 'shift_time user_status';
893
- };
894
- };
895
-
896
- export type ForwardMessageAction = {
897
- id: string;
898
- type: 'forward_message';
899
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
900
- metadata: {
901
- chat_id: string;
902
- prefix: string;
903
- };
904
- };
905
-
906
- export type SendEmailAction = {
907
- id: string;
908
- type: 'send_email';
909
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
910
- metadata: {
911
- email: string;
912
- subject: string;
913
- body: string;
914
- };
915
- };
916
-
917
- export type ReplyToMessageAction = {
918
- id: string;
919
- type: 'reply_to_message';
920
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
921
- metadata: {
922
- message: string;
923
- media?: {
924
- url: string;
925
- type: 'image' | 'video' | 'audio' | 'document';
926
- name: string;
927
- };
928
- maintain_flag_status: 'true' | 'false';
929
- debounce_messages: 'true' | 'false';
930
- debounce_message_time:
931
- | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
932
- | null
933
- | undefined;
934
- };
935
- };
936
-
937
- export type UpdateCustomPropertyAction = {
938
- id: string;
939
- type: 'update_custom_property';
940
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
941
- metadata: {
942
- property_id: string;
943
- value: string;
944
- };
945
- };
946
-
947
- export type DeleteMessageAction = {
948
- id: string;
949
- type: 'delete_message';
950
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
951
- metadata: {};
952
- };
953
-
954
- export type SendSlackNotificationAction = {
955
- id: string;
956
- type: 'send_slack_notification';
957
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
958
- metadata: {
959
- slack_payload: string;
960
- webhook_url: string;
961
- };
962
- };
963
-
964
- export type AttachMessageToTicketAction = {
965
- id: string;
966
- type: 'attach_message_to_ticket';
967
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
968
- metadata: {
969
- status: 'open' | 'inprogress' | 'open_inprogress' | null;
970
- };
971
- };
972
-
973
- export type CloseChatAction = {
974
- id: string;
975
- type: 'close_chat';
976
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
977
- metadata: {};
978
- };
979
-
980
- export type SendMessageToChatAction = {
981
- id: string;
982
- type: 'send_message_to_chat';
983
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
984
- metadata: {
985
- chat_id: string;
986
- message: string;
987
- media?: {
988
- url: string;
989
- type: 'image' | 'video' | 'audio' | 'document';
990
- name: string;
991
- };
992
- };
993
- };
994
-
995
- export type Action =
996
- | SendMessageAction
997
- | NotifyHttpAction
998
- | CreateTicketAction
999
- | FlagMessageAction
1000
- | AssignTicketAction
1001
- | CloseTicketAction
1002
- | AddChatLabelAction
1003
- | AddTicketLabelAction
1004
- | AssignChatAction
1005
- | ForwardMessageAction
1006
- | SendEmailAction
1007
- | ReplyToMessageAction
1008
- | UpdateCustomPropertyAction
1009
- | DeleteMessageAction
1010
- | SendSlackNotificationAction
1011
- | AttachMessageToTicketAction
1012
- | CloseChatAction
1013
- | SendMessageToChatAction;
1014
-
1015
- export const isSendMessageOrReplyToMessageAction = (
1016
- action: Action
1017
- ): action is SendMessageAction | ReplyToMessageAction => {
1018
- return ['send_message', 'reply_to_message'].includes(action.type);
1019
- };
1020
-
1021
- export type Rule = OverrideProperties<
1022
- Tables<'tbl_automation_rules'>,
1023
- {
1024
- actions: Action[];
1025
- conditions: Conditions;
1026
- trigger:
1027
- | 'message.created'
1028
- | 'message.updated'
1029
- | 'chat.created'
1030
- | 'ticket.updated'
1031
- | 'ticket.created'
1032
- | 'reaction.added'
1033
- | 'chat.label.updated'
1034
- | 'message.flagged'
1035
- | 'message.unflagged'
1036
- | 'message.deleted'
1037
- | 'ticket.closed';
1038
- }
1039
- >;
1040
-
1041
- export const RuleNameMap: Record<
1042
- Rule['trigger'],
1043
- {
1044
- title: string;
1045
- description: string;
1046
- base_conditions: {
1047
- org_phone: boolean;
1048
- };
1049
- }
1050
- > = {
1051
- 'message.created': {
1052
- title: 'New Message Received',
1053
- description: 'When a new message is received from an external contact',
1054
- base_conditions: {
1055
- org_phone: true,
1056
- },
1057
- },
1058
- 'chat.created': {
1059
- title: 'New Chat Created',
1060
- description: 'When a new chat is created',
1061
- base_conditions: {
1062
- org_phone: true,
1063
- },
1064
- },
1065
- 'ticket.created': {
1066
- title: 'New Ticket Created',
1067
- description: 'When a new ticket is created',
1068
- base_conditions: {
1069
- org_phone: false,
1070
- },
1071
- },
1072
- 'reaction.added': {
1073
- title: 'New Reaction Added',
1074
- description: 'When a reaction is added on a message',
1075
- base_conditions: {
1076
- org_phone: true,
1077
- },
1078
- },
1079
- 'message.updated': {
1080
- title: 'Message Updated',
1081
- description: 'When a message is updated',
1082
- base_conditions: {
1083
- org_phone: true,
1084
- },
1085
- },
1086
- 'ticket.updated': {
1087
- title: 'Ticket Updated',
1088
- description: 'When a ticket is updated',
1089
- base_conditions: {
1090
- org_phone: false,
1091
- },
1092
- },
1093
- 'chat.label.updated': {
1094
- title: 'Chat Label Added/Removed',
1095
- description: 'When labels on chats are updated',
1096
- base_conditions: {
1097
- org_phone: false,
1098
- },
1099
- },
1100
- 'message.flagged': {
1101
- title: 'Message Flagged',
1102
- description: 'When a message is flagged',
1103
- base_conditions: {
1104
- org_phone: true,
1105
- },
1106
- },
1107
- 'message.unflagged': {
1108
- title: 'Message Unflagged',
1109
- description: 'When a message is unflagged',
1110
- base_conditions: {
1111
- org_phone: true,
1112
- },
1113
- },
1114
- 'message.deleted': {
1115
- title: 'Message Deleted',
1116
- description: 'When a message is Deleted',
1117
- base_conditions: {
1118
- org_phone: true,
1119
- },
1120
- },
1121
- 'ticket.closed': {
1122
- title: 'Ticket Closed',
1123
- description: 'When a Ticket is Closed',
1124
- base_conditions: {
1125
- org_phone: false,
1126
- },
1127
- },
1128
- };
1129
-
1130
- export const ActionNameMap: Record<
1131
- Action['type'],
1132
- {
1133
- title: string;
1134
- description: string;
1135
- inputs: Record<
1136
- string,
1137
- {
1138
- id: string;
1139
- type:
1140
- | 'text'
1141
- | 'dropdown'
1142
- | 'editor'
1143
- | 'date'
1144
- | 'file'
1145
- | 'textarea'
1146
- | 'dynamic'
1147
- | 'json_editor';
1148
- value:
1149
- | 'ticket.labels'
1150
- | 'org.members'
1151
- | 'chat.labels'
1152
- | 'org.chats'
1153
- | {
1154
- id: string;
1155
- value: string;
1156
- label: string;
1157
- }[]
1158
- | null
1159
- | 'org.custom_properties'
1160
- | 'custom_property_values'
1161
- | 'debounce_messages';
1162
- label: string;
1163
- placeholder: string;
1164
- info?: string;
1165
- required: boolean;
1166
- description?: string;
1167
- }
1168
- >;
1169
- info?: string;
1170
- validTriggers: Rule['trigger'][];
1171
- }
1172
- > = {
1173
- send_message: {
1174
- title: 'Send Message',
1175
- description: 'Send a message',
1176
- inputs: {
1177
- message: {
1178
- id: 'message',
1179
- type: 'editor',
1180
- label: 'Message',
1181
- placeholder: 'Enter message',
1182
- value: null,
1183
- required: true,
1184
- },
1185
- media: {
1186
- id: 'media',
1187
- type: 'file',
1188
- label: 'Media',
1189
- placeholder: 'Upload media',
1190
- value: null,
1191
- required: false,
1192
- },
1193
- maintain_flag_status: {
1194
- id: 'maintain_flag_status',
1195
- type: 'dropdown',
1196
- label: 'Maintain Flag Status',
1197
- placeholder: 'Select...',
1198
- value: [
1199
- { id: 'true', value: 'true', label: 'True' },
1200
- { id: 'false', value: 'false', label: 'False' },
1201
- ],
1202
- required: true,
1203
- },
1204
- debounce_messages: {
1205
- id: 'debounce_messages',
1206
- type: 'dropdown',
1207
- label: 'Enable Cooldown Period',
1208
- placeholder: 'Select...',
1209
- value: [
1210
- { id: 'true', value: 'true', label: 'True' },
1211
- { id: 'false', value: 'false', label: 'False' },
1212
- ],
1213
- info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1214
- required: false,
1215
- },
1216
- debounce_message_time: {
1217
- id: 'debounce_message_time',
1218
- type: 'dynamic',
1219
- label: 'Cooldown Period',
1220
- placeholder: 'Enter time',
1221
- value: 'debounce_messages',
1222
- required: false,
1223
- },
1224
- },
1225
- validTriggers: [
1226
- 'message.created',
1227
- 'message.updated',
1228
- 'chat.created',
1229
- 'ticket.updated',
1230
- 'ticket.created',
1231
- 'reaction.added',
1232
- 'message.flagged',
1233
- 'message.unflagged',
1234
- 'chat.label.updated',
1235
- 'message.deleted',
1236
- 'ticket.closed',
1237
- ],
1238
- },
1239
- reply_to_message: {
1240
- title: 'Reply to message',
1241
- description: 'Send a message with the quoted message',
1242
- inputs: {
1243
- message: {
1244
- id: 'message',
1245
- type: 'editor',
1246
- label: 'Message',
1247
- placeholder: 'Enter message',
1248
- value: null,
1249
- required: true,
1250
- },
1251
- media: {
1252
- id: 'media',
1253
- type: 'file',
1254
- label: 'Media',
1255
- placeholder: 'Upload media',
1256
- value: null,
1257
- required: false,
1258
- },
1259
- maintain_flag_status: {
1260
- id: 'maintain_flag_status',
1261
- type: 'dropdown',
1262
- label: 'Maintain Flag Status',
1263
- placeholder: 'Select...',
1264
- value: [
1265
- { id: 'true', value: 'true', label: 'True' },
1266
- { id: 'false', value: 'false', label: 'False' },
1267
- ],
1268
- required: true,
1269
- },
1270
- debounce_messages: {
1271
- id: 'debounce_messages',
1272
- type: 'dropdown',
1273
- label: 'Enable Cooldown Period',
1274
- placeholder: 'Select...',
1275
- value: [
1276
- { id: 'true', value: 'true', label: 'True' },
1277
- { id: 'false', value: 'false', label: 'False' },
1278
- ],
1279
- info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1280
- required: false,
1281
- },
1282
- debounce_message_time: {
1283
- id: 'debounce_message_time',
1284
- type: 'dynamic',
1285
- label: 'Cooldown Period',
1286
- placeholder: 'Enter time',
1287
- value: 'debounce_messages',
1288
- required: false,
1289
- },
1290
- },
1291
- validTriggers: [
1292
- 'message.created',
1293
- 'message.updated',
1294
- 'reaction.added',
1295
- 'message.flagged',
1296
- 'ticket.created',
1297
- 'ticket.updated',
1298
- 'ticket.closed',
1299
- 'message.unflagged',
1300
- ],
1301
- },
1302
- delete_message: {
1303
- title: 'Delete Message',
1304
- description: 'Delete a message',
1305
- inputs: {},
1306
- validTriggers: [
1307
- 'message.created',
1308
- 'message.updated',
1309
- 'reaction.added',
1310
- 'message.flagged',
1311
- 'ticket.created',
1312
- 'ticket.updated',
1313
- 'ticket.closed',
1314
- 'message.unflagged',
1315
- ],
1316
- },
1317
- attach_message_to_ticket: {
1318
- title: 'Attach Message To Latest Ticket',
1319
- description: 'Attach message to latest ticket based on statuses',
1320
- inputs: {
1321
- status: {
1322
- id: 'status',
1323
- type: 'dropdown',
1324
- value: [
1325
- {
1326
- id: 'open_inprogress',
1327
- value: 'open_inprogress',
1328
- label: 'Open/In Progress',
1329
- },
1330
- { id: 'open', value: 'open', label: 'Open' },
1331
- { id: 'inprogress', value: 'inprogress', label: 'In Progress' },
1332
- ],
1333
- label: 'Ticket Status',
1334
- placeholder: 'Select...',
1335
- required: true,
1336
- info: 'Select the ticket status of ticket to attach the message to (only applicable for open or inprogress tickets)',
1337
- },
1338
- },
1339
- validTriggers: [
1340
- 'message.created',
1341
- 'message.updated',
1342
- 'reaction.added',
1343
- 'message.flagged',
1344
- ],
1345
- },
1346
- notify_http: {
1347
- title: 'Notify HTTP',
1348
- description: 'Notify an HTTP endpoint',
1349
- inputs: {
1350
- url: {
1351
- id: 'url',
1352
- type: 'text',
1353
- label: 'URL',
1354
- placeholder: 'Enter URL',
1355
- value: null,
1356
- required: true,
1357
- description:
1358
- 'Enter the Webhook URL here. The endpoint added here should be a **POST HTTP / Endpoint** with no open auth.',
1359
- },
1360
- },
1361
- validTriggers: [
1362
- 'message.created',
1363
- 'message.updated',
1364
- 'chat.created',
1365
- 'ticket.updated',
1366
- 'ticket.created',
1367
- 'reaction.added',
1368
- 'message.flagged',
1369
- 'chat.label.updated',
1370
- 'message.deleted',
1371
- 'ticket.closed',
1372
- 'message.unflagged',
1373
- ],
1374
- },
1375
- create_ticket: {
1376
- title: 'Create Ticket or Attach Message To Latest Ticket',
1377
- description: 'Create a ticket or attach message to latest ticket',
1378
- inputs: {
1379
- append_to_latest_ticket: {
1380
- id: 'append_to_latest_ticket',
1381
- type: 'dropdown',
1382
- value: [
1383
- { id: 'true', value: 'true', label: 'True' },
1384
- { id: 'false', value: 'false', label: 'False' },
1385
- ],
1386
- label: 'Attach message to latest ticket (if available)',
1387
- placeholder: 'Select...',
1388
- info: 'If enabled, the message will be appended to the latest open ticket (if available) else a new ticket will be created',
1389
- required: false,
1390
- },
1391
- priority: {
1392
- id: 'priority',
1393
- type: 'dropdown',
1394
- value: [
1395
- { id: '0', value: '0', label: 'No Priority' },
1396
- { id: '1', value: '1', label: 'Low' },
1397
- { id: '2', value: '2', label: 'Medium' },
1398
- { id: '3', value: '3', label: 'High' },
1399
- { id: '4', value: '4', label: 'Urgent' },
1400
- ],
1401
- label: 'Priority (New Ticket)',
1402
- placeholder: 'Select priority',
1403
- info: 'Only applicable for create ticket. If no priority is selected, the ticket will have no priority.',
1404
- required: false,
1405
- },
1406
- label: {
1407
- id: 'label',
1408
- type: 'dropdown',
1409
- value: 'ticket.labels',
1410
- label: 'Label (New Ticket)',
1411
- placeholder: 'Select label',
1412
- info: 'Only applicable for create ticket. If no label is selected, the ticket will have no label.',
1413
- required: false,
1414
- },
1415
- round_robin: {
1416
- id: 'round_robin',
1417
- type: 'dropdown',
1418
- value: [
1419
- { id: 'true', value: 'true', label: 'True' },
1420
- { id: 'false', value: 'false', label: 'False' },
1421
- ],
1422
- label: 'Enable Round Robin (New Ticket: Assignee)',
1423
- placeholder: 'Select...',
1424
- info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1425
- required: false,
1426
- },
1427
- rr_check_for: {
1428
- id: 'rr_check_for',
1429
- type: 'dropdown',
1430
- value: [
1431
- {
1432
- id: 'shift_time',
1433
- value: 'shift_time',
1434
- label: 'Consider shift timings',
1435
- },
1436
- {
1437
- id: 'user_status',
1438
- value: 'user_status',
1439
- label: 'Exclude users marked as offline',
1440
- },
1441
- {
1442
- id: 'shift_time user_status',
1443
- value: 'shift_time user_status',
1444
- label: 'Consider both shift timings and user status',
1445
- },
1446
- ],
1447
- label: 'Check Assignee status for (Round Robin)',
1448
- placeholder: 'Select...',
1449
- info: 'Criteria for assigning the next available agent',
1450
- required: false,
1451
- },
1452
- assignee: {
1453
- id: 'assignee',
1454
- type: 'dynamic',
1455
- value: 'org.members',
1456
- label: 'Assignee (New Ticket)',
1457
- placeholder: 'Select assignee',
1458
- info: "If round robin is enabled, the ticket will be assigned to the next available agent in the list else it'll be assigned to the selected agent",
1459
- required: false,
1460
- },
1461
- },
1462
- validTriggers: [
1463
- 'message.created',
1464
- 'message.updated',
1465
- 'reaction.added',
1466
- 'message.flagged',
1467
- 'message.unflagged',
1468
- ],
1469
- },
1470
- flag_message: {
1471
- title: 'Update flag status',
1472
- description: 'Flag/Unflag a message',
1473
- inputs: {
1474
- flag: {
1475
- id: 'flag',
1476
- type: 'dropdown',
1477
- value: [
1478
- { id: 'flag', value: 'true', label: 'True' },
1479
- { id: 'unflag', value: 'false', label: 'False' },
1480
- ],
1481
- label: 'Flag status',
1482
- placeholder: 'Select flag',
1483
- required: true,
1484
- },
1485
- },
1486
- validTriggers: [
1487
- 'message.created',
1488
- 'message.updated',
1489
- 'reaction.added',
1490
- 'message.flagged',
1491
- 'message.unflagged',
1492
- 'ticket.created',
1493
- 'ticket.updated',
1494
- 'ticket.closed',
1495
- ],
1496
- },
1497
- assign_ticket: {
1498
- title: 'Assign Ticket',
1499
- description: 'Assign a ticket',
1500
- inputs: {
1501
- round_robin: {
1502
- id: 'round_robin',
1503
- type: 'dropdown',
1504
- value: [
1505
- { id: 'true', value: 'true', label: 'True' },
1506
- { id: 'false', value: 'false', label: 'False' },
1507
- ],
1508
- label: 'Enable Round Robin',
1509
- placeholder: 'Select...',
1510
- info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1511
- required: false,
1512
- },
1513
- rr_check_for: {
1514
- id: 'rr_check_for',
1515
- type: 'dropdown',
1516
- value: [
1517
- {
1518
- id: 'shift_time',
1519
- value: 'shift_time',
1520
- label: 'Consider shift timings',
1521
- },
1522
- {
1523
- id: 'user_status',
1524
- value: 'user_status',
1525
- label: 'Exclude users marked as offline',
1526
- },
1527
- {
1528
- id: 'shift_time user_status',
1529
- value: 'shift_time user_status',
1530
- label: 'Consider both shift timings and user status',
1531
- },
1532
- ],
1533
- label: 'Check Assignee status for (Round Robin)',
1534
- placeholder: 'Select...',
1535
- info: 'Criteria for assigning the next available agent',
1536
- required: false,
1537
- },
1538
- assignee: {
1539
- id: 'assignee',
1540
- type: 'dynamic',
1541
- value: 'org.members',
1542
- label: 'Assignee',
1543
- placeholder: 'Select assignee',
1544
- info: "If round robin is enabled, the ticket will be assigned to the next available agent in the list else it'll be assigned to the selected agent",
1545
- required: true,
1546
- },
1547
- },
1548
- validTriggers: ['ticket.updated', 'ticket.created'],
1549
- },
1550
- close_ticket: {
1551
- title: 'Close Ticket',
1552
- description: 'Close a ticket',
1553
- info: "This action will close the ticket. This doesn't check for mandatory ticket custom properties.",
1554
- inputs: {
1555
- closing_note: {
1556
- id: 'closing_note',
1557
- type: 'textarea',
1558
- label: 'Closing Note',
1559
- placeholder: 'Enter closing note',
1560
- value: null,
1561
- required: false,
1562
- },
1563
- },
1564
- validTriggers: [
1565
- 'ticket.updated',
1566
- 'ticket.created',
1567
- 'reaction.added',
1568
- 'message.unflagged',
1569
- 'message.deleted',
1570
- ],
1571
- },
1572
- add_chat_label: {
1573
- title: 'Add Chat Label',
1574
- description: 'Add a label to referred chat',
1575
- inputs: {
1576
- label: {
1577
- id: 'label',
1578
- type: 'dropdown',
1579
- value: 'chat.labels',
1580
- label: 'Label',
1581
- placeholder: 'Select label',
1582
- required: true,
1583
- },
1584
- },
1585
- validTriggers: [
1586
- 'message.created',
1587
- 'message.updated',
1588
- 'chat.created',
1589
- 'ticket.updated',
1590
- 'ticket.created',
1591
- 'reaction.added',
1592
- 'chat.label.updated',
1593
- 'message.flagged',
1594
- 'message.deleted',
1595
- 'message.unflagged',
1596
- 'ticket.closed',
1597
- ],
1598
- },
1599
- add_ticket_label: {
1600
- title: 'Add Ticket Label',
1601
- description: 'Add a label to referred ticket',
1602
- inputs: {
1603
- label: {
1604
- id: 'label',
1605
- type: 'dropdown',
1606
- value: 'ticket.labels',
1607
- label: 'Label',
1608
- placeholder: 'Select label',
1609
- required: true,
1610
- },
1611
- },
1612
- validTriggers: ['ticket.updated', 'ticket.created'],
1613
- },
1614
- update_custom_property: {
1615
- description: 'Update a chat custom property',
1616
- title: 'Update Chat Custom Property',
1617
- validTriggers: [
1618
- 'message.created',
1619
- 'message.updated',
1620
- 'chat.created',
1621
- 'ticket.updated',
1622
- 'ticket.created',
1623
- 'reaction.added',
1624
- 'message.flagged',
1625
- 'chat.label.updated',
1626
- 'message.deleted',
1627
- 'message.unflagged',
1628
- 'ticket.closed',
1629
- ],
1630
- inputs: {
1631
- property_id: {
1632
- id: 'property_id',
1633
- type: 'dropdown',
1634
- value: 'org.custom_properties',
1635
- label: 'Property',
1636
- placeholder: 'Select property',
1637
- required: true,
1638
- },
1639
- value: {
1640
- id: 'property_id',
1641
- type: 'dynamic',
1642
- label: 'Value',
1643
- placeholder: 'Enter value',
1644
- value: 'custom_property_values',
1645
- required: true,
1646
- },
1647
- },
1648
- },
1649
- assign_chat: {
1650
- title: 'Assign Chat',
1651
- description: 'Assign a chat',
1652
- inputs: {
1653
- round_robin: {
1654
- id: 'round_robin',
1655
- type: 'dropdown',
1656
- value: [
1657
- { id: 'true', value: 'true', label: 'True' },
1658
- { id: 'false', value: 'false', label: 'False' },
1659
- ],
1660
- label: 'Enable Round Robin',
1661
- placeholder: 'Select...',
1662
- info: 'If enabled, the chat will be assigned to the next available agent in the list',
1663
- required: false,
1664
- },
1665
- rr_check_for: {
1666
- id: 'rr_check_for',
1667
- type: 'dropdown',
1668
- value: [
1669
- {
1670
- id: 'shift_time',
1671
- value: 'shift_time',
1672
- label: 'Consider shift timings',
1673
- },
1674
- {
1675
- id: 'user_status',
1676
- value: 'user_status',
1677
- label: 'Exclude users marked as offline',
1678
- },
1679
- {
1680
- id: 'shift_time user_status',
1681
- value: 'shift_time user_status',
1682
- label: 'Consider both shift timings and user status',
1683
- },
1684
- ],
1685
- label: 'Check Assignee status for (Round Robin)',
1686
- placeholder: 'Select...',
1687
- info: 'Criteria for assigning the next available agent',
1688
- required: false,
1689
- },
1690
- assignee: {
1691
- id: 'assignee',
1692
- type: 'dynamic',
1693
- value: 'org.members',
1694
- label: 'Assignee',
1695
- placeholder: 'Select assignee',
1696
- required: true,
1697
- },
1698
- },
1699
- validTriggers: [
1700
- 'message.created',
1701
- 'message.updated',
1702
- 'chat.created',
1703
- 'ticket.updated',
1704
- 'ticket.created',
1705
- 'reaction.added',
1706
- 'chat.label.updated',
1707
- 'message.flagged',
1708
- 'message.deleted',
1709
- 'message.unflagged',
1710
- 'ticket.closed',
1711
- ],
1712
- },
1713
- close_chat: {
1714
- title: 'Close Chat',
1715
- description: 'Close a chat conversation',
1716
- inputs: {},
1717
- validTriggers: [
1718
- 'message.created',
1719
- 'message.updated',
1720
- 'chat.created',
1721
- 'ticket.updated',
1722
- 'ticket.created',
1723
- 'reaction.added',
1724
- 'chat.label.updated',
1725
- 'message.flagged',
1726
- 'message.unflagged',
1727
- 'message.deleted',
1728
- 'ticket.closed',
1729
- ],
1730
- },
1731
- forward_message: {
1732
- title: 'Forward Message',
1733
- description: 'Forward a message',
1734
- inputs: {
1735
- chat_id: {
1736
- id: 'chat_id',
1737
- type: 'dropdown',
1738
- value: 'org.chats',
1739
- label: 'Chat',
1740
- placeholder: 'Select chat',
1741
- required: true,
1742
- },
1743
- },
1744
- validTriggers: [
1745
- 'message.created',
1746
- 'message.updated',
1747
- 'ticket.updated',
1748
- 'ticket.created',
1749
- 'reaction.added',
1750
- 'message.unflagged',
1751
- 'message.flagged',
1752
- 'ticket.closed',
1753
- ],
1754
- },
1755
- send_email: {
1756
- title: 'Send Email',
1757
- description: 'Send an email',
1758
- inputs: {
1759
- email: {
1760
- id: 'email',
1761
- type: 'text',
1762
- label: 'Email',
1763
- placeholder: 'Enter email',
1764
- value: null,
1765
- required: true,
1766
- },
1767
- subject: {
1768
- id: 'subject',
1769
- type: 'editor',
1770
- label: 'Subject',
1771
- placeholder: 'Enter subject',
1772
- value: null,
1773
- required: true,
1774
- },
1775
- body: {
1776
- id: 'body',
1777
- type: 'editor',
1778
- label: 'Body',
1779
- placeholder: 'Enter body',
1780
- value: null,
1781
- required: true,
1782
- },
1783
- },
1784
- validTriggers: [
1785
- 'message.created',
1786
- 'message.updated',
1787
- 'chat.created',
1788
- 'ticket.updated',
1789
- 'ticket.created',
1790
- 'reaction.added',
1791
- 'message.flagged',
1792
- 'message.unflagged',
1793
- 'chat.label.updated',
1794
- 'message.deleted',
1795
- 'ticket.closed',
1796
- ],
1797
- },
1798
- send_slack_notification: {
1799
- title: 'Send Slack Webhook Notification',
1800
- description: 'Send a slack webhook notification to a channel',
1801
- validTriggers: [
1802
- 'message.created',
1803
- 'message.updated',
1804
- 'chat.created',
1805
- 'ticket.updated',
1806
- 'ticket.created',
1807
- 'reaction.added',
1808
- 'message.flagged',
1809
- 'message.unflagged',
1810
- 'chat.label.updated',
1811
- 'message.deleted',
1812
- 'ticket.closed',
1813
- ],
1814
- inputs: {
1815
- webhook_url: {
1816
- type: 'text',
1817
- id: 'webhook_url',
1818
- label: 'Webhook URL',
1819
- placeholder: 'Enter webhook URL',
1820
- value: null,
1821
- required: true,
1822
- description:
1823
- 'Enter the webhook URL to send the notification, to create a slack incoming webhook to start receiving notification check [here](https://api.slack.com/messaging/webhooks)',
1824
- },
1825
- slack_payload: {
1826
- type: 'json_editor',
1827
- id: 'slack_payload',
1828
- label: 'Slack Notification Payload',
1829
- placeholder: 'Enter payload',
1830
- value: null,
1831
- required: true,
1832
- description:
1833
- 'You can send slack blocks as notifications to the provided hook URL.\n\nIn order to **build a slack notification block**, you can visit [here](https://api.slack.com/block-kit/building)',
1834
- },
1835
- },
1836
- },
1837
- send_message_to_chat: {
1838
- title: 'Send Message To Chat',
1839
- description: 'Send a message to a specified chat',
1840
- inputs: {
1841
- chat_id: {
1842
- id: 'chat_id',
1843
- type: 'dropdown',
1844
- value: 'org.chats',
1845
- label: 'Chat',
1846
- placeholder: 'Select chat',
1847
- required: true,
1848
- },
1849
- message: {
1850
- id: 'message',
1851
- type: 'editor',
1852
- label: 'Message',
1853
- placeholder: 'Enter message',
1854
- value: null,
1855
- required: true,
1856
- },
1857
- media: {
1858
- id: 'media',
1859
- type: 'file',
1860
- label: 'Media',
1861
- placeholder: 'Upload media',
1862
- value: null,
1863
- required: false,
1864
- },
1865
- },
1866
- validTriggers: [
1867
- 'message.created',
1868
- 'message.updated',
1869
- 'chat.created',
1870
- 'ticket.updated',
1871
- 'ticket.created',
1872
- 'reaction.added',
1873
- 'message.flagged',
1874
- 'message.unflagged',
1875
- 'chat.label.updated',
1876
- 'message.deleted',
1877
- 'ticket.closed',
1878
- ],
1879
- },
1880
- };
1881
-
1882
- type editorVariablesList =
1883
- | 'chat.assigned_to'
1884
- | 'chat.chat_id'
1885
- | 'chat.chat_name'
1886
- | 'chat.chat_type'
1887
- | 'chat.org_phone'
1888
- | 'chat.org_id'
1889
- | 'chat.group_description'
1890
- | 'ticket.assignee'
1891
- | 'ticket.due_date'
1892
- | 'ticket.priority'
1893
- | 'ticket.status'
1894
- | 'ticket.subject'
1895
- | 'ticket.ticket_id'
1896
- | 'ticket.raised_by'
1897
- | 'ticket.created_at'
1898
- | 'sender.is_internal'
1899
- | 'sender.is_admin'
1900
- | 'sender.contact_name'
1901
- | 'sender.contact_id'
1902
- | 'reaction.sender_id'
1903
- | 'reaction.reaction'
1904
- | 'message.message_id'
1905
- | 'message.timestamp'
1906
- | 'message.sender_phone'
1907
- | 'message.message_type'
1908
- | 'message.media'
1909
- | 'message.body';
1910
-
1911
- export const editorVariables: Array<{
1912
- label: string;
1913
- value: editorVariablesList;
1914
- validTriggers: Rule['trigger'][];
1915
- }> = [
1916
- {
1917
- label: 'Ticket ID',
1918
- value: 'ticket.ticket_id',
1919
- validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
1920
- },
1921
- {
1922
- value: 'ticket.assignee',
1923
- label: 'Ticket Assignee',
1924
- validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
1925
- },
1926
- {
1927
- value: 'ticket.due_date',
1928
- label: 'Ticket Due Date',
1929
- validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
1930
- },
1931
- {
1932
- value: 'ticket.priority',
1933
- label: 'Ticket Priority',
1934
- validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
1935
- },
1936
- {
1937
- value: 'ticket.status',
1938
- label: 'Ticket Status',
1939
- validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
1940
- },
1941
- {
1942
- value: 'ticket.subject',
1943
- label: 'Ticket Subject',
1944
- validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
1945
- },
1946
- {
1947
- label: 'Message Body',
1948
- value: 'message.body',
1949
- validTriggers: [
1950
- 'message.created',
1951
- 'message.updated',
1952
- 'reaction.added',
1953
- 'message.flagged',
1954
- 'ticket.created',
1955
- 'ticket.updated',
1956
- 'ticket.closed',
1957
- 'message.deleted',
1958
- ],
1959
- },
1960
- {
1961
- value: 'message.media',
1962
- label: 'Message Media',
1963
- validTriggers: [
1964
- 'message.created',
1965
- 'message.updated',
1966
- 'reaction.added',
1967
- 'message.flagged',
1968
- 'ticket.created',
1969
- 'ticket.updated',
1970
- 'ticket.closed',
1971
- 'message.deleted',
1972
- ],
1973
- },
1974
- {
1975
- value: 'message.message_id',
1976
- label: 'Message ID',
1977
- validTriggers: [
1978
- 'message.created',
1979
- 'message.updated',
1980
- 'reaction.added',
1981
- 'message.flagged',
1982
- 'ticket.created',
1983
- 'ticket.updated',
1984
- 'ticket.closed',
1985
- 'message.deleted',
1986
- ],
1987
- },
1988
- {
1989
- value: 'message.message_type',
1990
- label: 'Message Type',
1991
- validTriggers: [
1992
- 'message.created',
1993
- 'message.updated',
1994
- 'reaction.added',
1995
- 'message.flagged',
1996
- 'ticket.created',
1997
- 'ticket.updated',
1998
- 'ticket.closed',
1999
- 'message.deleted',
2000
- ],
2001
- },
2002
- {
2003
- value: 'message.sender_phone',
2004
- label: 'Sender Phone',
2005
- validTriggers: [
2006
- 'message.created',
2007
- 'message.updated',
2008
- 'reaction.added',
2009
- 'message.flagged',
2010
- 'ticket.created',
2011
- 'ticket.updated',
2012
- 'ticket.closed',
2013
- 'message.deleted',
2014
- ],
2015
- },
2016
- {
2017
- value: 'message.timestamp',
2018
- label: 'Message Timestamp',
2019
- validTriggers: [
2020
- 'message.created',
2021
- 'message.updated',
2022
- 'reaction.added',
2023
- 'message.flagged',
2024
- 'ticket.created',
2025
- 'ticket.updated',
2026
- 'ticket.closed',
2027
- 'message.deleted',
2028
- ],
2029
- },
2030
- {
2031
- label: 'Sender Name',
2032
- value: 'sender.contact_name',
2033
- validTriggers: [
2034
- 'message.created',
2035
- 'message.updated',
2036
- 'reaction.added',
2037
- 'message.flagged',
2038
- 'ticket.created',
2039
- 'ticket.updated',
2040
- 'ticket.closed',
2041
- 'message.deleted',
2042
- ],
2043
- },
2044
- {
2045
- value: 'sender.is_admin',
2046
- label: 'Sender Is Admin',
2047
- validTriggers: [
2048
- 'message.created',
2049
- 'message.updated',
2050
- 'reaction.added',
2051
- 'message.flagged',
2052
- 'ticket.created',
2053
- 'ticket.updated',
2054
- 'ticket.closed',
2055
- 'message.deleted',
2056
- ],
2057
- },
2058
- {
2059
- value: 'sender.is_internal',
2060
- label: 'Sender Is Internal',
2061
- validTriggers: [
2062
- 'message.created',
2063
- 'message.updated',
2064
- 'reaction.added',
2065
- 'message.flagged',
2066
- 'ticket.created',
2067
- 'ticket.updated',
2068
- 'ticket.closed',
2069
- 'message.deleted',
2070
- ],
2071
- },
2072
- {
2073
- label: 'Reaction',
2074
- value: 'reaction.reaction',
2075
- validTriggers: ['reaction.added'],
2076
- },
2077
- {
2078
- value: 'reaction.sender_id',
2079
- label: 'Reaction Sender Phone',
2080
- validTriggers: ['reaction.added'],
2081
- },
2082
- {
2083
- label: 'Chat Name',
2084
- value: 'chat.chat_name',
2085
- validTriggers: [
2086
- 'message.created',
2087
- 'message.updated',
2088
- 'reaction.added',
2089
- 'message.flagged',
2090
- 'chat.created',
2091
- 'chat.label.updated',
2092
- 'ticket.created',
2093
- 'ticket.updated',
2094
- 'ticket.closed',
2095
- 'message.deleted',
2096
- ],
2097
- },
2098
- {
2099
- value: 'chat.assigned_to',
2100
- label: 'Chat Assigned To',
2101
- validTriggers: [
2102
- 'message.created',
2103
- 'message.updated',
2104
- 'reaction.added',
2105
- 'message.flagged',
2106
- 'chat.created',
2107
- 'chat.label.updated',
2108
- 'ticket.created',
2109
- 'ticket.updated',
2110
- 'ticket.closed',
2111
- 'message.deleted',
2112
- ],
2113
- },
2114
- {
2115
- value: 'chat.chat_id',
2116
- label: 'Chat ID',
2117
- validTriggers: [
2118
- 'message.created',
2119
- 'message.updated',
2120
- 'reaction.added',
2121
- 'message.flagged',
2122
- 'chat.created',
2123
- 'chat.label.updated',
2124
- 'ticket.created',
2125
- 'ticket.updated',
2126
- 'ticket.closed',
2127
- 'message.deleted',
2128
- ],
2129
- },
2130
- {
2131
- value: 'chat.chat_type',
2132
- label: 'Chat Type',
2133
- validTriggers: [
2134
- 'message.created',
2135
- 'message.updated',
2136
- 'reaction.added',
2137
- 'message.flagged',
2138
- 'chat.created',
2139
- 'chat.label.updated',
2140
- 'ticket.created',
2141
- 'ticket.updated',
2142
- 'ticket.closed',
2143
- 'message.deleted',
2144
- ],
2145
- },
2146
- {
2147
- value: 'chat.org_id',
2148
- label: 'Chat Org ID',
2149
- validTriggers: [
2150
- 'message.created',
2151
- 'message.updated',
2152
- 'reaction.added',
2153
- 'message.flagged',
2154
- 'chat.created',
2155
- 'chat.label.updated',
2156
- 'ticket.created',
2157
- 'ticket.updated',
2158
- 'ticket.closed',
2159
- 'message.deleted',
2160
- ],
2161
- },
2162
- {
2163
- value: 'chat.org_phone',
2164
- label: 'Chat Org Phone',
2165
- validTriggers: [
2166
- 'message.created',
2167
- 'message.updated',
2168
- 'reaction.added',
2169
- 'message.flagged',
2170
- 'chat.created',
2171
- 'chat.label.updated',
2172
- 'ticket.created',
2173
- 'ticket.updated',
2174
- 'ticket.closed',
2175
- 'message.deleted',
2176
- ],
2177
- },
2178
- ];
2179
-
2180
- export const variablesExclusionList: Record<
2181
- Rule['trigger'],
2182
- Array<
2183
- | keyof AppendTypes<{ message: MessageVariablesType }, '.'>
2184
- | keyof AppendTypes<{ sender: SenderVariablesType }, '.'>
2185
- | keyof AppendTypes<{ chat: ChatVariablesType }, '.'>
2186
- | keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>
2187
- | keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>
2188
- >
2189
- > = {
2190
- 'ticket.created': ['ticket.is_deleted'],
2191
- 'chat.created': [
2192
- 'chat.labels',
2193
- 'chat.has_flagged_messages',
2194
- 'chat.assigned_to',
2195
- ],
2196
- 'message.created': [
2197
- 'message.author',
2198
- 'message.performed_by',
2199
- 'message.flag_status',
2200
- 'sender.is_internal',
2201
- ],
2202
- 'ticket.updated': ['ticket.is_deleted'],
2203
- 'reaction.added': [],
2204
- 'message.updated': [],
2205
- 'message.flagged': [],
2206
- 'message.unflagged': [],
2207
- 'message.deleted': [],
2208
- 'ticket.closed': ['ticket.is_deleted'],
2209
- 'chat.label.updated': [],
2210
- };
1
+ import { Merge, OverrideProperties } from 'type-fest';
2
+ import { Tables } from './supabase.types';
3
+ import {
4
+ ChatRuleInfoType,
5
+ MessageRuleInfoType,
6
+ OrgType,
7
+ ReactionRuleInfoType,
8
+ SenderRuleInfoType,
9
+ TicketRuleInfoType,
10
+ } from './types';
11
+
12
+ export type AppendTypes<T extends object, O extends string> = {
13
+ [K in keyof T & string as `${K}${O}${keyof T[K] & string}`]: T[K][keyof T[K]];
14
+ };
15
+
16
+ export type TicketVariablesType = TicketRuleInfoType['ticket'];
17
+
18
+ export type MessageVariablesType = MessageRuleInfoType['message'];
19
+
20
+ export type SenderVariablesType = SenderRuleInfoType;
21
+
22
+ export type ReactionVariablesType = ReactionRuleInfoType['reaction'];
23
+
24
+ export type ChatVariablesType = ChatRuleInfoType;
25
+
26
+ export type MessageRulesInfoType = Merge<
27
+ AppendTypes<
28
+ {
29
+ message: MessageVariablesType;
30
+ sender: SenderVariablesType;
31
+ chat: ChatVariablesType;
32
+ },
33
+ '.'
34
+ >,
35
+ {
36
+ rule: Tables<'tbl_automation_rules'>[];
37
+ id: 'message.message_id';
38
+ type: `message.${'created' | 'updated' | 'flagged' | 'deleted' | 'unflagged'}`;
39
+ org_id: string;
40
+ }
41
+ >;
42
+
43
+ export type TicketRulesInfoType = Merge<
44
+ AppendTypes<
45
+ {
46
+ ticket: TicketVariablesType;
47
+ message: MessageVariablesType;
48
+ sender: SenderVariablesType;
49
+ chat: ChatVariablesType;
50
+ },
51
+ '.'
52
+ >,
53
+ {
54
+ id: 'ticket.ticket_id';
55
+ type: `ticket.${'created' | 'updated' | 'closed'}`;
56
+ org_id: string;
57
+ rule: Tables<'tbl_automation_rules'>[];
58
+ }
59
+ >;
60
+
61
+ export type ReactionRulesInfoType = Merge<
62
+ AppendTypes<
63
+ {
64
+ reaction: ReactionVariablesType;
65
+ message: MessageVariablesType;
66
+ sender: SenderVariablesType;
67
+ chat: ChatVariablesType;
68
+ },
69
+ '.'
70
+ >,
71
+ {
72
+ rule: Tables<'tbl_automation_rules'>[];
73
+ id: 'reaction.reaction_id';
74
+ type: `reaction.added`;
75
+ org_id: string;
76
+ }
77
+ >;
78
+
79
+ export type ChatRulesInfoType = Merge<
80
+ AppendTypes<
81
+ {
82
+ chat: ChatVariablesType;
83
+ },
84
+ '.'
85
+ >,
86
+ {
87
+ rule: Tables<'tbl_automation_rules'>[];
88
+ id: 'chat.chat_id';
89
+ type: 'chat.created' | 'chat.label.updated';
90
+ org_id: string;
91
+ }
92
+ >;
93
+
94
+ export type RuleInfoType =
95
+ | MessageRulesInfoType
96
+ | ChatRulesInfoType
97
+ | TicketRulesInfoType
98
+ | ReactionRulesInfoType;
99
+
100
+ export interface Filter {
101
+ id: string;
102
+ condition:
103
+ | 'CONTAINS'
104
+ | 'NCONTAINS'
105
+ | 'EQ'
106
+ | 'NEQ'
107
+ | 'LT'
108
+ | 'LTE'
109
+ | 'GT'
110
+ | 'GTE'
111
+ | 'KNOWN'
112
+ | 'NKNOWN'
113
+ | 'IS'
114
+ | 'NIS'
115
+ | 'ON'
116
+ | 'STARTS_WITH'
117
+ | 'ENDS_WITH'; // Add other condition types as needed
118
+ variable: string;
119
+ value: string | string[];
120
+ variable_type?: 'string' | 'number' | 'boolean' | 'day-time' | 'date' | 'day'; // Optional, like 'Date'
121
+ }
122
+
123
+ export const isFilter = (filter: any): filter is Filter => {
124
+ return (
125
+ typeof filter === 'object' &&
126
+ 'id' in filter &&
127
+ 'condition' in filter &&
128
+ 'variable' in filter &&
129
+ 'value' in filter
130
+ );
131
+ };
132
+
133
+ export const FilterNameMap: Record<
134
+ Filter['condition'],
135
+ {
136
+ name: string;
137
+ input: boolean;
138
+ }
139
+ > = {
140
+ EQ: {
141
+ name: 'equals to',
142
+ input: true,
143
+ },
144
+ NEQ: {
145
+ name: 'not equals to',
146
+ input: true,
147
+ },
148
+ CONTAINS: {
149
+ name: 'contains',
150
+ input: true,
151
+ },
152
+ NCONTAINS: {
153
+ name: 'does not contain',
154
+ input: true,
155
+ },
156
+ LT: {
157
+ name: 'less than',
158
+ input: true,
159
+ },
160
+ LTE: {
161
+ name: 'less than or equals to',
162
+ input: true,
163
+ },
164
+ GT: {
165
+ name: 'greater than',
166
+ input: true,
167
+ },
168
+ GTE: {
169
+ name: 'greater than or equals to',
170
+ input: true,
171
+ },
172
+ KNOWN: {
173
+ name: 'is known',
174
+ input: false,
175
+ },
176
+ NKNOWN: {
177
+ name: 'is not known',
178
+ input: false,
179
+ },
180
+ IS: {
181
+ name: 'is',
182
+ input: true,
183
+ },
184
+ NIS: {
185
+ name: 'is not',
186
+ input: true,
187
+ },
188
+ ON: {
189
+ name: 'on',
190
+ input: true,
191
+ },
192
+ STARTS_WITH: {
193
+ name: 'starts with',
194
+ input: true,
195
+ },
196
+ ENDS_WITH: {
197
+ name: 'ends with',
198
+ input: true,
199
+ },
200
+ };
201
+
202
+ export type VariableNameValueType = {
203
+ text: string;
204
+ type:
205
+ | 'string'
206
+ | 'time'
207
+ | 'boolean'
208
+ | 'dropdown'
209
+ | 'day-time'
210
+ | 'number'
211
+ | 'date';
212
+ variable_type: 'string' | 'number' | 'boolean' | 'day-time' | 'date';
213
+ value?:
214
+ | string
215
+ | {
216
+ id: string;
217
+ value: string | number | boolean;
218
+ label: string;
219
+ }[]
220
+ | null;
221
+ filters:
222
+ | Partial<
223
+ Record<
224
+ Filter['condition'],
225
+ {
226
+ info?: string;
227
+ }
228
+ >
229
+ >
230
+ | Filter['condition'][];
231
+ hidden?: boolean;
232
+ placeholder?: string;
233
+ info?: string;
234
+ };
235
+
236
+ export const MessageVariableNameMap: Record<
237
+ keyof AppendTypes<{ message: MessageVariablesType }, '.'>,
238
+ VariableNameValueType
239
+ > = {
240
+ 'message.body': {
241
+ text: 'Message Body',
242
+ type: 'string',
243
+ filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
244
+ placeholder: 'e.g. Test message',
245
+ variable_type: 'string',
246
+ },
247
+ 'message.sender_phone': {
248
+ text: 'Message Sender Phone',
249
+ type: 'string',
250
+ filters: ['EQ', 'NEQ'],
251
+ placeholder: 'e.g. 919876543210',
252
+ variable_type: 'string',
253
+ },
254
+ 'message.timestamp': {
255
+ text: 'Message Timestamp',
256
+ type: 'day-time',
257
+ filters: {
258
+ LT: {
259
+ info: 'When message is received before mentioned time (UTC)',
260
+ },
261
+ LTE: {
262
+ info: 'When message is received before mentioned time (UTC)',
263
+ },
264
+ GT: {
265
+ info: 'When message is received after mentioned time (UTC)',
266
+ },
267
+ GTE: {
268
+ info: 'When message is received on or after mentioned time (UTC)',
269
+ },
270
+ ON: {
271
+ info: 'When message is received on mentioned days',
272
+ },
273
+ },
274
+ variable_type: 'day-time',
275
+ info: 'The timestamp when the message was received',
276
+ },
277
+ 'message.flag_status': {
278
+ text: 'Message Flag Status',
279
+ filters: ['IS'],
280
+ type: 'boolean',
281
+ variable_type: 'boolean',
282
+ },
283
+ 'message.has_quoted_msg': {
284
+ text: 'Has Quoted Message',
285
+ filters: ['IS'],
286
+ type: 'boolean',
287
+ variable_type: 'boolean',
288
+ },
289
+ 'message.media': {
290
+ text: 'Has Media',
291
+ type: 'boolean',
292
+ filters: ['KNOWN', 'NKNOWN'],
293
+ variable_type: 'boolean',
294
+ },
295
+ 'message.performed_by': {
296
+ text: 'Message Sent By (email)',
297
+ type: 'dropdown',
298
+ value: 'org.members',
299
+ filters: ['EQ', 'NEQ'],
300
+ variable_type: 'string',
301
+ },
302
+ 'message.chat_id': {
303
+ text: 'Chat ID',
304
+ type: 'string',
305
+ filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
306
+ hidden: true,
307
+ variable_type: 'string',
308
+ },
309
+ 'message.message_ticket_id': {
310
+ text: 'Message Ticket ID',
311
+ type: 'string',
312
+ filters: ['EQ', 'NEQ'],
313
+ hidden: true,
314
+ variable_type: 'string',
315
+ },
316
+ 'message.message_id': {
317
+ text: 'Message ID',
318
+ type: 'string',
319
+ filters: ['EQ', 'NEQ'],
320
+ hidden: true,
321
+ variable_type: 'string',
322
+ },
323
+ 'message.org_phone': {
324
+ text: 'Org Phone',
325
+ type: 'string',
326
+ filters: ['EQ', 'NEQ'],
327
+ hidden: true,
328
+ variable_type: 'string',
329
+ },
330
+ 'message.org_id': {
331
+ text: 'Org ID',
332
+ type: 'string',
333
+ filters: ['EQ', 'NEQ'],
334
+ hidden: true,
335
+ variable_type: 'string',
336
+ },
337
+ 'message.message_type': {
338
+ text: 'Message Type',
339
+ type: 'dropdown',
340
+ value: [
341
+ { id: 'text', value: 'chat', label: 'Text' },
342
+ { id: 'image', value: 'image', label: 'Image' },
343
+ { id: 'video', value: 'video', label: 'Video' },
344
+ { id: 'audio', value: 'audio', label: 'Audio' },
345
+ { id: 'audio', value: 'ptt', label: 'PTT (Audio voice message)' },
346
+ { id: 'document', value: 'document', label: 'Document' },
347
+ ],
348
+ filters: ['EQ', 'NEQ'],
349
+ variable_type: 'string',
350
+ },
351
+ 'message.author': {
352
+ text: 'Message Author',
353
+ type: 'string',
354
+ filters: ['EQ', 'NEQ'],
355
+ hidden: true,
356
+ variable_type: 'string',
357
+ },
358
+ };
359
+
360
+ export const SenderVariableNameMap: Record<
361
+ keyof AppendTypes<{ sender: SenderVariablesType }, '.'>,
362
+ VariableNameValueType
363
+ > = {
364
+ 'sender.is_internal': {
365
+ text: 'Sender Is Internal',
366
+ type: 'boolean',
367
+ filters: ['IS'],
368
+ variable_type: 'boolean',
369
+ },
370
+ 'sender.contact_name': {
371
+ text: 'Sender Name',
372
+ type: 'string',
373
+ filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
374
+ placeholder: 'e.g. John Doe',
375
+ variable_type: 'string',
376
+ },
377
+ 'sender.contact_id': {
378
+ text: 'Sender Phone',
379
+ type: 'string',
380
+ filters: ['EQ', 'NEQ'],
381
+ placeholder: 'e.g. 919876543210',
382
+ variable_type: 'string',
383
+ },
384
+ 'sender.org_id': {
385
+ text: 'Org ID',
386
+ type: 'string',
387
+ filters: ['EQ', 'NEQ'],
388
+ hidden: true,
389
+ variable_type: 'string',
390
+ },
391
+ 'sender.labels': {
392
+ text: 'Sender Contact Labels',
393
+ type: 'dropdown',
394
+ value: 'org.labels',
395
+ filters: ['CONTAINS', 'NCONTAINS'],
396
+ variable_type: 'string',
397
+ },
398
+ 'sender.is_admin': {
399
+ text: 'Sender Is Admin',
400
+ type: 'dropdown',
401
+ filters: ['EQ', 'NEQ'],
402
+ value: [
403
+ {
404
+ id: 'true',
405
+ value: 'true',
406
+ label: 'True',
407
+ },
408
+ {
409
+ id: 'false',
410
+ value: 'false',
411
+ label: 'False',
412
+ },
413
+ ],
414
+ variable_type: 'boolean',
415
+ },
416
+ };
417
+
418
+ export const ChatVariableNameMap: Record<
419
+ keyof AppendTypes<{ chat: ChatVariablesType }, '.'>,
420
+ VariableNameValueType
421
+ > = {
422
+ 'chat.assigned_to': {
423
+ text: 'Chat Assignee',
424
+ type: 'dropdown',
425
+ value: 'org.members',
426
+ filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
427
+ variable_type: 'string',
428
+ },
429
+ 'chat.chat_name': {
430
+ text: 'Chat Name',
431
+ type: 'string',
432
+ filters: ['EQ', 'NEQ', 'CONTAINS', 'NCONTAINS'],
433
+ placeholder: 'e.g. Support Chat',
434
+ variable_type: 'string',
435
+ },
436
+ 'chat.org_phone': {
437
+ text: 'Chat Org Phone',
438
+ type: 'dropdown',
439
+ value: 'org.org_phones',
440
+ filters: ['EQ', 'NEQ'],
441
+ variable_type: 'string',
442
+ },
443
+ 'chat.chat_type': {
444
+ text: 'Chat Type',
445
+ type: 'dropdown',
446
+ value: [
447
+ { id: 'user', value: 'user', label: 'User' },
448
+ { id: 'group', value: 'group', label: 'Group' },
449
+ ],
450
+ filters: ['EQ', 'NEQ'],
451
+ variable_type: 'string',
452
+ },
453
+ 'chat.members': {
454
+ text: 'Chat Members',
455
+ type: 'string',
456
+ filters: ['CONTAINS', 'NCONTAINS'],
457
+ placeholder: 'e.g. 919876543210',
458
+ variable_type: 'string',
459
+ },
460
+ 'chat.labels': {
461
+ text: 'Chat Labels',
462
+ type: 'dropdown',
463
+ value: 'org.labels',
464
+ filters: ['CONTAINS', 'NCONTAINS'],
465
+ variable_type: 'string',
466
+ },
467
+ 'chat.chat_id': {
468
+ text: 'Chat ID',
469
+ type: 'string',
470
+ filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
471
+ placeholder: 'e.g. 12027747916749@g.us',
472
+ variable_type: 'string',
473
+ },
474
+ 'chat.chat_org_phones': {
475
+ text: 'Chat Org Phones',
476
+ type: 'dropdown',
477
+ filters: ['CONTAINS', 'NCONTAINS'],
478
+ hidden: true,
479
+ variable_type: 'string',
480
+ },
481
+ 'chat.org_id': {
482
+ text: 'Org ID',
483
+ type: 'string',
484
+ filters: [],
485
+ hidden: true,
486
+ variable_type: 'string',
487
+ },
488
+ 'chat.messages_admins_only': {
489
+ text: 'Messages Admins Only (Chat Settings)',
490
+ type: 'boolean',
491
+ filters: ['EQ', 'NEQ'],
492
+ value: [
493
+ {
494
+ id: 'true',
495
+ value: 'true',
496
+ label: 'True',
497
+ },
498
+ {
499
+ id: 'false',
500
+ value: 'false',
501
+ label: 'False',
502
+ },
503
+ ],
504
+ variable_type: 'boolean',
505
+ },
506
+ 'chat.info_admins_only': {
507
+ text: 'Info Admins Only (Chat Settings)',
508
+ type: 'boolean',
509
+ filters: ['EQ', 'NEQ'],
510
+ value: [
511
+ {
512
+ id: 'true',
513
+ value: 'true',
514
+ label: 'True',
515
+ },
516
+ {
517
+ id: 'false',
518
+ value: 'false',
519
+ label: 'False',
520
+ },
521
+ ],
522
+ variable_type: 'boolean',
523
+ },
524
+ 'chat.has_flagged_messages': {
525
+ text: 'Chat Has Flagged Messages',
526
+ type: 'boolean',
527
+ filters: ['EQ', 'NEQ'],
528
+ value: [
529
+ {
530
+ id: 'true',
531
+ value: 'true',
532
+ label: 'True',
533
+ },
534
+ {
535
+ id: 'false',
536
+ value: 'false',
537
+ label: 'False',
538
+ },
539
+ ],
540
+ variable_type: 'boolean',
541
+ },
542
+ 'chat.group_description': {
543
+ text: 'Group Description',
544
+ type: 'string',
545
+ filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
546
+ placeholder: 'e.g. Group description',
547
+ variable_type: 'string',
548
+ },
549
+ 'chat.custom_properties': {
550
+ text: 'Chat Custom Properties',
551
+ type: 'dropdown',
552
+ value: 'org.custom_properties',
553
+ filters: ['EQ', 'NEQ'],
554
+ hidden: true,
555
+ variable_type: 'string',
556
+ },
557
+ 'chat.initiated_by': {
558
+ text: 'Chat Initiated By',
559
+ type: 'dropdown',
560
+ value: 'org.members',
561
+ filters: ['EQ', 'NEQ'],
562
+ variable_type: 'string',
563
+ hidden: true,
564
+ },
565
+ 'chat.created_at': {
566
+ text: 'Chat Created At',
567
+ type: 'day-time',
568
+ filters: {
569
+ LT: {
570
+ info: 'When chat is created before mentioned time (UTC)',
571
+ },
572
+ LTE: {
573
+ info: 'When chat is created before mentioned time (UTC)',
574
+ },
575
+ GT: {
576
+ info: 'When chat is created after mentioned time (UTC)',
577
+ },
578
+ GTE: {
579
+ info: 'When chat is created on or after mentioned time (UTC)',
580
+ },
581
+ ON: {
582
+ info: 'When chat is created on mentioned days',
583
+ },
584
+ },
585
+ variable_type: 'day-time',
586
+ },
587
+ };
588
+
589
+ export const TicketVariableNameMap: Record<
590
+ keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>,
591
+ VariableNameValueType
592
+ > = {
593
+ 'ticket.subject': {
594
+ text: 'Ticket Subject',
595
+ type: 'string',
596
+ filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
597
+ placeholder: 'e.g. Test ticket',
598
+ variable_type: 'string',
599
+ },
600
+ 'ticket.status': {
601
+ text: 'Ticket Status',
602
+ type: 'dropdown',
603
+ value: [
604
+ { id: 'open', value: 'open', label: 'Open' },
605
+ { id: 'closed', value: 'closed', label: 'Closed' },
606
+ { id: 'inprogress', value: 'inprogress', label: 'In progress' },
607
+ ],
608
+ filters: ['EQ', 'NEQ'],
609
+ variable_type: 'string',
610
+ },
611
+ 'ticket.priority': {
612
+ text: 'Ticket Priority',
613
+ type: 'dropdown',
614
+ value: [
615
+ { id: '0', value: '0', label: 'No Priority' },
616
+ { id: '1', value: '1', label: 'Low' },
617
+ { id: '2', value: '2', label: 'Medium' },
618
+ { id: '3', value: '3', label: 'High' },
619
+ { id: '4', value: '4', label: 'Urgent' },
620
+ ],
621
+ filters: ['EQ', 'NEQ'],
622
+ variable_type: 'string',
623
+ },
624
+ 'ticket.assignee': {
625
+ text: 'Ticket Assignee',
626
+ type: 'dropdown',
627
+ value: 'org.members',
628
+ filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
629
+ variable_type: 'string',
630
+ },
631
+ 'ticket.labels': {
632
+ text: 'Ticket Labels',
633
+ type: 'dropdown',
634
+ value: 'org.labels',
635
+ filters: ['CONTAINS', 'NCONTAINS'],
636
+ variable_type: 'string',
637
+ },
638
+ 'ticket.is_deleted': {
639
+ text: 'Ticket Is Deleted',
640
+ type: 'boolean',
641
+ value: [
642
+ {
643
+ id: 'true',
644
+ value: 'true',
645
+ label: 'True',
646
+ },
647
+ {
648
+ id: 'false',
649
+ value: 'false',
650
+ label: 'False',
651
+ },
652
+ ],
653
+ filters: ['IS'],
654
+ variable_type: 'boolean',
655
+ },
656
+ 'ticket.raised_by': {
657
+ text: 'Ticket Raised By',
658
+ type: 'dropdown',
659
+ value: 'org.members',
660
+ filters: ['EQ', 'NEQ'],
661
+ variable_type: 'string',
662
+ },
663
+ 'ticket.due_date': {
664
+ text: 'Ticket Due Date',
665
+ type: 'date',
666
+ filters: ['KNOWN', 'NKNOWN'],
667
+ variable_type: 'date',
668
+ hidden: true,
669
+ },
670
+ 'ticket.ticket_id': {
671
+ text: 'Ticket ID',
672
+ type: 'string',
673
+ filters: ['EQ', 'NEQ'],
674
+ hidden: true,
675
+ variable_type: 'string',
676
+ },
677
+ 'ticket.org_id': {
678
+ text: 'Org ID',
679
+ type: 'string',
680
+ filters: ['EQ', 'NEQ'],
681
+ hidden: true,
682
+ variable_type: 'string',
683
+ },
684
+ 'ticket.custom_properties': {
685
+ text: 'Ticket Custom Properties',
686
+ type: 'dropdown',
687
+ value: 'org.custom_properties',
688
+ filters: ['EQ', 'NEQ'],
689
+ hidden: true,
690
+ variable_type: 'string',
691
+ },
692
+ 'ticket.created_at': {
693
+ text: 'Ticket Created At',
694
+ type: 'day-time',
695
+ filters: {
696
+ LT: {
697
+ info: 'When ticket is created before mentioned time (UTC)',
698
+ },
699
+ LTE: {
700
+ info: 'When ticket is created before mentioned time (UTC)',
701
+ },
702
+ GT: {
703
+ info: 'When ticket is created after mentioned time (UTC)',
704
+ },
705
+ GTE: {
706
+ info: 'When ticket is created on or after mentioned time (UTC)',
707
+ },
708
+ ON: {
709
+ info: 'When ticket is created on mentioned days',
710
+ },
711
+ },
712
+ variable_type: 'day-time',
713
+ },
714
+ 'ticket.chat_id': {
715
+ text: 'Chat ID',
716
+ type: 'string',
717
+ filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
718
+ hidden: true,
719
+ variable_type: 'string',
720
+ },
721
+ };
722
+
723
+ export const ReactionVariableNameMap: Record<
724
+ keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>,
725
+ VariableNameValueType
726
+ > = {
727
+ 'reaction.reaction': {
728
+ text: 'Reaction',
729
+ type: 'string',
730
+ filters: ['EQ', 'NEQ'],
731
+ placeholder: 'e.g. 👍',
732
+ variable_type: 'string',
733
+ },
734
+ 'reaction.sender_id': {
735
+ text: 'Reaction Sender Phone',
736
+ type: 'string',
737
+ filters: ['EQ', 'NEQ'],
738
+ placeholder: 'e.g. 919876543210',
739
+ variable_type: 'string',
740
+ },
741
+ 'reaction.message_id': {
742
+ text: 'Reaction Message ID',
743
+ type: 'string',
744
+ filters: ['EQ', 'NEQ'],
745
+ hidden: true,
746
+ variable_type: 'string',
747
+ },
748
+ 'reaction.chat_id': {
749
+ text: 'Chat ID',
750
+ type: 'string',
751
+ filters: ['EQ', 'NEQ', 'STARTS_WITH', 'ENDS_WITH'],
752
+ hidden: true,
753
+ variable_type: 'string',
754
+ },
755
+ 'reaction.reaction_id': {
756
+ text: 'Reaction ID',
757
+ type: 'string',
758
+ filters: ['EQ', 'NEQ'],
759
+ hidden: true,
760
+ variable_type: 'string',
761
+ },
762
+ };
763
+
764
+ export enum FilterConditionMap {
765
+ 'CONTAINS' = 'contains',
766
+ 'NCONTAINS' = 'does not contain',
767
+ 'EQ' = '=',
768
+ 'NEQ' = '<>',
769
+ 'LT' = '<',
770
+ 'LTE' = '<=',
771
+ 'GT' = '>',
772
+ 'GTE' = '>=',
773
+ 'KNOWN' = 'is known',
774
+ 'NKNOWN' = 'is not known',
775
+ 'IS' = '=',
776
+ 'NIS' = '<>',
777
+ 'ON' = 'on',
778
+ 'STARTS_WITH' = 'starts with',
779
+ 'ENDS_WITH' = 'ends with',
780
+ }
781
+
782
+ interface FilterGroup {
783
+ filters: Filter[];
784
+ condition: 'allOf' | 'anyOf';
785
+ }
786
+
787
+ export interface Conditions {
788
+ filters: FilterGroup[];
789
+ condition: 'allOf' | 'anyOf';
790
+ variables: string[];
791
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
792
+ org_phones: string[];
793
+ allow_messages_from_org_phones?: boolean;
794
+ }
795
+
796
+ export type SendMessageAction = {
797
+ id: string;
798
+ type: 'send_message';
799
+ metadata: {
800
+ message: string;
801
+ media?: {
802
+ url: string;
803
+ type: 'image' | 'video' | 'audio' | 'document';
804
+ name: string;
805
+ };
806
+ maintain_flag_status: 'true' | 'false';
807
+ debounce_messages: 'true' | 'false';
808
+ debounce_message_time:
809
+ | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
810
+ | null
811
+ | undefined;
812
+ };
813
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
814
+ };
815
+
816
+ export type NotifyHttpAction = {
817
+ id: string;
818
+ type: 'notify_http';
819
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
820
+ metadata: {
821
+ url: string;
822
+ };
823
+ };
824
+
825
+ export type CreateTicketAction = {
826
+ id: string;
827
+ type: 'create_ticket';
828
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
829
+ metadata: {
830
+ priority?: '0' | '1' | '2' | '3' | '4';
831
+ label?: string;
832
+ append_to_latest_ticket?: 'true' | 'false';
833
+ round_robin?: 'true' | 'false';
834
+ assignee?: string;
835
+ rr_check_for?: 'shift_time' | 'user_status' | 'shift_time user_status';
836
+ };
837
+ };
838
+
839
+ export type FlagMessageAction = {
840
+ id: string;
841
+ type: 'flag_message';
842
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
843
+ metadata: {
844
+ flag: 'true' | 'false';
845
+ };
846
+ };
847
+
848
+ export type AssignTicketAction = {
849
+ id: string;
850
+ type: 'assign_ticket';
851
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
852
+ metadata: {
853
+ assignee: string;
854
+ round_robin: 'true' | 'false';
855
+ rr_check_for?: 'shift_time' | 'user_status' | 'shift_time user_status';
856
+ };
857
+ };
858
+
859
+ export type CloseTicketAction = {
860
+ id: string;
861
+ type: 'close_ticket';
862
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
863
+ metadata: {
864
+ closing_note: string;
865
+ };
866
+ };
867
+
868
+ export type AddChatLabelAction = {
869
+ id: string;
870
+ type: 'add_chat_label';
871
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
872
+ metadata: {
873
+ label: string;
874
+ };
875
+ };
876
+
877
+ export type AddTicketLabelAction = {
878
+ id: string;
879
+ type: 'add_ticket_label';
880
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
881
+ metadata: {
882
+ label: string;
883
+ };
884
+ };
885
+
886
+ export type AssignChatAction = {
887
+ id: string;
888
+ type: 'assign_chat';
889
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
890
+ metadata: {
891
+ assignee: string;
892
+ round_robin: 'true' | 'false';
893
+ rr_check_for?: 'shift_time' | 'user_status' | 'shift_time user_status';
894
+ };
895
+ };
896
+
897
+ export type ForwardMessageAction = {
898
+ id: string;
899
+ type: 'forward_message';
900
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
901
+ metadata: {
902
+ chat_id: string;
903
+ prefix: string;
904
+ };
905
+ };
906
+
907
+ export type SendEmailAction = {
908
+ id: string;
909
+ type: 'send_email';
910
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
911
+ metadata: {
912
+ email: string;
913
+ subject: string;
914
+ body: string;
915
+ };
916
+ };
917
+
918
+ export type ReplyToMessageAction = {
919
+ id: string;
920
+ type: 'reply_to_message';
921
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
922
+ metadata: {
923
+ message: string;
924
+ media?: {
925
+ url: string;
926
+ type: 'image' | 'video' | 'audio' | 'document';
927
+ name: string;
928
+ };
929
+ maintain_flag_status: 'true' | 'false';
930
+ debounce_messages: 'true' | 'false';
931
+ debounce_message_time:
932
+ | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
933
+ | null
934
+ | undefined;
935
+ };
936
+ };
937
+
938
+ export type UpdateCustomPropertyAction = {
939
+ id: string;
940
+ type: 'update_custom_property';
941
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
942
+ metadata: {
943
+ property_id: string;
944
+ value: string;
945
+ };
946
+ };
947
+
948
+ export type DeleteMessageAction = {
949
+ id: string;
950
+ type: 'delete_message';
951
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
952
+ metadata: {};
953
+ };
954
+
955
+ export type SendSlackNotificationAction = {
956
+ id: string;
957
+ type: 'send_slack_notification';
958
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
959
+ metadata: {
960
+ slack_payload: string;
961
+ webhook_url: string;
962
+ };
963
+ };
964
+
965
+ export type AttachMessageToTicketAction = {
966
+ id: string;
967
+ type: 'attach_message_to_ticket';
968
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
969
+ metadata: {
970
+ status: 'open' | 'inprogress' | 'open_inprogress' | null;
971
+ };
972
+ };
973
+
974
+ export type CloseChatAction = {
975
+ id: string;
976
+ type: 'close_chat';
977
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
978
+ metadata: {};
979
+ };
980
+
981
+ export type SendMessageToChatAction = {
982
+ id: string;
983
+ type: 'send_message_to_chat';
984
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
985
+ metadata: {
986
+ chat_id: string;
987
+ message: string;
988
+ media?: {
989
+ url: string;
990
+ type: 'image' | 'video' | 'audio' | 'document';
991
+ name: string;
992
+ };
993
+ };
994
+ };
995
+
996
+ export type FreshdeskCreateTicketAction = {
997
+ id: string;
998
+ type: 'create_ticket_on_freshdesk';
999
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
1000
+ metadata: {};
1001
+ };
1002
+
1003
+ export type HubspotCreateTicketAction = {
1004
+ id: string;
1005
+ type: 'create_ticket_on_hubspot';
1006
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
1007
+ metadata: {};
1008
+ };
1009
+
1010
+ export type ZohodeskCreateTicketAction = {
1011
+ id: string;
1012
+ type: 'create_ticket_on_zohodesk';
1013
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
1014
+ metadata: {};
1015
+ };
1016
+
1017
+ export type Action =
1018
+ | SendMessageAction
1019
+ | NotifyHttpAction
1020
+ | CreateTicketAction
1021
+ | FlagMessageAction
1022
+ | AssignTicketAction
1023
+ | CloseTicketAction
1024
+ | AddChatLabelAction
1025
+ | AddTicketLabelAction
1026
+ | AssignChatAction
1027
+ | ForwardMessageAction
1028
+ | SendEmailAction
1029
+ | ReplyToMessageAction
1030
+ | UpdateCustomPropertyAction
1031
+ | DeleteMessageAction
1032
+ | SendSlackNotificationAction
1033
+ | AttachMessageToTicketAction
1034
+ | CloseChatAction
1035
+ | SendMessageToChatAction
1036
+ | FreshdeskCreateTicketAction
1037
+ | HubspotCreateTicketAction
1038
+ | ZohodeskCreateTicketAction;
1039
+
1040
+ export const isSendMessageOrReplyToMessageAction = (
1041
+ action: Action
1042
+ ): action is SendMessageAction | ReplyToMessageAction => {
1043
+ return ['send_message', 'reply_to_message'].includes(action.type);
1044
+ };
1045
+
1046
+ export type Rule = OverrideProperties<
1047
+ Tables<'tbl_automation_rules'>,
1048
+ {
1049
+ actions: Action[];
1050
+ conditions: Conditions;
1051
+ trigger:
1052
+ | 'message.created'
1053
+ | 'message.updated'
1054
+ | 'chat.created'
1055
+ | 'ticket.updated'
1056
+ | 'ticket.created'
1057
+ | 'reaction.added'
1058
+ | 'chat.label.updated'
1059
+ | 'message.flagged'
1060
+ | 'message.unflagged'
1061
+ | 'message.deleted'
1062
+ | 'ticket.closed';
1063
+ }
1064
+ >;
1065
+
1066
+ export const RuleNameMap: Record<
1067
+ Rule['trigger'],
1068
+ {
1069
+ title: string;
1070
+ description: string;
1071
+ base_conditions: {
1072
+ org_phone: boolean;
1073
+ };
1074
+ }
1075
+ > = {
1076
+ 'message.created': {
1077
+ title: 'New Message Received',
1078
+ description: 'When a new message is received from an external contact',
1079
+ base_conditions: {
1080
+ org_phone: true,
1081
+ },
1082
+ },
1083
+ 'chat.created': {
1084
+ title: 'New Chat Created',
1085
+ description: 'When a new chat is created',
1086
+ base_conditions: {
1087
+ org_phone: true,
1088
+ },
1089
+ },
1090
+ 'ticket.created': {
1091
+ title: 'New Ticket Created',
1092
+ description: 'When a new ticket is created',
1093
+ base_conditions: {
1094
+ org_phone: false,
1095
+ },
1096
+ },
1097
+ 'reaction.added': {
1098
+ title: 'New Reaction Added',
1099
+ description: 'When a reaction is added on a message',
1100
+ base_conditions: {
1101
+ org_phone: true,
1102
+ },
1103
+ },
1104
+ 'message.updated': {
1105
+ title: 'Message Updated',
1106
+ description: 'When a message is updated',
1107
+ base_conditions: {
1108
+ org_phone: true,
1109
+ },
1110
+ },
1111
+ 'ticket.updated': {
1112
+ title: 'Ticket Updated',
1113
+ description: 'When a ticket is updated',
1114
+ base_conditions: {
1115
+ org_phone: false,
1116
+ },
1117
+ },
1118
+ 'chat.label.updated': {
1119
+ title: 'Chat Label Added/Removed',
1120
+ description: 'When labels on chats are updated',
1121
+ base_conditions: {
1122
+ org_phone: false,
1123
+ },
1124
+ },
1125
+ 'message.flagged': {
1126
+ title: 'Message Flagged',
1127
+ description: 'When a message is flagged',
1128
+ base_conditions: {
1129
+ org_phone: true,
1130
+ },
1131
+ },
1132
+ 'message.unflagged': {
1133
+ title: 'Message Unflagged',
1134
+ description: 'When a message is unflagged',
1135
+ base_conditions: {
1136
+ org_phone: true,
1137
+ },
1138
+ },
1139
+ 'message.deleted': {
1140
+ title: 'Message Deleted',
1141
+ description: 'When a message is Deleted',
1142
+ base_conditions: {
1143
+ org_phone: true,
1144
+ },
1145
+ },
1146
+ 'ticket.closed': {
1147
+ title: 'Ticket Closed',
1148
+ description: 'When a Ticket is Closed',
1149
+ base_conditions: {
1150
+ org_phone: false,
1151
+ },
1152
+ },
1153
+ };
1154
+
1155
+ export type ValidateFunction<T extends any[] = any[]> = (...args: T) => boolean;
1156
+
1157
+ type ValidateArgsMap = {
1158
+ create_ticket_on_freshdesk: [OrgType, Rule];
1159
+ create_ticket_on_hubspot: [OrgType, Rule];
1160
+ create_ticket_on_zohodesk: [OrgType, Rule];
1161
+ };
1162
+
1163
+ type ActionNameMapType = {
1164
+ [K in Action['type']]: {
1165
+ title: string;
1166
+ description: string;
1167
+ inputs: Record<
1168
+ string,
1169
+ {
1170
+ id: string;
1171
+ type:
1172
+ | 'text'
1173
+ | 'dropdown'
1174
+ | 'editor'
1175
+ | 'date'
1176
+ | 'file'
1177
+ | 'textarea'
1178
+ | 'dynamic'
1179
+ | 'json_editor';
1180
+ value:
1181
+ | 'ticket.labels'
1182
+ | 'org.members'
1183
+ | 'chat.labels'
1184
+ | 'org.chats'
1185
+ | {
1186
+ id: string;
1187
+ value: string;
1188
+ label: string;
1189
+ }[]
1190
+ | null
1191
+ | 'org.custom_properties'
1192
+ | 'custom_property_values'
1193
+ | 'debounce_messages';
1194
+ label: string;
1195
+ placeholder: string;
1196
+ info?: string;
1197
+ required: boolean;
1198
+ description?: string;
1199
+ }
1200
+ >;
1201
+ validate: K extends keyof ValidateArgsMap
1202
+ ? ValidateFunction<ValidateArgsMap[K]>
1203
+ : ValidateFunction<never[]>;
1204
+ info?: string;
1205
+ validTriggers: Rule['trigger'][];
1206
+ };
1207
+ };
1208
+
1209
+ export const ActionNameMap: ActionNameMapType = {
1210
+ send_message: {
1211
+ title: 'Send Message',
1212
+ description: 'Send a message',
1213
+ inputs: {
1214
+ message: {
1215
+ id: 'message',
1216
+ type: 'editor',
1217
+ label: 'Message',
1218
+ placeholder: 'Enter message',
1219
+ value: null,
1220
+ required: true,
1221
+ },
1222
+ media: {
1223
+ id: 'media',
1224
+ type: 'file',
1225
+ label: 'Media',
1226
+ placeholder: 'Upload media',
1227
+ value: null,
1228
+ required: false,
1229
+ },
1230
+ maintain_flag_status: {
1231
+ id: 'maintain_flag_status',
1232
+ type: 'dropdown',
1233
+ label: 'Maintain Flag Status',
1234
+ placeholder: 'Select...',
1235
+ value: [
1236
+ { id: 'true', value: 'true', label: 'True' },
1237
+ { id: 'false', value: 'false', label: 'False' },
1238
+ ],
1239
+ required: true,
1240
+ },
1241
+ debounce_messages: {
1242
+ id: 'debounce_messages',
1243
+ type: 'dropdown',
1244
+ label: 'Enable Cooldown Period',
1245
+ placeholder: 'Select...',
1246
+ value: [
1247
+ { id: 'true', value: 'true', label: 'True' },
1248
+ { id: 'false', value: 'false', label: 'False' },
1249
+ ],
1250
+ info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1251
+ required: false,
1252
+ },
1253
+ debounce_message_time: {
1254
+ id: 'debounce_message_time',
1255
+ type: 'dynamic',
1256
+ label: 'Cooldown Period',
1257
+ placeholder: 'Enter time',
1258
+ value: 'debounce_messages',
1259
+ required: false,
1260
+ },
1261
+ },
1262
+ validTriggers: [
1263
+ 'message.created',
1264
+ 'message.updated',
1265
+ 'chat.created',
1266
+ 'ticket.updated',
1267
+ 'ticket.created',
1268
+ 'reaction.added',
1269
+ 'message.flagged',
1270
+ 'message.unflagged',
1271
+ 'chat.label.updated',
1272
+ 'message.deleted',
1273
+ 'ticket.closed',
1274
+ ],
1275
+ validate: () => true,
1276
+ },
1277
+ reply_to_message: {
1278
+ title: 'Reply to message',
1279
+ description: 'Send a message with the quoted message',
1280
+ inputs: {
1281
+ message: {
1282
+ id: 'message',
1283
+ type: 'editor',
1284
+ label: 'Message',
1285
+ placeholder: 'Enter message',
1286
+ value: null,
1287
+ required: true,
1288
+ },
1289
+ media: {
1290
+ id: 'media',
1291
+ type: 'file',
1292
+ label: 'Media',
1293
+ placeholder: 'Upload media',
1294
+ value: null,
1295
+ required: false,
1296
+ },
1297
+ maintain_flag_status: {
1298
+ id: 'maintain_flag_status',
1299
+ type: 'dropdown',
1300
+ label: 'Maintain Flag Status',
1301
+ placeholder: 'Select...',
1302
+ value: [
1303
+ { id: 'true', value: 'true', label: 'True' },
1304
+ { id: 'false', value: 'false', label: 'False' },
1305
+ ],
1306
+ required: true,
1307
+ },
1308
+ debounce_messages: {
1309
+ id: 'debounce_messages',
1310
+ type: 'dropdown',
1311
+ label: 'Enable Cooldown Period',
1312
+ placeholder: 'Select...',
1313
+ value: [
1314
+ { id: 'true', value: 'true', label: 'True' },
1315
+ { id: 'false', value: 'false', label: 'False' },
1316
+ ],
1317
+ info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1318
+ required: false,
1319
+ },
1320
+ debounce_message_time: {
1321
+ id: 'debounce_message_time',
1322
+ type: 'dynamic',
1323
+ label: 'Cooldown Period',
1324
+ placeholder: 'Enter time',
1325
+ value: 'debounce_messages',
1326
+ required: false,
1327
+ },
1328
+ },
1329
+ validTriggers: [
1330
+ 'message.created',
1331
+ 'message.updated',
1332
+ 'reaction.added',
1333
+ 'message.flagged',
1334
+ 'ticket.created',
1335
+ 'ticket.updated',
1336
+ 'ticket.closed',
1337
+ 'message.unflagged',
1338
+ ],
1339
+ validate: () => true,
1340
+ },
1341
+ delete_message: {
1342
+ title: 'Delete Message',
1343
+ description: 'Delete a message',
1344
+ inputs: {},
1345
+ validTriggers: [
1346
+ 'message.created',
1347
+ 'message.updated',
1348
+ 'reaction.added',
1349
+ 'message.flagged',
1350
+ 'ticket.created',
1351
+ 'ticket.updated',
1352
+ 'ticket.closed',
1353
+ 'message.unflagged',
1354
+ ],
1355
+ validate: () => true,
1356
+ },
1357
+ attach_message_to_ticket: {
1358
+ title: 'Attach Message To Latest Ticket',
1359
+ description: 'Attach message to latest ticket based on statuses',
1360
+ inputs: {
1361
+ status: {
1362
+ id: 'status',
1363
+ type: 'dropdown',
1364
+ value: [
1365
+ {
1366
+ id: 'open_inprogress',
1367
+ value: 'open_inprogress',
1368
+ label: 'Open/In Progress',
1369
+ },
1370
+ { id: 'open', value: 'open', label: 'Open' },
1371
+ { id: 'inprogress', value: 'inprogress', label: 'In Progress' },
1372
+ ],
1373
+ label: 'Ticket Status',
1374
+ placeholder: 'Select...',
1375
+ required: true,
1376
+ info: 'Select the ticket status of ticket to attach the message to (only applicable for open or inprogress tickets)',
1377
+ },
1378
+ },
1379
+ validTriggers: [
1380
+ 'message.created',
1381
+ 'message.updated',
1382
+ 'reaction.added',
1383
+ 'message.flagged',
1384
+ ],
1385
+ validate: () => true,
1386
+ },
1387
+ notify_http: {
1388
+ title: 'Notify HTTP',
1389
+ description: 'Notify an HTTP endpoint',
1390
+ inputs: {
1391
+ url: {
1392
+ id: 'url',
1393
+ type: 'text',
1394
+ label: 'URL',
1395
+ placeholder: 'Enter URL',
1396
+ value: null,
1397
+ required: true,
1398
+ description:
1399
+ 'Enter the Webhook URL here. The endpoint added here should be a **POST HTTP / Endpoint** with no open auth.',
1400
+ },
1401
+ },
1402
+ validTriggers: [
1403
+ 'message.created',
1404
+ 'message.updated',
1405
+ 'chat.created',
1406
+ 'ticket.updated',
1407
+ 'ticket.created',
1408
+ 'reaction.added',
1409
+ 'message.flagged',
1410
+ 'chat.label.updated',
1411
+ 'message.deleted',
1412
+ 'ticket.closed',
1413
+ 'message.unflagged',
1414
+ ],
1415
+ validate: () => true,
1416
+ },
1417
+ create_ticket: {
1418
+ title: 'Create Ticket or Attach Message To Latest Ticket',
1419
+ description: 'Create a ticket or attach message to latest ticket',
1420
+ inputs: {
1421
+ append_to_latest_ticket: {
1422
+ id: 'append_to_latest_ticket',
1423
+ type: 'dropdown',
1424
+ value: [
1425
+ { id: 'true', value: 'true', label: 'True' },
1426
+ { id: 'false', value: 'false', label: 'False' },
1427
+ ],
1428
+ label: 'Attach message to latest ticket (if available)',
1429
+ placeholder: 'Select...',
1430
+ info: 'If enabled, the message will be appended to the latest open ticket (if available) else a new ticket will be created',
1431
+ required: false,
1432
+ },
1433
+ priority: {
1434
+ id: 'priority',
1435
+ type: 'dropdown',
1436
+ value: [
1437
+ { id: '0', value: '0', label: 'No Priority' },
1438
+ { id: '1', value: '1', label: 'Low' },
1439
+ { id: '2', value: '2', label: 'Medium' },
1440
+ { id: '3', value: '3', label: 'High' },
1441
+ { id: '4', value: '4', label: 'Urgent' },
1442
+ ],
1443
+ label: 'Priority (New Ticket)',
1444
+ placeholder: 'Select priority',
1445
+ info: 'Only applicable for create ticket. If no priority is selected, the ticket will have no priority.',
1446
+ required: false,
1447
+ },
1448
+ label: {
1449
+ id: 'label',
1450
+ type: 'dropdown',
1451
+ value: 'ticket.labels',
1452
+ label: 'Label (New Ticket)',
1453
+ placeholder: 'Select label',
1454
+ info: 'Only applicable for create ticket. If no label is selected, the ticket will have no label.',
1455
+ required: false,
1456
+ },
1457
+ round_robin: {
1458
+ id: 'round_robin',
1459
+ type: 'dropdown',
1460
+ value: [
1461
+ { id: 'true', value: 'true', label: 'True' },
1462
+ { id: 'false', value: 'false', label: 'False' },
1463
+ ],
1464
+ label: 'Enable Round Robin (New Ticket: Assignee)',
1465
+ placeholder: 'Select...',
1466
+ info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1467
+ required: false,
1468
+ },
1469
+ rr_check_for: {
1470
+ id: 'rr_check_for',
1471
+ type: 'dropdown',
1472
+ value: [
1473
+ {
1474
+ id: 'shift_time',
1475
+ value: 'shift_time',
1476
+ label: 'Consider shift timings',
1477
+ },
1478
+ {
1479
+ id: 'user_status',
1480
+ value: 'user_status',
1481
+ label: 'Exclude users marked as offline',
1482
+ },
1483
+ {
1484
+ id: 'shift_time user_status',
1485
+ value: 'shift_time user_status',
1486
+ label: 'Consider both shift timings and user status',
1487
+ },
1488
+ ],
1489
+ label: 'Check Assignee status for (Round Robin)',
1490
+ placeholder: 'Select...',
1491
+ info: 'Criteria for assigning the next available agent',
1492
+ required: false,
1493
+ },
1494
+ assignee: {
1495
+ id: 'assignee',
1496
+ type: 'dynamic',
1497
+ value: 'org.members',
1498
+ label: 'Assignee (New Ticket)',
1499
+ placeholder: 'Select assignee',
1500
+ info: "If round robin is enabled, the ticket will be assigned to the next available agent in the list else it'll be assigned to the selected agent",
1501
+ required: false,
1502
+ },
1503
+ },
1504
+ validTriggers: [
1505
+ 'message.created',
1506
+ 'message.updated',
1507
+ 'reaction.added',
1508
+ 'message.flagged',
1509
+ 'message.unflagged',
1510
+ ],
1511
+ validate: () => true,
1512
+ },
1513
+ flag_message: {
1514
+ title: 'Update flag status',
1515
+ description: 'Flag/Unflag a message',
1516
+ inputs: {
1517
+ flag: {
1518
+ id: 'flag',
1519
+ type: 'dropdown',
1520
+ value: [
1521
+ { id: 'flag', value: 'true', label: 'True' },
1522
+ { id: 'unflag', value: 'false', label: 'False' },
1523
+ ],
1524
+ label: 'Flag status',
1525
+ placeholder: 'Select flag',
1526
+ required: true,
1527
+ },
1528
+ },
1529
+ validTriggers: [
1530
+ 'message.created',
1531
+ 'message.updated',
1532
+ 'reaction.added',
1533
+ 'message.flagged',
1534
+ 'message.unflagged',
1535
+ 'ticket.created',
1536
+ 'ticket.updated',
1537
+ 'ticket.closed',
1538
+ ],
1539
+ validate: () => true,
1540
+ },
1541
+ assign_ticket: {
1542
+ title: 'Assign Ticket',
1543
+ description: 'Assign a ticket',
1544
+ inputs: {
1545
+ round_robin: {
1546
+ id: 'round_robin',
1547
+ type: 'dropdown',
1548
+ value: [
1549
+ { id: 'true', value: 'true', label: 'True' },
1550
+ { id: 'false', value: 'false', label: 'False' },
1551
+ ],
1552
+ label: 'Enable Round Robin',
1553
+ placeholder: 'Select...',
1554
+ info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1555
+ required: false,
1556
+ },
1557
+ rr_check_for: {
1558
+ id: 'rr_check_for',
1559
+ type: 'dropdown',
1560
+ value: [
1561
+ {
1562
+ id: 'shift_time',
1563
+ value: 'shift_time',
1564
+ label: 'Consider shift timings',
1565
+ },
1566
+ {
1567
+ id: 'user_status',
1568
+ value: 'user_status',
1569
+ label: 'Exclude users marked as offline',
1570
+ },
1571
+ {
1572
+ id: 'shift_time user_status',
1573
+ value: 'shift_time user_status',
1574
+ label: 'Consider both shift timings and user status',
1575
+ },
1576
+ ],
1577
+ label: 'Check Assignee status for (Round Robin)',
1578
+ placeholder: 'Select...',
1579
+ info: 'Criteria for assigning the next available agent',
1580
+ required: false,
1581
+ },
1582
+ assignee: {
1583
+ id: 'assignee',
1584
+ type: 'dynamic',
1585
+ value: 'org.members',
1586
+ label: 'Assignee',
1587
+ placeholder: 'Select assignee',
1588
+ info: "If round robin is enabled, the ticket will be assigned to the next available agent in the list else it'll be assigned to the selected agent",
1589
+ required: true,
1590
+ },
1591
+ },
1592
+ validTriggers: ['ticket.updated', 'ticket.created'],
1593
+ validate: () => true,
1594
+ },
1595
+ close_ticket: {
1596
+ title: 'Close Ticket',
1597
+ description: 'Close a ticket',
1598
+ info: "This action will close the ticket. This doesn't check for mandatory ticket custom properties.",
1599
+ inputs: {
1600
+ closing_note: {
1601
+ id: 'closing_note',
1602
+ type: 'textarea',
1603
+ label: 'Closing Note',
1604
+ placeholder: 'Enter closing note',
1605
+ value: null,
1606
+ required: false,
1607
+ },
1608
+ },
1609
+ validTriggers: [
1610
+ 'ticket.updated',
1611
+ 'ticket.created',
1612
+ 'reaction.added',
1613
+ 'message.unflagged',
1614
+ 'message.deleted',
1615
+ ],
1616
+ validate: () => true,
1617
+ },
1618
+ add_chat_label: {
1619
+ title: 'Add Chat Label',
1620
+ description: 'Add a label to referred chat',
1621
+ inputs: {
1622
+ label: {
1623
+ id: 'label',
1624
+ type: 'dropdown',
1625
+ value: 'chat.labels',
1626
+ label: 'Label',
1627
+ placeholder: 'Select label',
1628
+ required: true,
1629
+ },
1630
+ },
1631
+ validTriggers: [
1632
+ 'message.created',
1633
+ 'message.updated',
1634
+ 'chat.created',
1635
+ 'ticket.updated',
1636
+ 'ticket.created',
1637
+ 'reaction.added',
1638
+ 'chat.label.updated',
1639
+ 'message.flagged',
1640
+ 'message.deleted',
1641
+ 'message.unflagged',
1642
+ 'ticket.closed',
1643
+ ],
1644
+ validate: () => true,
1645
+ },
1646
+ add_ticket_label: {
1647
+ title: 'Add Ticket Label',
1648
+ description: 'Add a label to referred ticket',
1649
+ inputs: {
1650
+ label: {
1651
+ id: 'label',
1652
+ type: 'dropdown',
1653
+ value: 'ticket.labels',
1654
+ label: 'Label',
1655
+ placeholder: 'Select label',
1656
+ required: true,
1657
+ },
1658
+ },
1659
+ validTriggers: ['ticket.updated', 'ticket.created'],
1660
+ validate: () => true,
1661
+ },
1662
+ update_custom_property: {
1663
+ description: 'Update a chat custom property',
1664
+ title: 'Update Chat Custom Property',
1665
+ validTriggers: [
1666
+ 'message.created',
1667
+ 'message.updated',
1668
+ 'chat.created',
1669
+ 'ticket.updated',
1670
+ 'ticket.created',
1671
+ 'reaction.added',
1672
+ 'message.flagged',
1673
+ 'chat.label.updated',
1674
+ 'message.deleted',
1675
+ 'message.unflagged',
1676
+ 'ticket.closed',
1677
+ ],
1678
+ inputs: {
1679
+ property_id: {
1680
+ id: 'property_id',
1681
+ type: 'dropdown',
1682
+ value: 'org.custom_properties',
1683
+ label: 'Property',
1684
+ placeholder: 'Select property',
1685
+ required: true,
1686
+ },
1687
+ value: {
1688
+ id: 'property_id',
1689
+ type: 'dynamic',
1690
+ label: 'Value',
1691
+ placeholder: 'Enter value',
1692
+ value: 'custom_property_values',
1693
+ required: true,
1694
+ },
1695
+ },
1696
+ validate: () => true,
1697
+ },
1698
+ assign_chat: {
1699
+ title: 'Assign Chat',
1700
+ description: 'Assign a chat',
1701
+ inputs: {
1702
+ round_robin: {
1703
+ id: 'round_robin',
1704
+ type: 'dropdown',
1705
+ value: [
1706
+ { id: 'true', value: 'true', label: 'True' },
1707
+ { id: 'false', value: 'false', label: 'False' },
1708
+ ],
1709
+ label: 'Enable Round Robin',
1710
+ placeholder: 'Select...',
1711
+ info: 'If enabled, the chat will be assigned to the next available agent in the list',
1712
+ required: false,
1713
+ },
1714
+ rr_check_for: {
1715
+ id: 'rr_check_for',
1716
+ type: 'dropdown',
1717
+ value: [
1718
+ {
1719
+ id: 'shift_time',
1720
+ value: 'shift_time',
1721
+ label: 'Consider shift timings',
1722
+ },
1723
+ {
1724
+ id: 'user_status',
1725
+ value: 'user_status',
1726
+ label: 'Exclude users marked as offline',
1727
+ },
1728
+ {
1729
+ id: 'shift_time user_status',
1730
+ value: 'shift_time user_status',
1731
+ label: 'Consider both shift timings and user status',
1732
+ },
1733
+ ],
1734
+ label: 'Check Assignee status for (Round Robin)',
1735
+ placeholder: 'Select...',
1736
+ info: 'Criteria for assigning the next available agent',
1737
+ required: false,
1738
+ },
1739
+ assignee: {
1740
+ id: 'assignee',
1741
+ type: 'dynamic',
1742
+ value: 'org.members',
1743
+ label: 'Assignee',
1744
+ placeholder: 'Select assignee',
1745
+ required: true,
1746
+ },
1747
+ },
1748
+ validTriggers: [
1749
+ 'message.created',
1750
+ 'message.updated',
1751
+ 'chat.created',
1752
+ 'ticket.updated',
1753
+ 'ticket.created',
1754
+ 'reaction.added',
1755
+ 'chat.label.updated',
1756
+ 'message.flagged',
1757
+ 'message.deleted',
1758
+ 'message.unflagged',
1759
+ 'ticket.closed',
1760
+ ],
1761
+ validate: () => true,
1762
+ },
1763
+ close_chat: {
1764
+ title: 'Close Chat',
1765
+ description: 'Close a chat conversation',
1766
+ inputs: {},
1767
+ validTriggers: [
1768
+ 'message.created',
1769
+ 'message.updated',
1770
+ 'chat.created',
1771
+ 'ticket.updated',
1772
+ 'ticket.created',
1773
+ 'reaction.added',
1774
+ 'chat.label.updated',
1775
+ 'message.flagged',
1776
+ 'message.unflagged',
1777
+ 'message.deleted',
1778
+ 'ticket.closed',
1779
+ ],
1780
+ validate: () => true,
1781
+ },
1782
+ forward_message: {
1783
+ title: 'Forward Message',
1784
+ description: 'Forward a message',
1785
+ inputs: {
1786
+ chat_id: {
1787
+ id: 'chat_id',
1788
+ type: 'dropdown',
1789
+ value: 'org.chats',
1790
+ label: 'Chat',
1791
+ placeholder: 'Select chat',
1792
+ required: true,
1793
+ },
1794
+ },
1795
+ validTriggers: [
1796
+ 'message.created',
1797
+ 'message.updated',
1798
+ 'ticket.updated',
1799
+ 'ticket.created',
1800
+ 'reaction.added',
1801
+ 'message.unflagged',
1802
+ 'message.flagged',
1803
+ 'ticket.closed',
1804
+ ],
1805
+ validate: () => true,
1806
+ },
1807
+ send_email: {
1808
+ title: 'Send Email',
1809
+ description: 'Send an email',
1810
+ inputs: {
1811
+ email: {
1812
+ id: 'email',
1813
+ type: 'text',
1814
+ label: 'Email',
1815
+ placeholder: 'Enter email',
1816
+ value: null,
1817
+ required: true,
1818
+ },
1819
+ subject: {
1820
+ id: 'subject',
1821
+ type: 'editor',
1822
+ label: 'Subject',
1823
+ placeholder: 'Enter subject',
1824
+ value: null,
1825
+ required: true,
1826
+ },
1827
+ body: {
1828
+ id: 'body',
1829
+ type: 'editor',
1830
+ label: 'Body',
1831
+ placeholder: 'Enter body',
1832
+ value: null,
1833
+ required: true,
1834
+ },
1835
+ },
1836
+ validTriggers: [
1837
+ 'message.created',
1838
+ 'message.updated',
1839
+ 'chat.created',
1840
+ 'ticket.updated',
1841
+ 'ticket.created',
1842
+ 'reaction.added',
1843
+ 'message.flagged',
1844
+ 'message.unflagged',
1845
+ 'chat.label.updated',
1846
+ 'message.deleted',
1847
+ 'ticket.closed',
1848
+ ],
1849
+ validate: () => true,
1850
+ },
1851
+ send_slack_notification: {
1852
+ title: 'Send Slack Webhook Notification',
1853
+ description: 'Send a slack webhook notification to a channel',
1854
+ validTriggers: [
1855
+ 'message.created',
1856
+ 'message.updated',
1857
+ 'chat.created',
1858
+ 'ticket.updated',
1859
+ 'ticket.created',
1860
+ 'reaction.added',
1861
+ 'message.flagged',
1862
+ 'message.unflagged',
1863
+ 'chat.label.updated',
1864
+ 'message.deleted',
1865
+ 'ticket.closed',
1866
+ ],
1867
+ inputs: {
1868
+ webhook_url: {
1869
+ type: 'text',
1870
+ id: 'webhook_url',
1871
+ label: 'Webhook URL',
1872
+ placeholder: 'Enter webhook URL',
1873
+ value: null,
1874
+ required: true,
1875
+ description:
1876
+ 'Enter the webhook URL to send the notification, to create a slack incoming webhook to start receiving notification check [here](https://api.slack.com/messaging/webhooks)',
1877
+ },
1878
+ slack_payload: {
1879
+ type: 'json_editor',
1880
+ id: 'slack_payload',
1881
+ label: 'Slack Notification Payload',
1882
+ placeholder: 'Enter payload',
1883
+ value: null,
1884
+ required: true,
1885
+ description:
1886
+ 'You can send slack blocks as notifications to the provided hook URL.\n\nIn order to **build a slack notification block**, you can visit [here](https://api.slack.com/block-kit/building)',
1887
+ },
1888
+ },
1889
+ validate: () => true,
1890
+ },
1891
+ send_message_to_chat: {
1892
+ title: 'Send Message To Chat',
1893
+ description: 'Send a message to a specified chat',
1894
+ inputs: {
1895
+ chat_id: {
1896
+ id: 'chat_id',
1897
+ type: 'dropdown',
1898
+ value: 'org.chats',
1899
+ label: 'Chat',
1900
+ placeholder: 'Select chat',
1901
+ required: true,
1902
+ },
1903
+ message: {
1904
+ id: 'message',
1905
+ type: 'editor',
1906
+ label: 'Message',
1907
+ placeholder: 'Enter message',
1908
+ value: null,
1909
+ required: true,
1910
+ },
1911
+ media: {
1912
+ id: 'media',
1913
+ type: 'file',
1914
+ label: 'Media',
1915
+ placeholder: 'Upload media',
1916
+ value: null,
1917
+ required: false,
1918
+ },
1919
+ },
1920
+ validTriggers: [
1921
+ 'message.created',
1922
+ 'message.updated',
1923
+ 'chat.created',
1924
+ 'ticket.updated',
1925
+ 'ticket.created',
1926
+ 'reaction.added',
1927
+ 'message.flagged',
1928
+ 'message.unflagged',
1929
+ 'chat.label.updated',
1930
+ 'message.deleted',
1931
+ 'ticket.closed',
1932
+ ],
1933
+ validate: () => true,
1934
+ },
1935
+ create_ticket_on_freshdesk: {
1936
+ title: 'Create Ticket On Freshdesk',
1937
+ description: 'Create a ticket on Freshdesk',
1938
+ info: 'This action will create a ticket on Freshdesk. Please make sure you have a Freshdesk integration setup.',
1939
+ inputs: {},
1940
+ validTriggers: ['ticket.created'],
1941
+ validate: (org, rule) => {
1942
+ return (
1943
+ org.is_freshdesk_connected ||
1944
+ rule.actions.some((a) => a.type === 'create_ticket_on_freshdesk')
1945
+ );
1946
+ },
1947
+ },
1948
+ create_ticket_on_hubspot: {
1949
+ title: 'Create Ticket On Hubspot',
1950
+ description: 'Create a ticket on Hubspot',
1951
+ info: 'This action will create a ticket on Hubspot. Please make sure you have a Hubspot integration setup.',
1952
+ inputs: {},
1953
+ validTriggers: ['ticket.created'],
1954
+ validate: (org, rule) => {
1955
+ return (
1956
+ org.is_hubspot_connected ||
1957
+ rule.actions.some((a) => a.type === 'create_ticket_on_hubspot')
1958
+ );
1959
+ },
1960
+ },
1961
+ create_ticket_on_zohodesk: {
1962
+ title: 'Create Ticket On Zohodesk',
1963
+ description: 'Create a ticket on Zohodesk',
1964
+ info: 'This action will create a ticket on Zohodesk. Please make sure you have a Zohodesk integration setup.',
1965
+ inputs: {},
1966
+ validTriggers: ['ticket.created'],
1967
+ validate: (org, rule) => {
1968
+ return (
1969
+ org.is_zohodesk_connected ||
1970
+ rule.actions.some((a) => a.type === 'create_ticket_on_zohodesk')
1971
+ );
1972
+ },
1973
+ },
1974
+ };
1975
+
1976
+ type editorVariablesList =
1977
+ | 'chat.assigned_to'
1978
+ | 'chat.chat_id'
1979
+ | 'chat.chat_name'
1980
+ | 'chat.chat_type'
1981
+ | 'chat.org_phone'
1982
+ | 'chat.org_id'
1983
+ | 'chat.group_description'
1984
+ | 'ticket.assignee'
1985
+ | 'ticket.due_date'
1986
+ | 'ticket.priority'
1987
+ | 'ticket.status'
1988
+ | 'ticket.subject'
1989
+ | 'ticket.ticket_id'
1990
+ | 'ticket.raised_by'
1991
+ | 'ticket.created_at'
1992
+ | 'sender.is_internal'
1993
+ | 'sender.is_admin'
1994
+ | 'sender.contact_name'
1995
+ | 'sender.contact_id'
1996
+ | 'reaction.sender_id'
1997
+ | 'reaction.reaction'
1998
+ | 'message.message_id'
1999
+ | 'message.timestamp'
2000
+ | 'message.sender_phone'
2001
+ | 'message.message_type'
2002
+ | 'message.media'
2003
+ | 'message.body';
2004
+
2005
+ export const editorVariables: Array<{
2006
+ label: string;
2007
+ value: editorVariablesList;
2008
+ validTriggers: Rule['trigger'][];
2009
+ }> = [
2010
+ {
2011
+ label: 'Ticket ID',
2012
+ value: 'ticket.ticket_id',
2013
+ validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
2014
+ },
2015
+ {
2016
+ value: 'ticket.assignee',
2017
+ label: 'Ticket Assignee',
2018
+ validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
2019
+ },
2020
+ {
2021
+ value: 'ticket.due_date',
2022
+ label: 'Ticket Due Date',
2023
+ validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
2024
+ },
2025
+ {
2026
+ value: 'ticket.priority',
2027
+ label: 'Ticket Priority',
2028
+ validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
2029
+ },
2030
+ {
2031
+ value: 'ticket.status',
2032
+ label: 'Ticket Status',
2033
+ validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
2034
+ },
2035
+ {
2036
+ value: 'ticket.subject',
2037
+ label: 'Ticket Subject',
2038
+ validTriggers: ['ticket.updated', 'ticket.created', 'ticket.closed'],
2039
+ },
2040
+ {
2041
+ label: 'Message Body',
2042
+ value: 'message.body',
2043
+ validTriggers: [
2044
+ 'message.created',
2045
+ 'message.updated',
2046
+ 'reaction.added',
2047
+ 'message.flagged',
2048
+ 'ticket.created',
2049
+ 'ticket.updated',
2050
+ 'ticket.closed',
2051
+ 'message.deleted',
2052
+ ],
2053
+ },
2054
+ {
2055
+ value: 'message.media',
2056
+ label: 'Message Media',
2057
+ validTriggers: [
2058
+ 'message.created',
2059
+ 'message.updated',
2060
+ 'reaction.added',
2061
+ 'message.flagged',
2062
+ 'ticket.created',
2063
+ 'ticket.updated',
2064
+ 'ticket.closed',
2065
+ 'message.deleted',
2066
+ ],
2067
+ },
2068
+ {
2069
+ value: 'message.message_id',
2070
+ label: 'Message ID',
2071
+ validTriggers: [
2072
+ 'message.created',
2073
+ 'message.updated',
2074
+ 'reaction.added',
2075
+ 'message.flagged',
2076
+ 'ticket.created',
2077
+ 'ticket.updated',
2078
+ 'ticket.closed',
2079
+ 'message.deleted',
2080
+ ],
2081
+ },
2082
+ {
2083
+ value: 'message.message_type',
2084
+ label: 'Message Type',
2085
+ validTriggers: [
2086
+ 'message.created',
2087
+ 'message.updated',
2088
+ 'reaction.added',
2089
+ 'message.flagged',
2090
+ 'ticket.created',
2091
+ 'ticket.updated',
2092
+ 'ticket.closed',
2093
+ 'message.deleted',
2094
+ ],
2095
+ },
2096
+ {
2097
+ value: 'message.sender_phone',
2098
+ label: 'Sender Phone',
2099
+ validTriggers: [
2100
+ 'message.created',
2101
+ 'message.updated',
2102
+ 'reaction.added',
2103
+ 'message.flagged',
2104
+ 'ticket.created',
2105
+ 'ticket.updated',
2106
+ 'ticket.closed',
2107
+ 'message.deleted',
2108
+ ],
2109
+ },
2110
+ {
2111
+ value: 'message.timestamp',
2112
+ label: 'Message Timestamp',
2113
+ validTriggers: [
2114
+ 'message.created',
2115
+ 'message.updated',
2116
+ 'reaction.added',
2117
+ 'message.flagged',
2118
+ 'ticket.created',
2119
+ 'ticket.updated',
2120
+ 'ticket.closed',
2121
+ 'message.deleted',
2122
+ ],
2123
+ },
2124
+ {
2125
+ label: 'Sender Name',
2126
+ value: 'sender.contact_name',
2127
+ validTriggers: [
2128
+ 'message.created',
2129
+ 'message.updated',
2130
+ 'reaction.added',
2131
+ 'message.flagged',
2132
+ 'ticket.created',
2133
+ 'ticket.updated',
2134
+ 'ticket.closed',
2135
+ 'message.deleted',
2136
+ ],
2137
+ },
2138
+ {
2139
+ value: 'sender.is_admin',
2140
+ label: 'Sender Is Admin',
2141
+ validTriggers: [
2142
+ 'message.created',
2143
+ 'message.updated',
2144
+ 'reaction.added',
2145
+ 'message.flagged',
2146
+ 'ticket.created',
2147
+ 'ticket.updated',
2148
+ 'ticket.closed',
2149
+ 'message.deleted',
2150
+ ],
2151
+ },
2152
+ {
2153
+ value: 'sender.is_internal',
2154
+ label: 'Sender Is Internal',
2155
+ validTriggers: [
2156
+ 'message.created',
2157
+ 'message.updated',
2158
+ 'reaction.added',
2159
+ 'message.flagged',
2160
+ 'ticket.created',
2161
+ 'ticket.updated',
2162
+ 'ticket.closed',
2163
+ 'message.deleted',
2164
+ ],
2165
+ },
2166
+ {
2167
+ label: 'Reaction',
2168
+ value: 'reaction.reaction',
2169
+ validTriggers: ['reaction.added'],
2170
+ },
2171
+ {
2172
+ value: 'reaction.sender_id',
2173
+ label: 'Reaction Sender Phone',
2174
+ validTriggers: ['reaction.added'],
2175
+ },
2176
+ {
2177
+ label: 'Chat Name',
2178
+ value: 'chat.chat_name',
2179
+ validTriggers: [
2180
+ 'message.created',
2181
+ 'message.updated',
2182
+ 'reaction.added',
2183
+ 'message.flagged',
2184
+ 'chat.created',
2185
+ 'chat.label.updated',
2186
+ 'ticket.created',
2187
+ 'ticket.updated',
2188
+ 'ticket.closed',
2189
+ 'message.deleted',
2190
+ ],
2191
+ },
2192
+ {
2193
+ value: 'chat.assigned_to',
2194
+ label: 'Chat Assigned To',
2195
+ validTriggers: [
2196
+ 'message.created',
2197
+ 'message.updated',
2198
+ 'reaction.added',
2199
+ 'message.flagged',
2200
+ 'chat.created',
2201
+ 'chat.label.updated',
2202
+ 'ticket.created',
2203
+ 'ticket.updated',
2204
+ 'ticket.closed',
2205
+ 'message.deleted',
2206
+ ],
2207
+ },
2208
+ {
2209
+ value: 'chat.chat_id',
2210
+ label: 'Chat ID',
2211
+ validTriggers: [
2212
+ 'message.created',
2213
+ 'message.updated',
2214
+ 'reaction.added',
2215
+ 'message.flagged',
2216
+ 'chat.created',
2217
+ 'chat.label.updated',
2218
+ 'ticket.created',
2219
+ 'ticket.updated',
2220
+ 'ticket.closed',
2221
+ 'message.deleted',
2222
+ ],
2223
+ },
2224
+ {
2225
+ value: 'chat.chat_type',
2226
+ label: 'Chat Type',
2227
+ validTriggers: [
2228
+ 'message.created',
2229
+ 'message.updated',
2230
+ 'reaction.added',
2231
+ 'message.flagged',
2232
+ 'chat.created',
2233
+ 'chat.label.updated',
2234
+ 'ticket.created',
2235
+ 'ticket.updated',
2236
+ 'ticket.closed',
2237
+ 'message.deleted',
2238
+ ],
2239
+ },
2240
+ {
2241
+ value: 'chat.org_id',
2242
+ label: 'Chat Org ID',
2243
+ validTriggers: [
2244
+ 'message.created',
2245
+ 'message.updated',
2246
+ 'reaction.added',
2247
+ 'message.flagged',
2248
+ 'chat.created',
2249
+ 'chat.label.updated',
2250
+ 'ticket.created',
2251
+ 'ticket.updated',
2252
+ 'ticket.closed',
2253
+ 'message.deleted',
2254
+ ],
2255
+ },
2256
+ {
2257
+ value: 'chat.org_phone',
2258
+ label: 'Chat Org Phone',
2259
+ validTriggers: [
2260
+ 'message.created',
2261
+ 'message.updated',
2262
+ 'reaction.added',
2263
+ 'message.flagged',
2264
+ 'chat.created',
2265
+ 'chat.label.updated',
2266
+ 'ticket.created',
2267
+ 'ticket.updated',
2268
+ 'ticket.closed',
2269
+ 'message.deleted',
2270
+ ],
2271
+ },
2272
+ ];
2273
+
2274
+ export const variablesExclusionList: Record<
2275
+ Rule['trigger'],
2276
+ Array<
2277
+ | keyof AppendTypes<{ message: MessageVariablesType }, '.'>
2278
+ | keyof AppendTypes<{ sender: SenderVariablesType }, '.'>
2279
+ | keyof AppendTypes<{ chat: ChatVariablesType }, '.'>
2280
+ | keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>
2281
+ | keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>
2282
+ >
2283
+ > = {
2284
+ 'ticket.created': ['ticket.is_deleted'],
2285
+ 'chat.created': [
2286
+ 'chat.labels',
2287
+ 'chat.has_flagged_messages',
2288
+ 'chat.assigned_to',
2289
+ ],
2290
+ 'message.created': [
2291
+ 'message.author',
2292
+ 'message.performed_by',
2293
+ 'message.flag_status',
2294
+ 'sender.is_internal',
2295
+ ],
2296
+ 'ticket.updated': ['ticket.is_deleted'],
2297
+ 'reaction.added': [],
2298
+ 'message.updated': [],
2299
+ 'message.flagged': [],
2300
+ 'message.unflagged': [],
2301
+ 'message.deleted': [],
2302
+ 'ticket.closed': ['ticket.is_deleted'],
2303
+ 'chat.label.updated': [],
2304
+ };