@periskope/types 0.6.166 → 0.6.167

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.
package/rules.types.ts CHANGED
@@ -1,1599 +1,1601 @@
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'}`;
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'}`;
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'; // Add other condition types as needed
115
- variable: string;
116
- value: string | string[];
117
- variable_type?: 'string' | 'number' | 'boolean' | 'day-time' | 'date' | 'day'; // Optional, like 'Date'
118
- }
119
-
120
- export const isFilter = (filter: any): filter is Filter => {
121
- return (
122
- typeof filter === 'object' &&
123
- 'id' in filter &&
124
- 'condition' in filter &&
125
- 'variable' in filter &&
126
- 'value' in filter
127
- );
128
- };
129
-
130
- export const FilterNameMap: Record<
131
- Filter['condition'],
132
- {
133
- name: string;
134
- input: boolean;
135
- }
136
- > = {
137
- EQ: {
138
- name: 'equals to',
139
- input: true,
140
- },
141
- NEQ: {
142
- name: 'not equals to',
143
- input: true,
144
- },
145
- CONTAINS: {
146
- name: 'contains',
147
- input: true,
148
- },
149
- NCONTAINS: {
150
- name: 'does not contain',
151
- input: true,
152
- },
153
- LT: {
154
- name: 'less than',
155
- input: true,
156
- },
157
- LTE: {
158
- name: 'less than or equals to',
159
- input: true,
160
- },
161
- GT: {
162
- name: 'greater than',
163
- input: true,
164
- },
165
- GTE: {
166
- name: 'greater than or equals to',
167
- input: true,
168
- },
169
- KNOWN: {
170
- name: 'is known',
171
- input: false,
172
- },
173
- NKNOWN: {
174
- name: 'is not known',
175
- input: false,
176
- },
177
- IS: {
178
- name: 'is',
179
- input: true,
180
- },
181
- NIS: {
182
- name: 'is not',
183
- input: true,
184
- },
185
- ON: {
186
- name: 'on',
187
- input: true,
188
- },
189
- };
190
-
191
- export type VariableNameValueType = {
192
- text: string;
193
- type:
194
- | 'string'
195
- | 'time'
196
- | 'boolean'
197
- | 'dropdown'
198
- | 'day-time'
199
- | 'number'
200
- | 'date';
201
- variable_type: 'string' | 'number' | 'boolean' | 'day-time' | 'date';
202
- value?:
203
- | string
204
- | {
205
- id: string;
206
- value: string | number | boolean;
207
- label: string;
208
- }[]
209
- | null;
210
- filters:
211
- | Partial<
212
- Record<
213
- Filter['condition'],
214
- {
215
- info?: string;
216
- }
217
- >
218
- >
219
- | Filter['condition'][];
220
- hidden?: boolean;
221
- placeholder?: string;
222
- info?: string;
223
- };
224
-
225
- export const MessageVariableNameMap: Record<
226
- keyof AppendTypes<{ message: MessageVariablesType }, '.'>,
227
- VariableNameValueType
228
- > = {
229
- 'message.body': {
230
- text: 'Message Body',
231
- type: 'string',
232
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
233
- placeholder: 'e.g. Test message',
234
- variable_type: 'string',
235
- },
236
- 'message.sender_phone': {
237
- text: 'Message Sender Phone',
238
- type: 'string',
239
- filters: ['EQ', 'NEQ'],
240
- placeholder: 'e.g. 919876543210',
241
- variable_type: 'string',
242
- },
243
- 'message.timestamp': {
244
- text: 'Message Timestamp',
245
- type: 'day-time',
246
- filters: {
247
- LT: {
248
- info: 'When message is received before mentioned time (UTC)',
249
- },
250
- LTE: {
251
- info: 'When message is received before mentioned time (UTC)',
252
- },
253
- GT: {
254
- info: 'When message is received after mentioned time (UTC)',
255
- },
256
- GTE: {
257
- info: 'When message is received on or after mentioned time (UTC)',
258
- },
259
- ON: {
260
- info: 'When message is received on mentioned days',
261
- },
262
- },
263
- variable_type: 'day-time',
264
- info: 'The timestamp when the message was received',
265
- },
266
- 'message.flag_status': {
267
- text: 'Message Flag Status',
268
- filters: ['IS'],
269
- type: 'boolean',
270
- variable_type: 'boolean',
271
- },
272
- 'message.has_quoted_msg': {
273
- text: 'Has Quoted Message',
274
- filters: ['IS'],
275
- type: 'boolean',
276
- variable_type: 'boolean',
277
- },
278
- 'message.media': {
279
- text: 'Has Media',
280
- type: 'boolean',
281
- filters: ['KNOWN', 'NKNOWN'],
282
- variable_type: 'boolean',
283
- },
284
- 'message.performed_by': {
285
- text: 'Message Sent By (email)',
286
- type: 'dropdown',
287
- value: 'org.members',
288
- filters: ['EQ', 'NEQ'],
289
- variable_type: 'string',
290
- },
291
- 'message.chat_id': {
292
- text: 'Chat ID',
293
- type: 'string',
294
- filters: ['EQ', 'NEQ'],
295
- hidden: true,
296
- variable_type: 'string',
297
- },
298
- 'message.message_id': {
299
- text: 'Message ID',
300
- type: 'string',
301
- filters: ['EQ', 'NEQ'],
302
- hidden: true,
303
- variable_type: 'string',
304
- },
305
- 'message.org_phone': {
306
- text: 'Org Phone',
307
- type: 'string',
308
- filters: ['EQ', 'NEQ'],
309
- hidden: true,
310
- variable_type: 'string',
311
- },
312
- 'message.org_id': {
313
- text: 'Org ID',
314
- type: 'string',
315
- filters: ['EQ', 'NEQ'],
316
- hidden: true,
317
- variable_type: 'string',
318
- },
319
- 'message.message_type': {
320
- text: 'Message Type',
321
- type: 'dropdown',
322
- value: [
323
- { id: 'text', value: 'chat', label: 'Text' },
324
- { id: 'image', value: 'image', label: 'Image' },
325
- { id: 'video', value: 'video', label: 'Video' },
326
- { id: 'audio', value: 'audio', label: 'Audio' },
327
- { id: 'audio', value: 'ptt', label: 'PTT (Audio voice message)' },
328
- { id: 'document', value: 'document', label: 'Document' },
329
- ],
330
- filters: ['EQ', 'NEQ'],
331
- variable_type: 'string',
332
- },
333
- 'message.author': {
334
- text: 'Message Author',
335
- type: 'string',
336
- filters: ['EQ', 'NEQ'],
337
- hidden: true,
338
- variable_type: 'string',
339
- },
340
- };
341
-
342
- export const SenderVariableNameMap: Record<
343
- keyof AppendTypes<{ sender: SenderVariablesType }, '.'>,
344
- VariableNameValueType
345
- > = {
346
- 'sender.is_internal': {
347
- text: 'Sender Is Internal',
348
- type: 'boolean',
349
- filters: ['IS'],
350
- variable_type: 'boolean',
351
- },
352
- 'sender.contact_name': {
353
- text: 'Sender Name',
354
- type: 'string',
355
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
356
- placeholder: 'e.g. John Doe',
357
- variable_type: 'string',
358
- },
359
- 'sender.contact_id': {
360
- text: 'Sender Phone',
361
- type: 'string',
362
- filters: ['EQ', 'NEQ'],
363
- placeholder: 'e.g. 919876543210',
364
- variable_type: 'string',
365
- },
366
- 'sender.labels': {
367
- text: 'Sender Contact Labels',
368
- type: 'dropdown',
369
- value: 'org.labels',
370
- filters: ['CONTAINS', 'NCONTAINS'],
371
- variable_type: 'string',
372
- },
373
- 'sender.org_id': {
374
- text: 'Org ID',
375
- type: 'string',
376
- filters: ['EQ', 'NEQ'],
377
- hidden: true,
378
- variable_type: 'string',
379
- },
380
- 'sender.is_admin': {
381
- text: 'Sender Is Admin',
382
- type: 'dropdown',
383
- filters: ['EQ', 'NEQ'],
384
- value: [
385
- {
386
- id: 'true',
387
- value: 'true',
388
- label: 'True',
389
- },
390
- {
391
- id: 'false',
392
- value: 'false',
393
- label: 'False',
394
- },
395
- ],
396
- variable_type: 'boolean',
397
- },
398
- };
399
-
400
- export const ChatVariableNameMap: Record<
401
- keyof AppendTypes<{ chat: ChatVariablesType }, '.'>,
402
- VariableNameValueType
403
- > = {
404
- 'chat.assigned_to': {
405
- text: 'Chat Assignee',
406
- type: 'dropdown',
407
- value: 'org.members',
408
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
409
- variable_type: 'string',
410
- },
411
- 'chat.chat_name': {
412
- text: 'Chat Name',
413
- type: 'string',
414
- filters: ['EQ', 'NEQ', 'CONTAINS', 'NCONTAINS'],
415
- placeholder: 'e.g. Support Chat',
416
- variable_type: 'string',
417
- },
418
- 'chat.org_phone': {
419
- text: 'Chat Org Phone',
420
- type: 'dropdown',
421
- value: 'org.org_phones',
422
- filters: ['EQ', 'NEQ'],
423
- variable_type: 'string',
424
- },
425
- 'chat.chat_type': {
426
- text: 'Chat Type',
427
- type: 'dropdown',
428
- value: [
429
- { id: 'user', value: 'user', label: 'User' },
430
- { id: 'group', value: 'group', label: 'Group' },
431
- ],
432
- filters: ['EQ', 'NEQ'],
433
- variable_type: 'string',
434
- },
435
- 'chat.members': {
436
- text: 'Chat Members',
437
- type: 'string',
438
- filters: ['CONTAINS', 'NCONTAINS'],
439
- placeholder: 'e.g. 919876543210',
440
- variable_type: 'string',
441
- },
442
- 'chat.labels': {
443
- text: 'Chat Labels',
444
- type: 'dropdown',
445
- value: 'org.labels',
446
- filters: ['CONTAINS', 'NCONTAINS'],
447
- variable_type: 'string',
448
- },
449
- 'chat.chat_id': {
450
- text: 'Chat ID',
451
- type: 'string',
452
- filters: ['EQ', 'NEQ'],
453
- placeholder: 'e.g. 12027747916749@c.us',
454
- variable_type: 'string',
455
- },
456
- 'chat.chat_org_phones': {
457
- text: 'Chat Org Phones',
458
- type: 'dropdown',
459
- filters: ['CONTAINS', 'NCONTAINS'],
460
- hidden: true,
461
- variable_type: 'string',
462
- },
463
- 'chat.org_id': {
464
- text: 'Org ID',
465
- type: 'string',
466
- filters: [],
467
- hidden: true,
468
- variable_type: 'string',
469
- },
470
- 'chat.messages_admins_only': {
471
- text: 'Messages Admins Only (Chat Settings)',
472
- type: 'boolean',
473
- filters: ['EQ', 'NEQ'],
474
- value: [
475
- {
476
- id: 'true',
477
- value: 'true',
478
- label: 'True',
479
- },
480
- {
481
- id: 'false',
482
- value: 'false',
483
- label: 'False',
484
- },
485
- ],
486
- variable_type: 'boolean',
487
- },
488
- 'chat.info_admins_only': {
489
- text: 'Info 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.has_flagged_messages': {
507
- text: 'Chat Has Flagged Messages',
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.group_description': {
525
- text: 'Group Description',
526
- type: 'string',
527
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
528
- placeholder: 'e.g. Group description',
529
- variable_type: 'string',
530
- },
531
- 'chat.custom_properties': {
532
- text: 'Chat Custom Properties',
533
- type: 'dropdown',
534
- value: 'org.custom_properties',
535
- filters: ['EQ', 'NEQ'],
536
- hidden: true,
537
- variable_type: 'string',
538
- },
539
- 'chat.created_at': {
540
- text: 'Chat Created At',
541
- type: 'day-time',
542
- filters: {
543
- LT: {
544
- info: 'When chat is created before mentioned time (UTC)',
545
- },
546
- LTE: {
547
- info: 'When chat is created before mentioned time (UTC)',
548
- },
549
- GT: {
550
- info: 'When chat is created after mentioned time (UTC)',
551
- },
552
- GTE: {
553
- info: 'When chat is created on or after mentioned time (UTC)',
554
- },
555
- ON: {
556
- info: 'When chat is created on mentioned days',
557
- },
558
- },
559
- variable_type: 'day-time',
560
- },
561
- };
562
-
563
- export const TicketVariableNameMap: Record<
564
- keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>,
565
- VariableNameValueType
566
- > = {
567
- 'ticket.subject': {
568
- text: 'Ticket Subject',
569
- type: 'string',
570
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
571
- placeholder: 'e.g. Test ticket',
572
- variable_type: 'string',
573
- },
574
- 'ticket.status': {
575
- text: 'Ticket Status',
576
- type: 'dropdown',
577
- value: [
578
- { id: 'open', value: 'open', label: 'Open' },
579
- { id: 'closed', value: 'closed', label: 'Closed' },
580
- { id: 'inprogress', value: 'inprogress', label: 'In progress' },
581
- ],
582
- filters: ['EQ', 'NEQ'],
583
- variable_type: 'string',
584
- },
585
- 'ticket.priority': {
586
- text: 'Ticket Priority',
587
- type: 'dropdown',
588
- value: [
589
- { id: '0', value: '0', label: 'No Prioriy' },
590
- { id: '1', value: '1', label: 'Low' },
591
- { id: '2', value: '2', label: 'Medium' },
592
- { id: '3', value: '3', label: 'High' },
593
- { id: '4', value: '4', label: 'Urgent' },
594
- ],
595
- filters: ['EQ', 'NEQ'],
596
- variable_type: 'string',
597
- },
598
- 'ticket.assignee': {
599
- text: 'Ticket Assignee',
600
- type: 'dropdown',
601
- value: 'org.members',
602
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
603
- variable_type: 'string',
604
- },
605
- 'ticket.labels': {
606
- text: 'Ticket Labels',
607
- type: 'dropdown',
608
- value: 'org.labels',
609
- filters: ['CONTAINS', 'NCONTAINS'],
610
- variable_type: 'string',
611
- },
612
- 'ticket.is_deleted': {
613
- text: 'Ticket Is Deleted',
614
- type: 'boolean',
615
- value: [
616
- {
617
- id: 'true',
618
- value: 'true',
619
- label: 'True',
620
- },
621
- {
622
- id: 'false',
623
- value: 'false',
624
- label: 'False',
625
- },
626
- ],
627
- filters: ['IS'],
628
- variable_type: 'boolean',
629
- },
630
- 'ticket.raised_by': {
631
- text: 'Ticket Raised By',
632
- type: 'dropdown',
633
- value: 'org.members',
634
- filters: ['EQ', 'NEQ'],
635
- variable_type: 'string',
636
- },
637
- 'ticket.due_date': {
638
- text: 'Ticket Due Date',
639
- type: 'date',
640
- filters: ['KNOWN', 'NKNOWN'],
641
- variable_type: 'date',
642
- hidden: true,
643
- },
644
- 'ticket.ticket_id': {
645
- text: 'Ticket ID',
646
- type: 'string',
647
- filters: ['EQ', 'NEQ'],
648
- hidden: true,
649
- variable_type: 'string',
650
- },
651
- 'ticket.org_id': {
652
- text: 'Org ID',
653
- type: 'string',
654
- filters: ['EQ', 'NEQ'],
655
- hidden: true,
656
- variable_type: 'string',
657
- },
658
- 'ticket.custom_properties': {
659
- text: 'Ticket Custom Properties',
660
- type: 'dropdown',
661
- value: 'org.custom_properties',
662
- filters: ['EQ', 'NEQ'],
663
- hidden: true,
664
- variable_type: 'string',
665
- },
666
- 'ticket.created_at': {
667
- text: 'Ticket Created At',
668
- type: 'day-time',
669
- filters: {
670
- LT: {
671
- info: 'When ticket is created before mentioned time (UTC)',
672
- },
673
- LTE: {
674
- info: 'When ticket is created before mentioned time (UTC)',
675
- },
676
- GT: {
677
- info: 'When ticket is created after mentioned time (UTC)',
678
- },
679
- GTE: {
680
- info: 'When ticket is created on or after mentioned time (UTC)',
681
- },
682
- ON: {
683
- info: 'When ticket is created on mentioned days',
684
- },
685
- },
686
- variable_type: 'day-time',
687
- },
688
- 'ticket.chat_id': {
689
- text: 'Chat ID',
690
- type: 'string',
691
- filters: ['EQ', 'NEQ'],
692
- hidden: true,
693
- variable_type: 'string',
694
- },
695
- };
696
-
697
- export const ReactionVariableNameMap: Record<
698
- keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>,
699
- VariableNameValueType
700
- > = {
701
- 'reaction.reaction': {
702
- text: 'Reaction',
703
- type: 'string',
704
- filters: ['EQ', 'NEQ'],
705
- placeholder: 'e.g. 👍',
706
- variable_type: 'string',
707
- },
708
- 'reaction.sender_id': {
709
- text: 'Reaction Sender Phone',
710
- type: 'string',
711
- filters: ['EQ', 'NEQ'],
712
- placeholder: 'e.g. 919876543210',
713
- variable_type: 'string',
714
- },
715
- 'reaction.message_id': {
716
- text: 'Reaction Message ID',
717
- type: 'string',
718
- filters: ['EQ', 'NEQ'],
719
- hidden: true,
720
- variable_type: 'string',
721
- },
722
- 'reaction.chat_id': {
723
- text: 'Chat ID',
724
- type: 'string',
725
- filters: ['EQ', 'NEQ'],
726
- hidden: true,
727
- variable_type: 'string',
728
- },
729
- 'reaction.reaction_id': {
730
- text: 'Reaction ID',
731
- type: 'string',
732
- filters: ['EQ', 'NEQ'],
733
- hidden: true,
734
- variable_type: 'string',
735
- },
736
- };
737
-
738
- export enum FilterConditionMap {
739
- 'CONTAINS' = 'contains',
740
- 'NCONTAINS' = 'does not contain',
741
- 'EQ' = '=',
742
- 'NEQ' = '<>',
743
- 'LT' = '<',
744
- 'LTE' = '<=',
745
- 'GT' = '>',
746
- 'GTE' = '>=',
747
- 'KNOWN' = 'is known',
748
- 'NKNOWN' = 'is not known',
749
- 'IS' = '=',
750
- 'NIS' = '<>',
751
- 'ON' = 'on',
752
- }
753
-
754
- interface FilterGroup {
755
- filters: Filter[];
756
- condition: 'allOf' | 'anyOf';
757
- }
758
-
759
- export interface Conditions {
760
- filters: FilterGroup[];
761
- condition: 'allOf' | 'anyOf';
762
- variables: string[];
763
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
764
- org_phones: string[];
765
- }
766
-
767
- export type SendMessageAction = {
768
- id: string;
769
- type: 'send_message';
770
- metadata: {
771
- message: string;
772
- media?: {
773
- url: string;
774
- type: 'image' | 'video' | 'audio' | 'document';
775
- name: string;
776
- };
777
- maintain_flag_status: 'true' | 'false';
778
- debounce_messages: 'true' | 'false';
779
- debounce_message_time:
780
- | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
781
- | null
782
- | undefined;
783
- };
784
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
785
- };
786
-
787
- export type NotifyHttpAction = {
788
- id: string;
789
- type: 'notify_http';
790
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
791
- metadata: {
792
- url: string;
793
- };
794
- };
795
-
796
- export type CreateTicketAction = {
797
- id: string;
798
- type: 'create_ticket';
799
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
800
- metadata: {
801
- assignee?: string;
802
- priority?: '0' | '1' | '2' | '3' | '4';
803
- label?: string;
804
- };
805
- };
806
-
807
- export type FlagMessageAction = {
808
- id: string;
809
- type: 'flag_message';
810
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
811
- metadata: {
812
- flag: 'true' | 'false';
813
- };
814
- };
815
-
816
- export type AssignTicketAction = {
817
- id: string;
818
- type: 'assign_ticket';
819
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
820
- metadata: {
821
- assignee: string;
822
- round_robin: 'true' | 'false';
823
- };
824
- };
825
-
826
- export type CloseTicketAction = {
827
- id: string;
828
- type: 'close_ticket';
829
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
830
- metadata: {
831
- closing_note: string;
832
- };
833
- };
834
-
835
- export type AddChatLabelAction = {
836
- id: string;
837
- type: 'add_chat_label';
838
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
839
- metadata: {
840
- label: string;
841
- };
842
- };
843
-
844
- export type AddTicketLabelAction = {
845
- id: string;
846
- type: 'add_ticket_label';
847
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
848
- metadata: {
849
- label: string;
850
- };
851
- };
852
-
853
- export type AssignChatAction = {
854
- id: string;
855
- type: 'assign_chat';
856
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
857
- metadata: {
858
- assignee: string;
859
- round_robin: 'true' | 'false';
860
- };
861
- };
862
-
863
- export type ForwardMessageAction = {
864
- id: string;
865
- type: 'forward_message';
866
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
867
- metadata: {
868
- chat_id: string;
869
- prefix: string;
870
- };
871
- };
872
-
873
- export type SendEmailAction = {
874
- id: string;
875
- type: 'send_email';
876
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
877
- metadata: {
878
- email: string;
879
- subject: string;
880
- body: string;
881
- };
882
- };
883
-
884
- export type ReplyToMessageAction = {
885
- id: string;
886
- type: 'reply_to_message';
887
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
888
- metadata: {
889
- message: string;
890
- media?: {
891
- url: string;
892
- type: 'image' | 'video' | 'audio' | 'document';
893
- name: string;
894
- };
895
- maintain_flag_status: boolean;
896
- debounce_messages: 'true' | 'false';
897
- debounce_message_time:
898
- | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
899
- | null
900
- | undefined;
901
- };
902
- };
903
-
904
- export type UpdateCustomPropertyAction = {
905
- id: string;
906
- type: 'update_custom_property';
907
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
908
- metadata: {
909
- property_id: string;
910
- value: string;
911
- };
912
- };
913
-
914
- export type DeleteMessageAction = {
915
- id: string;
916
- type: 'delete_message';
917
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
918
- metadata: {};
919
- };
920
-
921
- export type Action =
922
- | SendMessageAction
923
- | NotifyHttpAction
924
- | CreateTicketAction
925
- | FlagMessageAction
926
- | AssignTicketAction
927
- | CloseTicketAction
928
- | AddChatLabelAction
929
- | AddTicketLabelAction
930
- | AssignChatAction
931
- | ForwardMessageAction
932
- | SendEmailAction
933
- | ReplyToMessageAction
934
- | UpdateCustomPropertyAction
935
- | DeleteMessageAction;
936
-
937
- export const isSendMessageOrReplyToMessageAction = (
938
- action: Action
939
- ): action is SendMessageAction | ReplyToMessageAction => {
940
- return ['send_message', 'reply_to_message'].includes(action.type);
941
- };
942
-
943
- export type Rule = OverrideProperties<
944
- Tables<'tbl_automation_rules'>,
945
- {
946
- actions: Action[];
947
- conditions: Conditions;
948
- trigger:
949
- | 'message.created'
950
- | 'message.updated'
951
- | 'chat.created'
952
- | 'ticket.updated'
953
- | 'ticket.created'
954
- | 'reaction.added'
955
- | 'chat.label.updated'
956
- | 'message.flagged';
957
- }
958
- >;
959
-
960
- export const RuleNameMap: Record<
961
- Rule['trigger'],
962
- {
963
- title: string;
964
- description: string;
965
- base_conditions: {
966
- org_phone: boolean;
967
- };
968
- }
969
- > = {
970
- 'message.created': {
971
- title: 'New Message Received',
972
- description: 'When a new message is received from an external contact',
973
- base_conditions: {
974
- org_phone: true,
975
- },
976
- },
977
- 'chat.created': {
978
- title: 'New Chat Created',
979
- description: 'When a new chat is created',
980
- base_conditions: {
981
- org_phone: true,
982
- },
983
- },
984
- 'ticket.created': {
985
- title: 'New Ticket Created',
986
- description: 'When a new ticket is created',
987
- base_conditions: {
988
- org_phone: false,
989
- },
990
- },
991
- 'reaction.added': {
992
- title: 'New Reaction Added',
993
- description: 'When a reaction is added on a message',
994
- base_conditions: {
995
- org_phone: true,
996
- },
997
- },
998
- 'message.updated': {
999
- title: 'Message Updated',
1000
- description: 'When a message is updated',
1001
- base_conditions: {
1002
- org_phone: true,
1003
- },
1004
- },
1005
- 'ticket.updated': {
1006
- title: 'Ticket Updated',
1007
- description: 'When a ticket is updated',
1008
- base_conditions: {
1009
- org_phone: false,
1010
- },
1011
- },
1012
- 'chat.label.updated': {
1013
- title: 'Chat Label Added/Removed',
1014
- description: 'When labels on chats are updated',
1015
- base_conditions: {
1016
- org_phone: false,
1017
- },
1018
- },
1019
- 'message.flagged': {
1020
- title: 'Message Flagged',
1021
- description: 'When a message is flagged',
1022
- base_conditions: {
1023
- org_phone: true,
1024
- },
1025
- },
1026
- };
1027
-
1028
- export const ActionNameMap: Record<
1029
- Action['type'],
1030
- {
1031
- title: string;
1032
- description: string;
1033
- inputs: Record<
1034
- string,
1035
- {
1036
- id: string;
1037
- type:
1038
- | 'text'
1039
- | 'dropdown'
1040
- | 'editor'
1041
- | 'date'
1042
- | 'file'
1043
- | 'textarea'
1044
- | 'dynamic';
1045
- value:
1046
- | 'ticket.labels'
1047
- | 'org.members'
1048
- | 'chat.labels'
1049
- | 'org.chats'
1050
- | {
1051
- id: string;
1052
- value: string;
1053
- label: string;
1054
- }[]
1055
- | null
1056
- | 'org.custom_properties'
1057
- | 'custom_property_values'
1058
- | 'debounce_messages';
1059
- label: string;
1060
- placeholder: string;
1061
- info?: string;
1062
- required: boolean;
1063
- }
1064
- >;
1065
- validTriggers: Rule['trigger'][];
1066
- }
1067
- > = {
1068
- send_message: {
1069
- title: 'Send Message',
1070
- description: 'Send a message',
1071
- inputs: {
1072
- message: {
1073
- id: 'message',
1074
- type: 'editor',
1075
- label: 'Message',
1076
- placeholder: 'Enter message',
1077
- value: null,
1078
- required: true,
1079
- },
1080
- media: {
1081
- id: 'media',
1082
- type: 'file',
1083
- label: 'Media',
1084
- placeholder: 'Upload media',
1085
- value: null,
1086
- required: false,
1087
- },
1088
- maintain_flag_status: {
1089
- id: 'maintain_flag_status',
1090
- type: 'dropdown',
1091
- label: 'Maintain Flag Status',
1092
- placeholder: 'Select...',
1093
- value: [
1094
- { id: 'true', value: 'true', label: 'True' },
1095
- { id: 'false', value: 'false', label: 'False' },
1096
- ],
1097
- required: true,
1098
- },
1099
- debounce_messages: {
1100
- id: 'debounce_messages',
1101
- type: 'dropdown',
1102
- label: 'Debounce Messages',
1103
- placeholder: 'Select...',
1104
- value: [
1105
- { id: 'true', value: 'true', label: 'True' },
1106
- { id: 'false', value: 'false', label: 'False' },
1107
- ],
1108
- required: false,
1109
- },
1110
- debounce_message_time: {
1111
- id: 'debounce_message_time',
1112
- type: 'dynamic',
1113
- label: 'Debounce Messages Time',
1114
- placeholder: 'Enter time',
1115
- value: 'debounce_messages',
1116
- required: false,
1117
- },
1118
- },
1119
- validTriggers: [
1120
- 'message.created',
1121
- 'message.updated',
1122
- 'chat.created',
1123
- 'ticket.updated',
1124
- 'ticket.created',
1125
- 'reaction.added',
1126
- 'message.flagged',
1127
- 'chat.label.updated',
1128
- ],
1129
- },
1130
- reply_to_message: {
1131
- title: 'Reply to message',
1132
- description: 'Send a message with the quoted message',
1133
- inputs: {
1134
- message: {
1135
- id: 'message',
1136
- type: 'editor',
1137
- label: 'Message',
1138
- placeholder: 'Enter message',
1139
- value: null,
1140
- required: true,
1141
- },
1142
- media: {
1143
- id: 'media',
1144
- type: 'file',
1145
- label: 'Media',
1146
- placeholder: 'Upload media',
1147
- value: null,
1148
- required: false,
1149
- },
1150
- maintain_flag_status: {
1151
- id: 'maintain_flag_status',
1152
- type: 'dropdown',
1153
- label: 'Maintain Flag Status',
1154
- placeholder: 'Select...',
1155
- value: [
1156
- { id: 'true', value: 'true', label: 'True' },
1157
- { id: 'false', value: 'false', label: 'False' },
1158
- ],
1159
- required: true,
1160
- },
1161
- debounce_messages: {
1162
- id: 'debounce_messages',
1163
- type: 'dropdown',
1164
- label: 'Debounce Messages',
1165
- placeholder: 'Select...',
1166
- value: [
1167
- { id: 'true', value: 'true', label: 'True' },
1168
- { id: 'false', value: 'false', label: 'False' },
1169
- ],
1170
- required: false,
1171
- },
1172
- debounce_message_time: {
1173
- id: 'debounce_message_time',
1174
- type: 'dynamic',
1175
- label: 'Debounce Messages Time',
1176
- placeholder: 'Enter time',
1177
- value: 'debounce_messages',
1178
- required: false,
1179
- },
1180
- },
1181
- validTriggers: [
1182
- 'message.created',
1183
- 'message.updated',
1184
- 'reaction.added',
1185
- 'message.flagged',
1186
- ],
1187
- },
1188
- delete_message: {
1189
- title: 'Delete Message',
1190
- description: 'Delete a message',
1191
- inputs: {},
1192
- validTriggers: [
1193
- 'message.created',
1194
- 'message.updated',
1195
- 'reaction.added',
1196
- 'message.flagged',
1197
- ],
1198
- },
1199
- notify_http: {
1200
- title: 'Notify HTTP',
1201
- description: 'Notify an HTTP endpoint',
1202
- inputs: {
1203
- url: {
1204
- id: 'url',
1205
- type: 'text',
1206
- label: 'URL',
1207
- placeholder: 'Enter URL',
1208
- value: null,
1209
- required: true,
1210
- },
1211
- },
1212
- validTriggers: [
1213
- 'message.created',
1214
- 'message.updated',
1215
- 'chat.created',
1216
- 'ticket.updated',
1217
- 'ticket.created',
1218
- 'reaction.added',
1219
- 'message.flagged',
1220
- 'chat.label.updated',
1221
- ],
1222
- },
1223
- create_ticket: {
1224
- title: 'Create Ticket',
1225
- description: 'Create a ticket',
1226
- inputs: {
1227
- assignee: {
1228
- id: 'assignee',
1229
- type: 'dropdown',
1230
- value: 'org.members',
1231
- label: 'Assignee',
1232
- placeholder: 'Select assignee',
1233
- required: false,
1234
- },
1235
- priority: {
1236
- id: 'priority',
1237
- type: 'dropdown',
1238
- value: [
1239
- { id: '0', value: '0', label: 'No Prioriy' },
1240
- { id: '1', value: '1', label: 'Low' },
1241
- { id: '2', value: '2', label: 'Medium' },
1242
- { id: '3', value: '3', label: 'High' },
1243
- { id: '4', value: '4', label: 'Urgent' },
1244
- ],
1245
- label: 'Priority',
1246
- placeholder: 'Select priority',
1247
- required: false,
1248
- },
1249
- label: {
1250
- id: 'label',
1251
- type: 'dropdown',
1252
- value: 'ticket.labels',
1253
- label: 'Label',
1254
- placeholder: 'Select label',
1255
- required: false,
1256
- },
1257
- },
1258
- validTriggers: [
1259
- 'message.created',
1260
- 'message.updated',
1261
- 'reaction.added',
1262
- 'message.flagged',
1263
- ],
1264
- },
1265
- flag_message: {
1266
- title: 'Update flag status',
1267
- description: 'Flag/Unflag a message',
1268
- inputs: {
1269
- flag: {
1270
- id: 'flag',
1271
- type: 'dropdown',
1272
- value: [
1273
- { id: 'flag', value: 'true', label: 'TRUE' },
1274
- { id: 'unflag', value: 'false', label: 'FALSE' },
1275
- ],
1276
- label: 'Flag status',
1277
- placeholder: 'Select flag',
1278
- required: true,
1279
- },
1280
- },
1281
- validTriggers: [
1282
- 'message.created',
1283
- 'message.updated',
1284
- 'reaction.added',
1285
- 'message.flagged',
1286
- ],
1287
- },
1288
- assign_ticket: {
1289
- title: 'Assign Ticket',
1290
- description: 'Assign a ticket',
1291
- inputs: {
1292
- round_robin: {
1293
- id: 'round_robin',
1294
- type: 'dropdown',
1295
- value: [
1296
- { id: 'true', value: 'true', label: 'True' },
1297
- { id: 'false', value: 'false', label: 'False' },
1298
- ],
1299
- label: 'Enable Round Robin',
1300
- placeholder: 'Select...',
1301
- info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1302
- required: false,
1303
- },
1304
- assignee: {
1305
- id: 'assignee',
1306
- type: 'dynamic',
1307
- value: 'org.members',
1308
- label: 'Assignee',
1309
- placeholder: 'Select assignee',
1310
- 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",
1311
- required: true,
1312
- },
1313
- },
1314
- validTriggers: ['ticket.updated', 'ticket.created'],
1315
- },
1316
- close_ticket: {
1317
- title: 'Close Ticket',
1318
- description: 'Close a ticket',
1319
- inputs: {
1320
- closing_note: {
1321
- id: 'closing_note',
1322
- type: 'textarea',
1323
- label: 'Closing Note',
1324
- placeholder: 'Enter closing note',
1325
- value: null,
1326
- required: false,
1327
- },
1328
- },
1329
- validTriggers: ['ticket.updated', 'ticket.created'],
1330
- },
1331
- add_chat_label: {
1332
- title: 'Add Chat Label',
1333
- description: 'Add a label to referred chat',
1334
- inputs: {
1335
- label: {
1336
- id: 'label',
1337
- type: 'dropdown',
1338
- value: 'chat.labels',
1339
- label: 'Label',
1340
- placeholder: 'Select label',
1341
- required: true,
1342
- },
1343
- },
1344
- validTriggers: [
1345
- 'message.created',
1346
- 'message.updated',
1347
- 'chat.created',
1348
- 'ticket.updated',
1349
- 'ticket.created',
1350
- 'reaction.added',
1351
- 'chat.label.updated',
1352
- 'message.flagged',
1353
- ],
1354
- },
1355
- add_ticket_label: {
1356
- title: 'Add Ticket Label',
1357
- description: 'Add a label to referred ticket',
1358
- inputs: {
1359
- label: {
1360
- id: 'label',
1361
- type: 'dropdown',
1362
- value: 'ticket.labels',
1363
- label: 'Label',
1364
- placeholder: 'Select label',
1365
- required: true,
1366
- },
1367
- },
1368
- validTriggers: ['ticket.updated', 'ticket.created'],
1369
- },
1370
- update_custom_property: {
1371
- description: 'Update a chat custom property',
1372
- title: 'Update Chat Custom Property',
1373
- validTriggers: [
1374
- 'message.created',
1375
- 'message.updated',
1376
- 'chat.created',
1377
- 'ticket.updated',
1378
- 'ticket.created',
1379
- 'reaction.added',
1380
- 'message.flagged',
1381
- 'chat.label.updated',
1382
- ],
1383
- inputs: {
1384
- property_id: {
1385
- id: 'property_id',
1386
- type: 'dropdown',
1387
- value: 'org.custom_properties',
1388
- label: 'Property',
1389
- placeholder: 'Select property',
1390
- required: true,
1391
- },
1392
- value: {
1393
- id: 'property_id',
1394
- type: 'dynamic',
1395
- label: 'Value',
1396
- placeholder: 'Enter value',
1397
- value: 'custom_property_values',
1398
- required: true,
1399
- },
1400
- },
1401
- },
1402
- assign_chat: {
1403
- title: 'Assign Chat',
1404
- description: 'Assign a chat',
1405
- inputs: {
1406
- round_robin: {
1407
- id: 'round_robin',
1408
- type: 'dropdown',
1409
- value: [
1410
- { id: 'true', value: 'true', label: 'True' },
1411
- { id: 'false', value: 'false', label: 'False' },
1412
- ],
1413
- label: 'Enable Round Robin',
1414
- placeholder: 'Select...',
1415
- info: 'If enabled, the chat will be assigned to the next available agent in the list',
1416
- required: false,
1417
- },
1418
- assignee: {
1419
- id: 'assignee',
1420
- type: 'dynamic',
1421
- value: 'org.members',
1422
- label: 'Assignee',
1423
- placeholder: 'Select assignee',
1424
- required: true,
1425
- },
1426
- },
1427
- validTriggers: [
1428
- 'message.created',
1429
- 'message.updated',
1430
- 'chat.created',
1431
- 'ticket.updated',
1432
- 'ticket.created',
1433
- 'reaction.added',
1434
- 'chat.label.updated',
1435
- 'message.flagged',
1436
- ],
1437
- },
1438
- forward_message: {
1439
- title: 'Forward Message',
1440
- description: 'Forward a message',
1441
- inputs: {
1442
- chat_id: {
1443
- id: 'chat_id',
1444
- type: 'dropdown',
1445
- value: 'org.chats',
1446
- label: 'Chat',
1447
- placeholder: 'Select chat',
1448
- required: true,
1449
- },
1450
- },
1451
- validTriggers: [
1452
- 'message.created',
1453
- 'message.updated',
1454
- 'ticket.updated',
1455
- 'ticket.created',
1456
- 'reaction.added',
1457
- 'message.flagged',
1458
- ],
1459
- },
1460
- send_email: {
1461
- title: 'Send Email',
1462
- description: 'Send an email',
1463
- inputs: {
1464
- email: {
1465
- id: 'email',
1466
- type: 'text',
1467
- label: 'Email',
1468
- placeholder: 'Enter email',
1469
- value: null,
1470
- required: true,
1471
- },
1472
- subject: {
1473
- id: 'subject',
1474
- type: 'editor',
1475
- label: 'Subject',
1476
- placeholder: 'Enter subject',
1477
- value: null,
1478
- required: true,
1479
- },
1480
- body: {
1481
- id: 'body',
1482
- type: 'editor',
1483
- label: 'Body',
1484
- placeholder: 'Enter body',
1485
- value: null,
1486
- required: true,
1487
- },
1488
- },
1489
- validTriggers: [
1490
- 'message.created',
1491
- 'message.updated',
1492
- 'chat.created',
1493
- 'ticket.updated',
1494
- 'ticket.created',
1495
- 'reaction.added',
1496
- 'message.flagged',
1497
- 'chat.label.updated',
1498
- ],
1499
- },
1500
- };
1501
-
1502
- export const editorVariables: Array<{
1503
- label: string;
1504
- value: string;
1505
- validTriggers: Rule['trigger'][];
1506
- }> = [
1507
- {
1508
- label: 'Message Body',
1509
- value: 'message.body',
1510
- validTriggers: [
1511
- 'message.created',
1512
- 'message.updated',
1513
- 'reaction.added',
1514
- 'message.flagged',
1515
- 'ticket.created',
1516
- 'ticket.updated',
1517
- ],
1518
- },
1519
- {
1520
- label: 'Sender Name',
1521
- value: 'sender.contact_name',
1522
- validTriggers: [
1523
- 'message.created',
1524
- 'message.updated',
1525
- 'reaction.added',
1526
- 'message.flagged',
1527
- 'ticket.created',
1528
- 'ticket.updated',
1529
- ],
1530
- },
1531
- {
1532
- label: 'Chat Name',
1533
- value: 'chat.chat_name',
1534
- validTriggers: [
1535
- 'message.created',
1536
- 'message.updated',
1537
- 'reaction.added',
1538
- 'message.flagged',
1539
- 'chat.created',
1540
- 'chat.label.updated',
1541
- 'ticket.created',
1542
- 'ticket.updated',
1543
- ],
1544
- },
1545
- {
1546
- label: 'Ticket ID',
1547
- value: 'ticket.ticket_id',
1548
- validTriggers: ['ticket.updated', 'ticket.created'],
1549
- },
1550
- {
1551
- label: 'Chat ID',
1552
- value: 'chat.chat_id',
1553
- validTriggers: [
1554
- 'message.created',
1555
- 'message.updated',
1556
- 'reaction.added',
1557
- 'message.flagged',
1558
- 'chat.created',
1559
- 'chat.label.updated',
1560
- 'ticket.created',
1561
- 'ticket.updated',
1562
- ],
1563
- },
1564
- {
1565
- label: 'Reaction',
1566
- value: 'reaction.reaction',
1567
- validTriggers: ['reaction.added'],
1568
- },
1569
- ];
1570
-
1571
- export const variablesExclusionList: Record<
1572
- Rule['trigger'],
1573
- Array<
1574
- | keyof AppendTypes<{ message: MessageVariablesType }, '.'>
1575
- | keyof AppendTypes<{ sender: SenderVariablesType }, '.'>
1576
- | keyof AppendTypes<{ chat: ChatVariablesType }, '.'>
1577
- | keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>
1578
- | keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>
1579
- >
1580
- > = {
1581
- 'ticket.created': ['ticket.is_deleted'],
1582
- 'chat.created': [
1583
- 'chat.chat_id',
1584
- 'chat.labels',
1585
- 'chat.has_flagged_messages',
1586
- 'chat.assigned_to',
1587
- ],
1588
- 'message.created': [
1589
- 'message.author',
1590
- 'message.performed_by',
1591
- 'message.flag_status',
1592
- 'sender.is_internal',
1593
- ],
1594
- 'ticket.updated': ['ticket.is_deleted'],
1595
- 'reaction.added': [],
1596
- 'message.updated': [],
1597
- 'message.flagged': [],
1598
- 'chat.label.updated': [],
1599
- };
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'}`;
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'}`;
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'; // Add other condition types as needed
115
+ variable: string;
116
+ value: string | string[];
117
+ variable_type?: 'string' | 'number' | 'boolean' | 'day-time' | 'date' | 'day'; // Optional, like 'Date'
118
+ }
119
+
120
+ export const isFilter = (filter: any): filter is Filter => {
121
+ return (
122
+ typeof filter === 'object' &&
123
+ 'id' in filter &&
124
+ 'condition' in filter &&
125
+ 'variable' in filter &&
126
+ 'value' in filter
127
+ );
128
+ };
129
+
130
+ export const FilterNameMap: Record<
131
+ Filter['condition'],
132
+ {
133
+ name: string;
134
+ input: boolean;
135
+ }
136
+ > = {
137
+ EQ: {
138
+ name: 'equals to',
139
+ input: true,
140
+ },
141
+ NEQ: {
142
+ name: 'not equals to',
143
+ input: true,
144
+ },
145
+ CONTAINS: {
146
+ name: 'contains',
147
+ input: true,
148
+ },
149
+ NCONTAINS: {
150
+ name: 'does not contain',
151
+ input: true,
152
+ },
153
+ LT: {
154
+ name: 'less than',
155
+ input: true,
156
+ },
157
+ LTE: {
158
+ name: 'less than or equals to',
159
+ input: true,
160
+ },
161
+ GT: {
162
+ name: 'greater than',
163
+ input: true,
164
+ },
165
+ GTE: {
166
+ name: 'greater than or equals to',
167
+ input: true,
168
+ },
169
+ KNOWN: {
170
+ name: 'is known',
171
+ input: false,
172
+ },
173
+ NKNOWN: {
174
+ name: 'is not known',
175
+ input: false,
176
+ },
177
+ IS: {
178
+ name: 'is',
179
+ input: true,
180
+ },
181
+ NIS: {
182
+ name: 'is not',
183
+ input: true,
184
+ },
185
+ ON: {
186
+ name: 'on',
187
+ input: true,
188
+ },
189
+ };
190
+
191
+ export type VariableNameValueType = {
192
+ text: string;
193
+ type:
194
+ | 'string'
195
+ | 'time'
196
+ | 'boolean'
197
+ | 'dropdown'
198
+ | 'day-time'
199
+ | 'number'
200
+ | 'date';
201
+ variable_type: 'string' | 'number' | 'boolean' | 'day-time' | 'date';
202
+ value?:
203
+ | string
204
+ | {
205
+ id: string;
206
+ value: string | number | boolean;
207
+ label: string;
208
+ }[]
209
+ | null;
210
+ filters:
211
+ | Partial<
212
+ Record<
213
+ Filter['condition'],
214
+ {
215
+ info?: string;
216
+ }
217
+ >
218
+ >
219
+ | Filter['condition'][];
220
+ hidden?: boolean;
221
+ placeholder?: string;
222
+ info?: string;
223
+ };
224
+
225
+ export const MessageVariableNameMap: Record<
226
+ keyof AppendTypes<{ message: MessageVariablesType }, '.'>,
227
+ VariableNameValueType
228
+ > = {
229
+ 'message.body': {
230
+ text: 'Message Body',
231
+ type: 'string',
232
+ filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
233
+ placeholder: 'e.g. Test message',
234
+ variable_type: 'string',
235
+ },
236
+ 'message.sender_phone': {
237
+ text: 'Message Sender Phone',
238
+ type: 'string',
239
+ filters: ['EQ', 'NEQ'],
240
+ placeholder: 'e.g. 919876543210',
241
+ variable_type: 'string',
242
+ },
243
+ 'message.timestamp': {
244
+ text: 'Message Timestamp',
245
+ type: 'day-time',
246
+ filters: {
247
+ LT: {
248
+ info: 'When message is received before mentioned time (UTC)',
249
+ },
250
+ LTE: {
251
+ info: 'When message is received before mentioned time (UTC)',
252
+ },
253
+ GT: {
254
+ info: 'When message is received after mentioned time (UTC)',
255
+ },
256
+ GTE: {
257
+ info: 'When message is received on or after mentioned time (UTC)',
258
+ },
259
+ ON: {
260
+ info: 'When message is received on mentioned days',
261
+ },
262
+ },
263
+ variable_type: 'day-time',
264
+ info: 'The timestamp when the message was received',
265
+ },
266
+ 'message.flag_status': {
267
+ text: 'Message Flag Status',
268
+ filters: ['IS'],
269
+ type: 'boolean',
270
+ variable_type: 'boolean',
271
+ },
272
+ 'message.has_quoted_msg': {
273
+ text: 'Has Quoted Message',
274
+ filters: ['IS'],
275
+ type: 'boolean',
276
+ variable_type: 'boolean',
277
+ },
278
+ 'message.media': {
279
+ text: 'Has Media',
280
+ type: 'boolean',
281
+ filters: ['KNOWN', 'NKNOWN'],
282
+ variable_type: 'boolean',
283
+ },
284
+ 'message.performed_by': {
285
+ text: 'Message Sent By (email)',
286
+ type: 'dropdown',
287
+ value: 'org.members',
288
+ filters: ['EQ', 'NEQ'],
289
+ variable_type: 'string',
290
+ },
291
+ 'message.chat_id': {
292
+ text: 'Chat ID',
293
+ type: 'string',
294
+ filters: ['EQ', 'NEQ'],
295
+ hidden: true,
296
+ variable_type: 'string',
297
+ },
298
+ 'message.message_id': {
299
+ text: 'Message ID',
300
+ type: 'string',
301
+ filters: ['EQ', 'NEQ'],
302
+ hidden: true,
303
+ variable_type: 'string',
304
+ },
305
+ 'message.org_phone': {
306
+ text: 'Org Phone',
307
+ type: 'string',
308
+ filters: ['EQ', 'NEQ'],
309
+ hidden: true,
310
+ variable_type: 'string',
311
+ },
312
+ 'message.org_id': {
313
+ text: 'Org ID',
314
+ type: 'string',
315
+ filters: ['EQ', 'NEQ'],
316
+ hidden: true,
317
+ variable_type: 'string',
318
+ },
319
+ 'message.message_type': {
320
+ text: 'Message Type',
321
+ type: 'dropdown',
322
+ value: [
323
+ { id: 'text', value: 'chat', label: 'Text' },
324
+ { id: 'image', value: 'image', label: 'Image' },
325
+ { id: 'video', value: 'video', label: 'Video' },
326
+ { id: 'audio', value: 'audio', label: 'Audio' },
327
+ { id: 'audio', value: 'ptt', label: 'PTT (Audio voice message)' },
328
+ { id: 'document', value: 'document', label: 'Document' },
329
+ ],
330
+ filters: ['EQ', 'NEQ'],
331
+ variable_type: 'string',
332
+ },
333
+ 'message.author': {
334
+ text: 'Message Author',
335
+ type: 'string',
336
+ filters: ['EQ', 'NEQ'],
337
+ hidden: true,
338
+ variable_type: 'string',
339
+ },
340
+ };
341
+
342
+ export const SenderVariableNameMap: Record<
343
+ keyof AppendTypes<{ sender: SenderVariablesType }, '.'>,
344
+ VariableNameValueType
345
+ > = {
346
+ 'sender.is_internal': {
347
+ text: 'Sender Is Internal',
348
+ type: 'boolean',
349
+ filters: ['IS'],
350
+ variable_type: 'boolean',
351
+ },
352
+ 'sender.contact_name': {
353
+ text: 'Sender Name',
354
+ type: 'string',
355
+ filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
356
+ placeholder: 'e.g. John Doe',
357
+ variable_type: 'string',
358
+ },
359
+ 'sender.contact_id': {
360
+ text: 'Sender Phone',
361
+ type: 'string',
362
+ filters: ['EQ', 'NEQ'],
363
+ placeholder: 'e.g. 919876543210',
364
+ variable_type: 'string',
365
+ },
366
+ 'sender.labels': {
367
+ text: 'Sender Contact Labels',
368
+ type: 'dropdown',
369
+ value: 'org.labels',
370
+ filters: ['CONTAINS', 'NCONTAINS'],
371
+ variable_type: 'string',
372
+ },
373
+ 'sender.org_id': {
374
+ text: 'Org ID',
375
+ type: 'string',
376
+ filters: ['EQ', 'NEQ'],
377
+ hidden: true,
378
+ variable_type: 'string',
379
+ },
380
+ 'sender.is_admin': {
381
+ text: 'Sender Is Admin',
382
+ type: 'dropdown',
383
+ filters: ['EQ', 'NEQ'],
384
+ value: [
385
+ {
386
+ id: 'true',
387
+ value: 'true',
388
+ label: 'True',
389
+ },
390
+ {
391
+ id: 'false',
392
+ value: 'false',
393
+ label: 'False',
394
+ },
395
+ ],
396
+ variable_type: 'boolean',
397
+ },
398
+ };
399
+
400
+ export const ChatVariableNameMap: Record<
401
+ keyof AppendTypes<{ chat: ChatVariablesType }, '.'>,
402
+ VariableNameValueType
403
+ > = {
404
+ 'chat.assigned_to': {
405
+ text: 'Chat Assignee',
406
+ type: 'dropdown',
407
+ value: 'org.members',
408
+ filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
409
+ variable_type: 'string',
410
+ },
411
+ 'chat.chat_name': {
412
+ text: 'Chat Name',
413
+ type: 'string',
414
+ filters: ['EQ', 'NEQ', 'CONTAINS', 'NCONTAINS'],
415
+ placeholder: 'e.g. Support Chat',
416
+ variable_type: 'string',
417
+ },
418
+ 'chat.org_phone': {
419
+ text: 'Chat Org Phone',
420
+ type: 'dropdown',
421
+ value: 'org.org_phones',
422
+ filters: ['EQ', 'NEQ'],
423
+ variable_type: 'string',
424
+ },
425
+ 'chat.chat_type': {
426
+ text: 'Chat Type',
427
+ type: 'dropdown',
428
+ value: [
429
+ { id: 'user', value: 'user', label: 'User' },
430
+ { id: 'group', value: 'group', label: 'Group' },
431
+ ],
432
+ filters: ['EQ', 'NEQ'],
433
+ variable_type: 'string',
434
+ },
435
+ 'chat.members': {
436
+ text: 'Chat Members',
437
+ type: 'string',
438
+ filters: ['CONTAINS', 'NCONTAINS'],
439
+ placeholder: 'e.g. 919876543210',
440
+ variable_type: 'string',
441
+ },
442
+ 'chat.labels': {
443
+ text: 'Chat Labels',
444
+ type: 'dropdown',
445
+ value: 'org.labels',
446
+ filters: ['CONTAINS', 'NCONTAINS'],
447
+ variable_type: 'string',
448
+ },
449
+ 'chat.chat_id': {
450
+ text: 'Chat ID',
451
+ type: 'string',
452
+ filters: ['EQ', 'NEQ'],
453
+ placeholder: 'e.g. 12027747916749@c.us',
454
+ variable_type: 'string',
455
+ },
456
+ 'chat.chat_org_phones': {
457
+ text: 'Chat Org Phones',
458
+ type: 'dropdown',
459
+ filters: ['CONTAINS', 'NCONTAINS'],
460
+ hidden: true,
461
+ variable_type: 'string',
462
+ },
463
+ 'chat.org_id': {
464
+ text: 'Org ID',
465
+ type: 'string',
466
+ filters: [],
467
+ hidden: true,
468
+ variable_type: 'string',
469
+ },
470
+ 'chat.messages_admins_only': {
471
+ text: 'Messages Admins Only (Chat Settings)',
472
+ type: 'boolean',
473
+ filters: ['EQ', 'NEQ'],
474
+ value: [
475
+ {
476
+ id: 'true',
477
+ value: 'true',
478
+ label: 'True',
479
+ },
480
+ {
481
+ id: 'false',
482
+ value: 'false',
483
+ label: 'False',
484
+ },
485
+ ],
486
+ variable_type: 'boolean',
487
+ },
488
+ 'chat.info_admins_only': {
489
+ text: 'Info 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.has_flagged_messages': {
507
+ text: 'Chat Has Flagged Messages',
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.group_description': {
525
+ text: 'Group Description',
526
+ type: 'string',
527
+ filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
528
+ placeholder: 'e.g. Group description',
529
+ variable_type: 'string',
530
+ },
531
+ 'chat.custom_properties': {
532
+ text: 'Chat Custom Properties',
533
+ type: 'dropdown',
534
+ value: 'org.custom_properties',
535
+ filters: ['EQ', 'NEQ'],
536
+ hidden: true,
537
+ variable_type: 'string',
538
+ },
539
+ 'chat.created_at': {
540
+ text: 'Chat Created At',
541
+ type: 'day-time',
542
+ filters: {
543
+ LT: {
544
+ info: 'When chat is created before mentioned time (UTC)',
545
+ },
546
+ LTE: {
547
+ info: 'When chat is created before mentioned time (UTC)',
548
+ },
549
+ GT: {
550
+ info: 'When chat is created after mentioned time (UTC)',
551
+ },
552
+ GTE: {
553
+ info: 'When chat is created on or after mentioned time (UTC)',
554
+ },
555
+ ON: {
556
+ info: 'When chat is created on mentioned days',
557
+ },
558
+ },
559
+ variable_type: 'day-time',
560
+ },
561
+ };
562
+
563
+ export const TicketVariableNameMap: Record<
564
+ keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>,
565
+ VariableNameValueType
566
+ > = {
567
+ 'ticket.subject': {
568
+ text: 'Ticket Subject',
569
+ type: 'string',
570
+ filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
571
+ placeholder: 'e.g. Test ticket',
572
+ variable_type: 'string',
573
+ },
574
+ 'ticket.status': {
575
+ text: 'Ticket Status',
576
+ type: 'dropdown',
577
+ value: [
578
+ { id: 'open', value: 'open', label: 'Open' },
579
+ { id: 'closed', value: 'closed', label: 'Closed' },
580
+ { id: 'inprogress', value: 'inprogress', label: 'In progress' },
581
+ ],
582
+ filters: ['EQ', 'NEQ'],
583
+ variable_type: 'string',
584
+ },
585
+ 'ticket.priority': {
586
+ text: 'Ticket Priority',
587
+ type: 'dropdown',
588
+ value: [
589
+ { id: '0', value: '0', label: 'No Prioriy' },
590
+ { id: '1', value: '1', label: 'Low' },
591
+ { id: '2', value: '2', label: 'Medium' },
592
+ { id: '3', value: '3', label: 'High' },
593
+ { id: '4', value: '4', label: 'Urgent' },
594
+ ],
595
+ filters: ['EQ', 'NEQ'],
596
+ variable_type: 'string',
597
+ },
598
+ 'ticket.assignee': {
599
+ text: 'Ticket Assignee',
600
+ type: 'dropdown',
601
+ value: 'org.members',
602
+ filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
603
+ variable_type: 'string',
604
+ },
605
+ 'ticket.labels': {
606
+ text: 'Ticket Labels',
607
+ type: 'dropdown',
608
+ value: 'org.labels',
609
+ filters: ['CONTAINS', 'NCONTAINS'],
610
+ variable_type: 'string',
611
+ },
612
+ 'ticket.is_deleted': {
613
+ text: 'Ticket Is Deleted',
614
+ type: 'boolean',
615
+ value: [
616
+ {
617
+ id: 'true',
618
+ value: 'true',
619
+ label: 'True',
620
+ },
621
+ {
622
+ id: 'false',
623
+ value: 'false',
624
+ label: 'False',
625
+ },
626
+ ],
627
+ filters: ['IS'],
628
+ variable_type: 'boolean',
629
+ },
630
+ 'ticket.raised_by': {
631
+ text: 'Ticket Raised By',
632
+ type: 'dropdown',
633
+ value: 'org.members',
634
+ filters: ['EQ', 'NEQ'],
635
+ variable_type: 'string',
636
+ },
637
+ 'ticket.due_date': {
638
+ text: 'Ticket Due Date',
639
+ type: 'date',
640
+ filters: ['KNOWN', 'NKNOWN'],
641
+ variable_type: 'date',
642
+ hidden: true,
643
+ },
644
+ 'ticket.ticket_id': {
645
+ text: 'Ticket ID',
646
+ type: 'string',
647
+ filters: ['EQ', 'NEQ'],
648
+ hidden: true,
649
+ variable_type: 'string',
650
+ },
651
+ 'ticket.org_id': {
652
+ text: 'Org ID',
653
+ type: 'string',
654
+ filters: ['EQ', 'NEQ'],
655
+ hidden: true,
656
+ variable_type: 'string',
657
+ },
658
+ 'ticket.custom_properties': {
659
+ text: 'Ticket Custom Properties',
660
+ type: 'dropdown',
661
+ value: 'org.custom_properties',
662
+ filters: ['EQ', 'NEQ'],
663
+ hidden: true,
664
+ variable_type: 'string',
665
+ },
666
+ 'ticket.created_at': {
667
+ text: 'Ticket Created At',
668
+ type: 'day-time',
669
+ filters: {
670
+ LT: {
671
+ info: 'When ticket is created before mentioned time (UTC)',
672
+ },
673
+ LTE: {
674
+ info: 'When ticket is created before mentioned time (UTC)',
675
+ },
676
+ GT: {
677
+ info: 'When ticket is created after mentioned time (UTC)',
678
+ },
679
+ GTE: {
680
+ info: 'When ticket is created on or after mentioned time (UTC)',
681
+ },
682
+ ON: {
683
+ info: 'When ticket is created on mentioned days',
684
+ },
685
+ },
686
+ variable_type: 'day-time',
687
+ },
688
+ 'ticket.chat_id': {
689
+ text: 'Chat ID',
690
+ type: 'string',
691
+ filters: ['EQ', 'NEQ'],
692
+ hidden: true,
693
+ variable_type: 'string',
694
+ },
695
+ };
696
+
697
+ export const ReactionVariableNameMap: Record<
698
+ keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>,
699
+ VariableNameValueType
700
+ > = {
701
+ 'reaction.reaction': {
702
+ text: 'Reaction',
703
+ type: 'string',
704
+ filters: ['EQ', 'NEQ'],
705
+ placeholder: 'e.g. 👍',
706
+ variable_type: 'string',
707
+ },
708
+ 'reaction.sender_id': {
709
+ text: 'Reaction Sender Phone',
710
+ type: 'string',
711
+ filters: ['EQ', 'NEQ'],
712
+ placeholder: 'e.g. 919876543210',
713
+ variable_type: 'string',
714
+ },
715
+ 'reaction.message_id': {
716
+ text: 'Reaction Message ID',
717
+ type: 'string',
718
+ filters: ['EQ', 'NEQ'],
719
+ hidden: true,
720
+ variable_type: 'string',
721
+ },
722
+ 'reaction.chat_id': {
723
+ text: 'Chat ID',
724
+ type: 'string',
725
+ filters: ['EQ', 'NEQ'],
726
+ hidden: true,
727
+ variable_type: 'string',
728
+ },
729
+ 'reaction.reaction_id': {
730
+ text: 'Reaction ID',
731
+ type: 'string',
732
+ filters: ['EQ', 'NEQ'],
733
+ hidden: true,
734
+ variable_type: 'string',
735
+ },
736
+ };
737
+
738
+ export enum FilterConditionMap {
739
+ 'CONTAINS' = 'contains',
740
+ 'NCONTAINS' = 'does not contain',
741
+ 'EQ' = '=',
742
+ 'NEQ' = '<>',
743
+ 'LT' = '<',
744
+ 'LTE' = '<=',
745
+ 'GT' = '>',
746
+ 'GTE' = '>=',
747
+ 'KNOWN' = 'is known',
748
+ 'NKNOWN' = 'is not known',
749
+ 'IS' = '=',
750
+ 'NIS' = '<>',
751
+ 'ON' = 'on',
752
+ }
753
+
754
+ interface FilterGroup {
755
+ filters: Filter[];
756
+ condition: 'allOf' | 'anyOf';
757
+ }
758
+
759
+ export interface Conditions {
760
+ filters: FilterGroup[];
761
+ condition: 'allOf' | 'anyOf';
762
+ variables: string[];
763
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
764
+ org_phones: string[];
765
+ }
766
+
767
+ export type SendMessageAction = {
768
+ id: string;
769
+ type: 'send_message';
770
+ metadata: {
771
+ message: string;
772
+ media?: {
773
+ url: string;
774
+ type: 'image' | 'video' | 'audio' | 'document';
775
+ name: string;
776
+ };
777
+ maintain_flag_status: 'true' | 'false';
778
+ debounce_messages: 'true' | 'false';
779
+ debounce_message_time:
780
+ | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
781
+ | null
782
+ | undefined;
783
+ };
784
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
785
+ };
786
+
787
+ export type NotifyHttpAction = {
788
+ id: string;
789
+ type: 'notify_http';
790
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
791
+ metadata: {
792
+ url: string;
793
+ };
794
+ };
795
+
796
+ export type CreateTicketAction = {
797
+ id: string;
798
+ type: 'create_ticket';
799
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
800
+ metadata: {
801
+ assignee?: string;
802
+ priority?: '0' | '1' | '2' | '3' | '4';
803
+ label?: string;
804
+ };
805
+ };
806
+
807
+ export type FlagMessageAction = {
808
+ id: string;
809
+ type: 'flag_message';
810
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
811
+ metadata: {
812
+ flag: 'true' | 'false';
813
+ };
814
+ };
815
+
816
+ export type AssignTicketAction = {
817
+ id: string;
818
+ type: 'assign_ticket';
819
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
820
+ metadata: {
821
+ assignee: string;
822
+ round_robin: 'true' | 'false';
823
+ };
824
+ };
825
+
826
+ export type CloseTicketAction = {
827
+ id: string;
828
+ type: 'close_ticket';
829
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
830
+ metadata: {
831
+ closing_note: string;
832
+ };
833
+ };
834
+
835
+ export type AddChatLabelAction = {
836
+ id: string;
837
+ type: 'add_chat_label';
838
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
839
+ metadata: {
840
+ label: string;
841
+ };
842
+ };
843
+
844
+ export type AddTicketLabelAction = {
845
+ id: string;
846
+ type: 'add_ticket_label';
847
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
848
+ metadata: {
849
+ label: string;
850
+ };
851
+ };
852
+
853
+ export type AssignChatAction = {
854
+ id: string;
855
+ type: 'assign_chat';
856
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
857
+ metadata: {
858
+ assignee: string;
859
+ round_robin: 'true' | 'false';
860
+ };
861
+ };
862
+
863
+ export type ForwardMessageAction = {
864
+ id: string;
865
+ type: 'forward_message';
866
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
867
+ metadata: {
868
+ chat_id: string;
869
+ prefix: string;
870
+ };
871
+ };
872
+
873
+ export type SendEmailAction = {
874
+ id: string;
875
+ type: 'send_email';
876
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
877
+ metadata: {
878
+ email: string;
879
+ subject: string;
880
+ body: string;
881
+ };
882
+ };
883
+
884
+ export type ReplyToMessageAction = {
885
+ id: string;
886
+ type: 'reply_to_message';
887
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
888
+ metadata: {
889
+ message: string;
890
+ media?: {
891
+ url: string;
892
+ type: 'image' | 'video' | 'audio' | 'document';
893
+ name: string;
894
+ };
895
+ maintain_flag_status: boolean;
896
+ debounce_messages: 'true' | 'false';
897
+ debounce_message_time:
898
+ | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
899
+ | null
900
+ | undefined;
901
+ };
902
+ };
903
+
904
+ export type UpdateCustomPropertyAction = {
905
+ id: string;
906
+ type: 'update_custom_property';
907
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
908
+ metadata: {
909
+ property_id: string;
910
+ value: string;
911
+ };
912
+ };
913
+
914
+ export type DeleteMessageAction = {
915
+ id: string;
916
+ type: 'delete_message';
917
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
918
+ metadata: {};
919
+ };
920
+
921
+ export type Action =
922
+ | SendMessageAction
923
+ | NotifyHttpAction
924
+ | CreateTicketAction
925
+ | FlagMessageAction
926
+ | AssignTicketAction
927
+ | CloseTicketAction
928
+ | AddChatLabelAction
929
+ | AddTicketLabelAction
930
+ | AssignChatAction
931
+ | ForwardMessageAction
932
+ | SendEmailAction
933
+ | ReplyToMessageAction
934
+ | UpdateCustomPropertyAction
935
+ | DeleteMessageAction;
936
+
937
+ export const isSendMessageOrReplyToMessageAction = (
938
+ action: Action
939
+ ): action is SendMessageAction | ReplyToMessageAction => {
940
+ return ['send_message', 'reply_to_message'].includes(action.type);
941
+ };
942
+
943
+ export type Rule = OverrideProperties<
944
+ Tables<'tbl_automation_rules'>,
945
+ {
946
+ actions: Action[];
947
+ conditions: Conditions;
948
+ trigger:
949
+ | 'message.created'
950
+ | 'message.updated'
951
+ | 'chat.created'
952
+ | 'ticket.updated'
953
+ | 'ticket.created'
954
+ | 'reaction.added'
955
+ | 'chat.label.updated'
956
+ | 'message.flagged';
957
+ }
958
+ >;
959
+
960
+ export const RuleNameMap: Record<
961
+ Rule['trigger'],
962
+ {
963
+ title: string;
964
+ description: string;
965
+ base_conditions: {
966
+ org_phone: boolean;
967
+ };
968
+ }
969
+ > = {
970
+ 'message.created': {
971
+ title: 'New Message Received',
972
+ description: 'When a new message is received from an external contact',
973
+ base_conditions: {
974
+ org_phone: true,
975
+ },
976
+ },
977
+ 'chat.created': {
978
+ title: 'New Chat Created',
979
+ description: 'When a new chat is created',
980
+ base_conditions: {
981
+ org_phone: true,
982
+ },
983
+ },
984
+ 'ticket.created': {
985
+ title: 'New Ticket Created',
986
+ description: 'When a new ticket is created',
987
+ base_conditions: {
988
+ org_phone: false,
989
+ },
990
+ },
991
+ 'reaction.added': {
992
+ title: 'New Reaction Added',
993
+ description: 'When a reaction is added on a message',
994
+ base_conditions: {
995
+ org_phone: true,
996
+ },
997
+ },
998
+ 'message.updated': {
999
+ title: 'Message Updated',
1000
+ description: 'When a message is updated',
1001
+ base_conditions: {
1002
+ org_phone: true,
1003
+ },
1004
+ },
1005
+ 'ticket.updated': {
1006
+ title: 'Ticket Updated',
1007
+ description: 'When a ticket is updated',
1008
+ base_conditions: {
1009
+ org_phone: false,
1010
+ },
1011
+ },
1012
+ 'chat.label.updated': {
1013
+ title: 'Chat Label Added/Removed',
1014
+ description: 'When labels on chats are updated',
1015
+ base_conditions: {
1016
+ org_phone: false,
1017
+ },
1018
+ },
1019
+ 'message.flagged': {
1020
+ title: 'Message Flagged',
1021
+ description: 'When a message is flagged',
1022
+ base_conditions: {
1023
+ org_phone: true,
1024
+ },
1025
+ },
1026
+ };
1027
+
1028
+ export const ActionNameMap: Record<
1029
+ Action['type'],
1030
+ {
1031
+ title: string;
1032
+ description: string;
1033
+ inputs: Record<
1034
+ string,
1035
+ {
1036
+ id: string;
1037
+ type:
1038
+ | 'text'
1039
+ | 'dropdown'
1040
+ | 'editor'
1041
+ | 'date'
1042
+ | 'file'
1043
+ | 'textarea'
1044
+ | 'dynamic';
1045
+ value:
1046
+ | 'ticket.labels'
1047
+ | 'org.members'
1048
+ | 'chat.labels'
1049
+ | 'org.chats'
1050
+ | {
1051
+ id: string;
1052
+ value: string;
1053
+ label: string;
1054
+ }[]
1055
+ | null
1056
+ | 'org.custom_properties'
1057
+ | 'custom_property_values'
1058
+ | 'debounce_messages';
1059
+ label: string;
1060
+ placeholder: string;
1061
+ info?: string;
1062
+ required: boolean;
1063
+ }
1064
+ >;
1065
+ validTriggers: Rule['trigger'][];
1066
+ }
1067
+ > = {
1068
+ send_message: {
1069
+ title: 'Send Message',
1070
+ description: 'Send a message',
1071
+ inputs: {
1072
+ message: {
1073
+ id: 'message',
1074
+ type: 'editor',
1075
+ label: 'Message',
1076
+ placeholder: 'Enter message',
1077
+ value: null,
1078
+ required: true,
1079
+ },
1080
+ media: {
1081
+ id: 'media',
1082
+ type: 'file',
1083
+ label: 'Media',
1084
+ placeholder: 'Upload media',
1085
+ value: null,
1086
+ required: false,
1087
+ },
1088
+ maintain_flag_status: {
1089
+ id: 'maintain_flag_status',
1090
+ type: 'dropdown',
1091
+ label: 'Maintain Flag Status',
1092
+ placeholder: 'Select...',
1093
+ value: [
1094
+ { id: 'true', value: 'true', label: 'True' },
1095
+ { id: 'false', value: 'false', label: 'False' },
1096
+ ],
1097
+ required: true,
1098
+ },
1099
+ debounce_messages: {
1100
+ id: 'debounce_messages',
1101
+ type: 'dropdown',
1102
+ label: 'Enable Cooldown Period',
1103
+ placeholder: 'Select...',
1104
+ value: [
1105
+ { id: 'true', value: 'true', label: 'True' },
1106
+ { id: 'false', value: 'false', label: 'False' },
1107
+ ],
1108
+ info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1109
+ required: false,
1110
+ },
1111
+ debounce_message_time: {
1112
+ id: 'debounce_message_time',
1113
+ type: 'dynamic',
1114
+ label: 'Cooldown Period',
1115
+ placeholder: 'Enter time',
1116
+ value: 'debounce_messages',
1117
+ required: false,
1118
+ },
1119
+ },
1120
+ validTriggers: [
1121
+ 'message.created',
1122
+ 'message.updated',
1123
+ 'chat.created',
1124
+ 'ticket.updated',
1125
+ 'ticket.created',
1126
+ 'reaction.added',
1127
+ 'message.flagged',
1128
+ 'chat.label.updated',
1129
+ ],
1130
+ },
1131
+ reply_to_message: {
1132
+ title: 'Reply to message',
1133
+ description: 'Send a message with the quoted message',
1134
+ inputs: {
1135
+ message: {
1136
+ id: 'message',
1137
+ type: 'editor',
1138
+ label: 'Message',
1139
+ placeholder: 'Enter message',
1140
+ value: null,
1141
+ required: true,
1142
+ },
1143
+ media: {
1144
+ id: 'media',
1145
+ type: 'file',
1146
+ label: 'Media',
1147
+ placeholder: 'Upload media',
1148
+ value: null,
1149
+ required: false,
1150
+ },
1151
+ maintain_flag_status: {
1152
+ id: 'maintain_flag_status',
1153
+ type: 'dropdown',
1154
+ label: 'Maintain Flag Status',
1155
+ placeholder: 'Select...',
1156
+ value: [
1157
+ { id: 'true', value: 'true', label: 'True' },
1158
+ { id: 'false', value: 'false', label: 'False' },
1159
+ ],
1160
+ required: true,
1161
+ },
1162
+ debounce_messages: {
1163
+ id: 'debounce_messages',
1164
+ type: 'dropdown',
1165
+ label: 'Enable Cooldown Period',
1166
+ placeholder: 'Select...',
1167
+ value: [
1168
+ { id: 'true', value: 'true', label: 'True' },
1169
+ { id: 'false', value: 'false', label: 'False' },
1170
+ ],
1171
+ info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1172
+ required: false,
1173
+ },
1174
+ debounce_message_time: {
1175
+ id: 'debounce_message_time',
1176
+ type: 'dynamic',
1177
+ label: 'Cooldown Period',
1178
+ placeholder: 'Enter time',
1179
+ value: 'debounce_messages',
1180
+ required: false,
1181
+ },
1182
+ },
1183
+ validTriggers: [
1184
+ 'message.created',
1185
+ 'message.updated',
1186
+ 'reaction.added',
1187
+ 'message.flagged',
1188
+ ],
1189
+ },
1190
+ delete_message: {
1191
+ title: 'Delete Message',
1192
+ description: 'Delete a message',
1193
+ inputs: {},
1194
+ validTriggers: [
1195
+ 'message.created',
1196
+ 'message.updated',
1197
+ 'reaction.added',
1198
+ 'message.flagged',
1199
+ ],
1200
+ },
1201
+ notify_http: {
1202
+ title: 'Notify HTTP',
1203
+ description: 'Notify an HTTP endpoint',
1204
+ inputs: {
1205
+ url: {
1206
+ id: 'url',
1207
+ type: 'text',
1208
+ label: 'URL',
1209
+ placeholder: 'Enter URL',
1210
+ value: null,
1211
+ required: true,
1212
+ },
1213
+ },
1214
+ validTriggers: [
1215
+ 'message.created',
1216
+ 'message.updated',
1217
+ 'chat.created',
1218
+ 'ticket.updated',
1219
+ 'ticket.created',
1220
+ 'reaction.added',
1221
+ 'message.flagged',
1222
+ 'chat.label.updated',
1223
+ ],
1224
+ },
1225
+ create_ticket: {
1226
+ title: 'Create Ticket',
1227
+ description: 'Create a ticket',
1228
+ inputs: {
1229
+ assignee: {
1230
+ id: 'assignee',
1231
+ type: 'dropdown',
1232
+ value: 'org.members',
1233
+ label: 'Assignee',
1234
+ placeholder: 'Select assignee',
1235
+ required: false,
1236
+ },
1237
+ priority: {
1238
+ id: 'priority',
1239
+ type: 'dropdown',
1240
+ value: [
1241
+ { id: '0', value: '0', label: 'No Prioriy' },
1242
+ { id: '1', value: '1', label: 'Low' },
1243
+ { id: '2', value: '2', label: 'Medium' },
1244
+ { id: '3', value: '3', label: 'High' },
1245
+ { id: '4', value: '4', label: 'Urgent' },
1246
+ ],
1247
+ label: 'Priority',
1248
+ placeholder: 'Select priority',
1249
+ required: false,
1250
+ },
1251
+ label: {
1252
+ id: 'label',
1253
+ type: 'dropdown',
1254
+ value: 'ticket.labels',
1255
+ label: 'Label',
1256
+ placeholder: 'Select label',
1257
+ required: false,
1258
+ },
1259
+ },
1260
+ validTriggers: [
1261
+ 'message.created',
1262
+ 'message.updated',
1263
+ 'reaction.added',
1264
+ 'message.flagged',
1265
+ ],
1266
+ },
1267
+ flag_message: {
1268
+ title: 'Update flag status',
1269
+ description: 'Flag/Unflag a message',
1270
+ inputs: {
1271
+ flag: {
1272
+ id: 'flag',
1273
+ type: 'dropdown',
1274
+ value: [
1275
+ { id: 'flag', value: 'true', label: 'TRUE' },
1276
+ { id: 'unflag', value: 'false', label: 'FALSE' },
1277
+ ],
1278
+ label: 'Flag status',
1279
+ placeholder: 'Select flag',
1280
+ required: true,
1281
+ },
1282
+ },
1283
+ validTriggers: [
1284
+ 'message.created',
1285
+ 'message.updated',
1286
+ 'reaction.added',
1287
+ 'message.flagged',
1288
+ ],
1289
+ },
1290
+ assign_ticket: {
1291
+ title: 'Assign Ticket',
1292
+ description: 'Assign a ticket',
1293
+ inputs: {
1294
+ round_robin: {
1295
+ id: 'round_robin',
1296
+ type: 'dropdown',
1297
+ value: [
1298
+ { id: 'true', value: 'true', label: 'True' },
1299
+ { id: 'false', value: 'false', label: 'False' },
1300
+ ],
1301
+ label: 'Enable Round Robin',
1302
+ placeholder: 'Select...',
1303
+ info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1304
+ required: false,
1305
+ },
1306
+ assignee: {
1307
+ id: 'assignee',
1308
+ type: 'dynamic',
1309
+ value: 'org.members',
1310
+ label: 'Assignee',
1311
+ placeholder: 'Select assignee',
1312
+ 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",
1313
+ required: true,
1314
+ },
1315
+ },
1316
+ validTriggers: ['ticket.updated', 'ticket.created'],
1317
+ },
1318
+ close_ticket: {
1319
+ title: 'Close Ticket',
1320
+ description: 'Close a ticket',
1321
+ inputs: {
1322
+ closing_note: {
1323
+ id: 'closing_note',
1324
+ type: 'textarea',
1325
+ label: 'Closing Note',
1326
+ placeholder: 'Enter closing note',
1327
+ value: null,
1328
+ required: false,
1329
+ },
1330
+ },
1331
+ validTriggers: ['ticket.updated', 'ticket.created'],
1332
+ },
1333
+ add_chat_label: {
1334
+ title: 'Add Chat Label',
1335
+ description: 'Add a label to referred chat',
1336
+ inputs: {
1337
+ label: {
1338
+ id: 'label',
1339
+ type: 'dropdown',
1340
+ value: 'chat.labels',
1341
+ label: 'Label',
1342
+ placeholder: 'Select label',
1343
+ required: true,
1344
+ },
1345
+ },
1346
+ validTriggers: [
1347
+ 'message.created',
1348
+ 'message.updated',
1349
+ 'chat.created',
1350
+ 'ticket.updated',
1351
+ 'ticket.created',
1352
+ 'reaction.added',
1353
+ 'chat.label.updated',
1354
+ 'message.flagged',
1355
+ ],
1356
+ },
1357
+ add_ticket_label: {
1358
+ title: 'Add Ticket Label',
1359
+ description: 'Add a label to referred ticket',
1360
+ inputs: {
1361
+ label: {
1362
+ id: 'label',
1363
+ type: 'dropdown',
1364
+ value: 'ticket.labels',
1365
+ label: 'Label',
1366
+ placeholder: 'Select label',
1367
+ required: true,
1368
+ },
1369
+ },
1370
+ validTriggers: ['ticket.updated', 'ticket.created'],
1371
+ },
1372
+ update_custom_property: {
1373
+ description: 'Update a chat custom property',
1374
+ title: 'Update Chat Custom Property',
1375
+ validTriggers: [
1376
+ 'message.created',
1377
+ 'message.updated',
1378
+ 'chat.created',
1379
+ 'ticket.updated',
1380
+ 'ticket.created',
1381
+ 'reaction.added',
1382
+ 'message.flagged',
1383
+ 'chat.label.updated',
1384
+ ],
1385
+ inputs: {
1386
+ property_id: {
1387
+ id: 'property_id',
1388
+ type: 'dropdown',
1389
+ value: 'org.custom_properties',
1390
+ label: 'Property',
1391
+ placeholder: 'Select property',
1392
+ required: true,
1393
+ },
1394
+ value: {
1395
+ id: 'property_id',
1396
+ type: 'dynamic',
1397
+ label: 'Value',
1398
+ placeholder: 'Enter value',
1399
+ value: 'custom_property_values',
1400
+ required: true,
1401
+ },
1402
+ },
1403
+ },
1404
+ assign_chat: {
1405
+ title: 'Assign Chat',
1406
+ description: 'Assign a chat',
1407
+ inputs: {
1408
+ round_robin: {
1409
+ id: 'round_robin',
1410
+ type: 'dropdown',
1411
+ value: [
1412
+ { id: 'true', value: 'true', label: 'True' },
1413
+ { id: 'false', value: 'false', label: 'False' },
1414
+ ],
1415
+ label: 'Enable Round Robin',
1416
+ placeholder: 'Select...',
1417
+ info: 'If enabled, the chat will be assigned to the next available agent in the list',
1418
+ required: false,
1419
+ },
1420
+ assignee: {
1421
+ id: 'assignee',
1422
+ type: 'dynamic',
1423
+ value: 'org.members',
1424
+ label: 'Assignee',
1425
+ placeholder: 'Select assignee',
1426
+ required: true,
1427
+ },
1428
+ },
1429
+ validTriggers: [
1430
+ 'message.created',
1431
+ 'message.updated',
1432
+ 'chat.created',
1433
+ 'ticket.updated',
1434
+ 'ticket.created',
1435
+ 'reaction.added',
1436
+ 'chat.label.updated',
1437
+ 'message.flagged',
1438
+ ],
1439
+ },
1440
+ forward_message: {
1441
+ title: 'Forward Message',
1442
+ description: 'Forward a message',
1443
+ inputs: {
1444
+ chat_id: {
1445
+ id: 'chat_id',
1446
+ type: 'dropdown',
1447
+ value: 'org.chats',
1448
+ label: 'Chat',
1449
+ placeholder: 'Select chat',
1450
+ required: true,
1451
+ },
1452
+ },
1453
+ validTriggers: [
1454
+ 'message.created',
1455
+ 'message.updated',
1456
+ 'ticket.updated',
1457
+ 'ticket.created',
1458
+ 'reaction.added',
1459
+ 'message.flagged',
1460
+ ],
1461
+ },
1462
+ send_email: {
1463
+ title: 'Send Email',
1464
+ description: 'Send an email',
1465
+ inputs: {
1466
+ email: {
1467
+ id: 'email',
1468
+ type: 'text',
1469
+ label: 'Email',
1470
+ placeholder: 'Enter email',
1471
+ value: null,
1472
+ required: true,
1473
+ },
1474
+ subject: {
1475
+ id: 'subject',
1476
+ type: 'editor',
1477
+ label: 'Subject',
1478
+ placeholder: 'Enter subject',
1479
+ value: null,
1480
+ required: true,
1481
+ },
1482
+ body: {
1483
+ id: 'body',
1484
+ type: 'editor',
1485
+ label: 'Body',
1486
+ placeholder: 'Enter body',
1487
+ value: null,
1488
+ required: true,
1489
+ },
1490
+ },
1491
+ validTriggers: [
1492
+ 'message.created',
1493
+ 'message.updated',
1494
+ 'chat.created',
1495
+ 'ticket.updated',
1496
+ 'ticket.created',
1497
+ 'reaction.added',
1498
+ 'message.flagged',
1499
+ 'chat.label.updated',
1500
+ ],
1501
+ },
1502
+ };
1503
+
1504
+ export const editorVariables: Array<{
1505
+ label: string;
1506
+ value: string;
1507
+ validTriggers: Rule['trigger'][];
1508
+ }> = [
1509
+ {
1510
+ label: 'Message Body',
1511
+ value: 'message.body',
1512
+ validTriggers: [
1513
+ 'message.created',
1514
+ 'message.updated',
1515
+ 'reaction.added',
1516
+ 'message.flagged',
1517
+ 'ticket.created',
1518
+ 'ticket.updated',
1519
+ ],
1520
+ },
1521
+ {
1522
+ label: 'Sender Name',
1523
+ value: 'sender.contact_name',
1524
+ validTriggers: [
1525
+ 'message.created',
1526
+ 'message.updated',
1527
+ 'reaction.added',
1528
+ 'message.flagged',
1529
+ 'ticket.created',
1530
+ 'ticket.updated',
1531
+ ],
1532
+ },
1533
+ {
1534
+ label: 'Chat Name',
1535
+ value: 'chat.chat_name',
1536
+ validTriggers: [
1537
+ 'message.created',
1538
+ 'message.updated',
1539
+ 'reaction.added',
1540
+ 'message.flagged',
1541
+ 'chat.created',
1542
+ 'chat.label.updated',
1543
+ 'ticket.created',
1544
+ 'ticket.updated',
1545
+ ],
1546
+ },
1547
+ {
1548
+ label: 'Ticket ID',
1549
+ value: 'ticket.ticket_id',
1550
+ validTriggers: ['ticket.updated', 'ticket.created'],
1551
+ },
1552
+ {
1553
+ label: 'Chat ID',
1554
+ value: 'chat.chat_id',
1555
+ validTriggers: [
1556
+ 'message.created',
1557
+ 'message.updated',
1558
+ 'reaction.added',
1559
+ 'message.flagged',
1560
+ 'chat.created',
1561
+ 'chat.label.updated',
1562
+ 'ticket.created',
1563
+ 'ticket.updated',
1564
+ ],
1565
+ },
1566
+ {
1567
+ label: 'Reaction',
1568
+ value: 'reaction.reaction',
1569
+ validTriggers: ['reaction.added'],
1570
+ },
1571
+ ];
1572
+
1573
+ export const variablesExclusionList: Record<
1574
+ Rule['trigger'],
1575
+ Array<
1576
+ | keyof AppendTypes<{ message: MessageVariablesType }, '.'>
1577
+ | keyof AppendTypes<{ sender: SenderVariablesType }, '.'>
1578
+ | keyof AppendTypes<{ chat: ChatVariablesType }, '.'>
1579
+ | keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>
1580
+ | keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>
1581
+ >
1582
+ > = {
1583
+ 'ticket.created': ['ticket.is_deleted'],
1584
+ 'chat.created': [
1585
+ 'chat.chat_id',
1586
+ 'chat.labels',
1587
+ 'chat.has_flagged_messages',
1588
+ 'chat.assigned_to',
1589
+ ],
1590
+ 'message.created': [
1591
+ 'message.author',
1592
+ 'message.performed_by',
1593
+ 'message.flag_status',
1594
+ 'sender.is_internal',
1595
+ ],
1596
+ 'ticket.updated': ['ticket.is_deleted'],
1597
+ 'reaction.added': [],
1598
+ 'message.updated': [],
1599
+ 'message.flagged': [],
1600
+ 'chat.label.updated': [],
1601
+ };