@periskope/types 0.6.178 → 0.6.180

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,1618 +1,1874 @@
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
- allow_messages_from_org_phones?: boolean;
766
- }
767
-
768
- export type SendMessageAction = {
769
- id: string;
770
- type: 'send_message';
771
- metadata: {
772
- message: string;
773
- media?: {
774
- url: string;
775
- type: 'image' | 'video' | 'audio' | 'document';
776
- name: string;
777
- };
778
- maintain_flag_status: 'true' | 'false';
779
- debounce_messages: 'true' | 'false';
780
- debounce_message_time:
781
- | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
782
- | null
783
- | undefined;
784
- };
785
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
786
- };
787
-
788
- export type NotifyHttpAction = {
789
- id: string;
790
- type: 'notify_http';
791
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
792
- metadata: {
793
- url: string;
794
- };
795
- };
796
-
797
- export type CreateTicketAction = {
798
- id: string;
799
- type: 'create_ticket';
800
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
801
- metadata: {
802
- assignee?: string;
803
- priority?: '0' | '1' | '2' | '3' | '4';
804
- label?: string;
805
- append_to_latest_ticket?: 'true' | 'false';
806
- };
807
- };
808
-
809
- export type FlagMessageAction = {
810
- id: string;
811
- type: 'flag_message';
812
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
813
- metadata: {
814
- flag: 'true' | 'false';
815
- };
816
- };
817
-
818
- export type AssignTicketAction = {
819
- id: string;
820
- type: 'assign_ticket';
821
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
822
- metadata: {
823
- assignee: string;
824
- round_robin: 'true' | 'false';
825
- };
826
- };
827
-
828
- export type CloseTicketAction = {
829
- id: string;
830
- type: 'close_ticket';
831
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
832
- metadata: {
833
- closing_note: string;
834
- };
835
- };
836
-
837
- export type AddChatLabelAction = {
838
- id: string;
839
- type: 'add_chat_label';
840
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
841
- metadata: {
842
- label: string;
843
- };
844
- };
845
-
846
- export type AddTicketLabelAction = {
847
- id: string;
848
- type: 'add_ticket_label';
849
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
850
- metadata: {
851
- label: string;
852
- };
853
- };
854
-
855
- export type AssignChatAction = {
856
- id: string;
857
- type: 'assign_chat';
858
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
859
- metadata: {
860
- assignee: string;
861
- round_robin: 'true' | 'false';
862
- };
863
- };
864
-
865
- export type ForwardMessageAction = {
866
- id: string;
867
- type: 'forward_message';
868
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
869
- metadata: {
870
- chat_id: string;
871
- prefix: string;
872
- };
873
- };
874
-
875
- export type SendEmailAction = {
876
- id: string;
877
- type: 'send_email';
878
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
879
- metadata: {
880
- email: string;
881
- subject: string;
882
- body: string;
883
- };
884
- };
885
-
886
- export type ReplyToMessageAction = {
887
- id: string;
888
- type: 'reply_to_message';
889
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
890
- metadata: {
891
- message: string;
892
- media?: {
893
- url: string;
894
- type: 'image' | 'video' | 'audio' | 'document';
895
- name: string;
896
- };
897
- maintain_flag_status: 'true' | 'false';
898
- debounce_messages: 'true' | 'false';
899
- debounce_message_time:
900
- | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
901
- | null
902
- | undefined;
903
- };
904
- };
905
-
906
- export type UpdateCustomPropertyAction = {
907
- id: string;
908
- type: 'update_custom_property';
909
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
910
- metadata: {
911
- property_id: string;
912
- value: string;
913
- };
914
- };
915
-
916
- export type DeleteMessageAction = {
917
- id: string;
918
- type: 'delete_message';
919
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
920
- metadata: {};
921
- };
922
-
923
- export type Action =
924
- | SendMessageAction
925
- | NotifyHttpAction
926
- | CreateTicketAction
927
- | FlagMessageAction
928
- | AssignTicketAction
929
- | CloseTicketAction
930
- | AddChatLabelAction
931
- | AddTicketLabelAction
932
- | AssignChatAction
933
- | ForwardMessageAction
934
- | SendEmailAction
935
- | ReplyToMessageAction
936
- | UpdateCustomPropertyAction
937
- | DeleteMessageAction;
938
-
939
- export const isSendMessageOrReplyToMessageAction = (
940
- action: Action
941
- ): action is SendMessageAction | ReplyToMessageAction => {
942
- return ['send_message', 'reply_to_message'].includes(action.type);
943
- };
944
-
945
- export type Rule = OverrideProperties<
946
- Tables<'tbl_automation_rules'>,
947
- {
948
- actions: Action[];
949
- conditions: Conditions;
950
- trigger:
951
- | 'message.created'
952
- | 'message.updated'
953
- | 'chat.created'
954
- | 'ticket.updated'
955
- | 'ticket.created'
956
- | 'reaction.added'
957
- | 'chat.label.updated'
958
- | 'message.flagged';
959
- }
960
- >;
961
-
962
- export const RuleNameMap: Record<
963
- Rule['trigger'],
964
- {
965
- title: string;
966
- description: string;
967
- base_conditions: {
968
- org_phone: boolean;
969
- };
970
- }
971
- > = {
972
- 'message.created': {
973
- title: 'New Message Received',
974
- description: 'When a new message is received from an external contact',
975
- base_conditions: {
976
- org_phone: true,
977
- },
978
- },
979
- 'chat.created': {
980
- title: 'New Chat Created',
981
- description: 'When a new chat is created',
982
- base_conditions: {
983
- org_phone: true,
984
- },
985
- },
986
- 'ticket.created': {
987
- title: 'New Ticket Created',
988
- description: 'When a new ticket is created',
989
- base_conditions: {
990
- org_phone: false,
991
- },
992
- },
993
- 'reaction.added': {
994
- title: 'New Reaction Added',
995
- description: 'When a reaction is added on a message',
996
- base_conditions: {
997
- org_phone: true,
998
- },
999
- },
1000
- 'message.updated': {
1001
- title: 'Message Updated',
1002
- description: 'When a message is updated',
1003
- base_conditions: {
1004
- org_phone: true,
1005
- },
1006
- },
1007
- 'ticket.updated': {
1008
- title: 'Ticket Updated',
1009
- description: 'When a ticket is updated',
1010
- base_conditions: {
1011
- org_phone: false,
1012
- },
1013
- },
1014
- 'chat.label.updated': {
1015
- title: 'Chat Label Added/Removed',
1016
- description: 'When labels on chats are updated',
1017
- base_conditions: {
1018
- org_phone: false,
1019
- },
1020
- },
1021
- 'message.flagged': {
1022
- title: 'Message Flagged',
1023
- description: 'When a message is flagged',
1024
- base_conditions: {
1025
- org_phone: true,
1026
- },
1027
- },
1028
- };
1029
-
1030
- export const ActionNameMap: Record<
1031
- Action['type'],
1032
- {
1033
- title: string;
1034
- description: string;
1035
- inputs: Record<
1036
- string,
1037
- {
1038
- id: string;
1039
- type:
1040
- | 'text'
1041
- | 'dropdown'
1042
- | 'editor'
1043
- | 'date'
1044
- | 'file'
1045
- | 'textarea'
1046
- | 'dynamic';
1047
- value:
1048
- | 'ticket.labels'
1049
- | 'org.members'
1050
- | 'chat.labels'
1051
- | 'org.chats'
1052
- | {
1053
- id: string;
1054
- value: string;
1055
- label: string;
1056
- }[]
1057
- | null
1058
- | 'org.custom_properties'
1059
- | 'custom_property_values'
1060
- | 'debounce_messages';
1061
- label: string;
1062
- placeholder: string;
1063
- info?: string;
1064
- required: boolean;
1065
- }
1066
- >;
1067
- validTriggers: Rule['trigger'][];
1068
- }
1069
- > = {
1070
- send_message: {
1071
- title: 'Send Message',
1072
- description: 'Send a message',
1073
- inputs: {
1074
- message: {
1075
- id: 'message',
1076
- type: 'editor',
1077
- label: 'Message',
1078
- placeholder: 'Enter message',
1079
- value: null,
1080
- required: true,
1081
- },
1082
- media: {
1083
- id: 'media',
1084
- type: 'file',
1085
- label: 'Media',
1086
- placeholder: 'Upload media',
1087
- value: null,
1088
- required: false,
1089
- },
1090
- maintain_flag_status: {
1091
- id: 'maintain_flag_status',
1092
- type: 'dropdown',
1093
- label: 'Maintain Flag Status',
1094
- placeholder: 'Select...',
1095
- value: [
1096
- { id: 'true', value: 'true', label: 'True' },
1097
- { id: 'false', value: 'false', label: 'False' },
1098
- ],
1099
- required: true,
1100
- },
1101
- debounce_messages: {
1102
- id: 'debounce_messages',
1103
- type: 'dropdown',
1104
- label: 'Enable Cooldown Period',
1105
- placeholder: 'Select...',
1106
- value: [
1107
- { id: 'true', value: 'true', label: 'True' },
1108
- { id: 'false', value: 'false', label: 'False' },
1109
- ],
1110
- info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1111
- required: false,
1112
- },
1113
- debounce_message_time: {
1114
- id: 'debounce_message_time',
1115
- type: 'dynamic',
1116
- label: 'Cooldown Period',
1117
- placeholder: 'Enter time',
1118
- value: 'debounce_messages',
1119
- required: false,
1120
- },
1121
- },
1122
- validTriggers: [
1123
- 'message.created',
1124
- 'message.updated',
1125
- 'chat.created',
1126
- 'ticket.updated',
1127
- 'ticket.created',
1128
- 'reaction.added',
1129
- 'message.flagged',
1130
- 'chat.label.updated',
1131
- ],
1132
- },
1133
- reply_to_message: {
1134
- title: 'Reply to message',
1135
- description: 'Send a message with the quoted message',
1136
- inputs: {
1137
- message: {
1138
- id: 'message',
1139
- type: 'editor',
1140
- label: 'Message',
1141
- placeholder: 'Enter message',
1142
- value: null,
1143
- required: true,
1144
- },
1145
- media: {
1146
- id: 'media',
1147
- type: 'file',
1148
- label: 'Media',
1149
- placeholder: 'Upload media',
1150
- value: null,
1151
- required: false,
1152
- },
1153
- maintain_flag_status: {
1154
- id: 'maintain_flag_status',
1155
- type: 'dropdown',
1156
- label: 'Maintain Flag Status',
1157
- placeholder: 'Select...',
1158
- value: [
1159
- { id: 'true', value: 'true', label: 'True' },
1160
- { id: 'false', value: 'false', label: 'False' },
1161
- ],
1162
- required: true,
1163
- },
1164
- debounce_messages: {
1165
- id: 'debounce_messages',
1166
- type: 'dropdown',
1167
- label: 'Enable Cooldown Period',
1168
- placeholder: 'Select...',
1169
- value: [
1170
- { id: 'true', value: 'true', label: 'True' },
1171
- { id: 'false', value: 'false', label: 'False' },
1172
- ],
1173
- info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1174
- required: false,
1175
- },
1176
- debounce_message_time: {
1177
- id: 'debounce_message_time',
1178
- type: 'dynamic',
1179
- label: 'Cooldown Period',
1180
- placeholder: 'Enter time',
1181
- value: 'debounce_messages',
1182
- required: false,
1183
- },
1184
- },
1185
- validTriggers: [
1186
- 'message.created',
1187
- 'message.updated',
1188
- 'reaction.added',
1189
- 'message.flagged',
1190
- ],
1191
- },
1192
- delete_message: {
1193
- title: 'Delete Message',
1194
- description: 'Delete a message',
1195
- inputs: {},
1196
- validTriggers: [
1197
- 'message.created',
1198
- 'message.updated',
1199
- 'reaction.added',
1200
- 'message.flagged',
1201
- ],
1202
- },
1203
- notify_http: {
1204
- title: 'Notify HTTP',
1205
- description: 'Notify an HTTP endpoint',
1206
- inputs: {
1207
- url: {
1208
- id: 'url',
1209
- type: 'text',
1210
- label: 'URL',
1211
- placeholder: 'Enter URL',
1212
- value: null,
1213
- required: true,
1214
- },
1215
- },
1216
- validTriggers: [
1217
- 'message.created',
1218
- 'message.updated',
1219
- 'chat.created',
1220
- 'ticket.updated',
1221
- 'ticket.created',
1222
- 'reaction.added',
1223
- 'message.flagged',
1224
- 'chat.label.updated',
1225
- ],
1226
- },
1227
- create_ticket: {
1228
- title: 'Create Ticket or Attach Message To Latest Ticket',
1229
- description: 'Create a ticket or attach message to latest ticket',
1230
- inputs: {
1231
- append_to_latest_ticket: {
1232
- id: 'append_to_latest_ticket',
1233
- type: 'dropdown',
1234
- value: [
1235
- { id: 'true', value: 'true', label: 'True' },
1236
- { id: 'false', value: 'false', label: 'False' },
1237
- ],
1238
- label: 'Attach message to latest ticket (if available)',
1239
- placeholder: 'Select...',
1240
- info: 'If enabled, the message will be appended to the latest open ticket (if available) else a new ticket will be created',
1241
- required: false,
1242
- },
1243
- assignee: {
1244
- id: 'assignee',
1245
- type: 'dropdown',
1246
- value: 'org.members',
1247
- label: 'Assignee (New Ticket)',
1248
- placeholder: 'Select assignee',
1249
- info: 'Only applicable for create ticket. If no assignee is selected, the ticket will be unassigned.',
1250
- required: false,
1251
- },
1252
- priority: {
1253
- id: 'priority',
1254
- type: 'dropdown',
1255
- value: [
1256
- { id: '0', value: '0', label: 'No Prioriy' },
1257
- { id: '1', value: '1', label: 'Low' },
1258
- { id: '2', value: '2', label: 'Medium' },
1259
- { id: '3', value: '3', label: 'High' },
1260
- { id: '4', value: '4', label: 'Urgent' },
1261
- ],
1262
- label: 'Priority (New Ticket)',
1263
- placeholder: 'Select priority',
1264
- info: 'Only applicable for create ticket. If no priority is selected, the ticket will have no priority.',
1265
- required: false,
1266
- },
1267
- label: {
1268
- id: 'label',
1269
- type: 'dropdown',
1270
- value: 'ticket.labels',
1271
- label: 'Label (New Ticket)',
1272
- placeholder: 'Select label',
1273
- info: 'Only applicable for create ticket. If no label is selected, the ticket will have no label.',
1274
- required: false,
1275
- },
1276
- },
1277
- validTriggers: [
1278
- 'message.created',
1279
- 'message.updated',
1280
- 'reaction.added',
1281
- 'message.flagged',
1282
- ],
1283
- },
1284
- flag_message: {
1285
- title: 'Update flag status',
1286
- description: 'Flag/Unflag a message',
1287
- inputs: {
1288
- flag: {
1289
- id: 'flag',
1290
- type: 'dropdown',
1291
- value: [
1292
- { id: 'flag', value: 'true', label: 'TRUE' },
1293
- { id: 'unflag', value: 'false', label: 'FALSE' },
1294
- ],
1295
- label: 'Flag status',
1296
- placeholder: 'Select flag',
1297
- required: true,
1298
- },
1299
- },
1300
- validTriggers: [
1301
- 'message.created',
1302
- 'message.updated',
1303
- 'reaction.added',
1304
- 'message.flagged',
1305
- ],
1306
- },
1307
- assign_ticket: {
1308
- title: 'Assign Ticket',
1309
- description: 'Assign a ticket',
1310
- inputs: {
1311
- round_robin: {
1312
- id: 'round_robin',
1313
- type: 'dropdown',
1314
- value: [
1315
- { id: 'true', value: 'true', label: 'True' },
1316
- { id: 'false', value: 'false', label: 'False' },
1317
- ],
1318
- label: 'Enable Round Robin',
1319
- placeholder: 'Select...',
1320
- info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1321
- required: false,
1322
- },
1323
- assignee: {
1324
- id: 'assignee',
1325
- type: 'dynamic',
1326
- value: 'org.members',
1327
- label: 'Assignee',
1328
- placeholder: 'Select assignee',
1329
- 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",
1330
- required: true,
1331
- },
1332
- },
1333
- validTriggers: ['ticket.updated', 'ticket.created'],
1334
- },
1335
- close_ticket: {
1336
- title: 'Close Ticket',
1337
- description: 'Close a ticket',
1338
- inputs: {
1339
- closing_note: {
1340
- id: 'closing_note',
1341
- type: 'textarea',
1342
- label: 'Closing Note',
1343
- placeholder: 'Enter closing note',
1344
- value: null,
1345
- required: false,
1346
- },
1347
- },
1348
- validTriggers: ['ticket.updated', 'ticket.created'],
1349
- },
1350
- add_chat_label: {
1351
- title: 'Add Chat Label',
1352
- description: 'Add a label to referred chat',
1353
- inputs: {
1354
- label: {
1355
- id: 'label',
1356
- type: 'dropdown',
1357
- value: 'chat.labels',
1358
- label: 'Label',
1359
- placeholder: 'Select label',
1360
- required: true,
1361
- },
1362
- },
1363
- validTriggers: [
1364
- 'message.created',
1365
- 'message.updated',
1366
- 'chat.created',
1367
- 'ticket.updated',
1368
- 'ticket.created',
1369
- 'reaction.added',
1370
- 'chat.label.updated',
1371
- 'message.flagged',
1372
- ],
1373
- },
1374
- add_ticket_label: {
1375
- title: 'Add Ticket Label',
1376
- description: 'Add a label to referred ticket',
1377
- inputs: {
1378
- label: {
1379
- id: 'label',
1380
- type: 'dropdown',
1381
- value: 'ticket.labels',
1382
- label: 'Label',
1383
- placeholder: 'Select label',
1384
- required: true,
1385
- },
1386
- },
1387
- validTriggers: ['ticket.updated', 'ticket.created'],
1388
- },
1389
- update_custom_property: {
1390
- description: 'Update a chat custom property',
1391
- title: 'Update Chat Custom Property',
1392
- validTriggers: [
1393
- 'message.created',
1394
- 'message.updated',
1395
- 'chat.created',
1396
- 'ticket.updated',
1397
- 'ticket.created',
1398
- 'reaction.added',
1399
- 'message.flagged',
1400
- 'chat.label.updated',
1401
- ],
1402
- inputs: {
1403
- property_id: {
1404
- id: 'property_id',
1405
- type: 'dropdown',
1406
- value: 'org.custom_properties',
1407
- label: 'Property',
1408
- placeholder: 'Select property',
1409
- required: true,
1410
- },
1411
- value: {
1412
- id: 'property_id',
1413
- type: 'dynamic',
1414
- label: 'Value',
1415
- placeholder: 'Enter value',
1416
- value: 'custom_property_values',
1417
- required: true,
1418
- },
1419
- },
1420
- },
1421
- assign_chat: {
1422
- title: 'Assign Chat',
1423
- description: 'Assign a chat',
1424
- inputs: {
1425
- round_robin: {
1426
- id: 'round_robin',
1427
- type: 'dropdown',
1428
- value: [
1429
- { id: 'true', value: 'true', label: 'True' },
1430
- { id: 'false', value: 'false', label: 'False' },
1431
- ],
1432
- label: 'Enable Round Robin',
1433
- placeholder: 'Select...',
1434
- info: 'If enabled, the chat will be assigned to the next available agent in the list',
1435
- required: false,
1436
- },
1437
- assignee: {
1438
- id: 'assignee',
1439
- type: 'dynamic',
1440
- value: 'org.members',
1441
- label: 'Assignee',
1442
- placeholder: 'Select assignee',
1443
- required: true,
1444
- },
1445
- },
1446
- validTriggers: [
1447
- 'message.created',
1448
- 'message.updated',
1449
- 'chat.created',
1450
- 'ticket.updated',
1451
- 'ticket.created',
1452
- 'reaction.added',
1453
- 'chat.label.updated',
1454
- 'message.flagged',
1455
- ],
1456
- },
1457
- forward_message: {
1458
- title: 'Forward Message',
1459
- description: 'Forward a message',
1460
- inputs: {
1461
- chat_id: {
1462
- id: 'chat_id',
1463
- type: 'dropdown',
1464
- value: 'org.chats',
1465
- label: 'Chat',
1466
- placeholder: 'Select chat',
1467
- required: true,
1468
- },
1469
- },
1470
- validTriggers: [
1471
- 'message.created',
1472
- 'message.updated',
1473
- 'ticket.updated',
1474
- 'ticket.created',
1475
- 'reaction.added',
1476
- 'message.flagged',
1477
- ],
1478
- },
1479
- send_email: {
1480
- title: 'Send Email',
1481
- description: 'Send an email',
1482
- inputs: {
1483
- email: {
1484
- id: 'email',
1485
- type: 'text',
1486
- label: 'Email',
1487
- placeholder: 'Enter email',
1488
- value: null,
1489
- required: true,
1490
- },
1491
- subject: {
1492
- id: 'subject',
1493
- type: 'editor',
1494
- label: 'Subject',
1495
- placeholder: 'Enter subject',
1496
- value: null,
1497
- required: true,
1498
- },
1499
- body: {
1500
- id: 'body',
1501
- type: 'editor',
1502
- label: 'Body',
1503
- placeholder: 'Enter body',
1504
- value: null,
1505
- required: true,
1506
- },
1507
- },
1508
- validTriggers: [
1509
- 'message.created',
1510
- 'message.updated',
1511
- 'chat.created',
1512
- 'ticket.updated',
1513
- 'ticket.created',
1514
- 'reaction.added',
1515
- 'message.flagged',
1516
- 'chat.label.updated',
1517
- ],
1518
- },
1519
- };
1520
-
1521
- export const editorVariables: Array<{
1522
- label: string;
1523
- value: string;
1524
- validTriggers: Rule['trigger'][];
1525
- }> = [
1526
- {
1527
- label: 'Message Body',
1528
- value: 'message.body',
1529
- validTriggers: [
1530
- 'message.created',
1531
- 'message.updated',
1532
- 'reaction.added',
1533
- 'message.flagged',
1534
- 'ticket.created',
1535
- 'ticket.updated',
1536
- ],
1537
- },
1538
- {
1539
- label: 'Sender Name',
1540
- value: 'sender.contact_name',
1541
- validTriggers: [
1542
- 'message.created',
1543
- 'message.updated',
1544
- 'reaction.added',
1545
- 'message.flagged',
1546
- 'ticket.created',
1547
- 'ticket.updated',
1548
- ],
1549
- },
1550
- {
1551
- label: 'Chat Name',
1552
- value: 'chat.chat_name',
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: 'Ticket ID',
1566
- value: 'ticket.ticket_id',
1567
- validTriggers: ['ticket.updated', 'ticket.created'],
1568
- },
1569
- {
1570
- label: 'Chat ID',
1571
- value: 'chat.chat_id',
1572
- validTriggers: [
1573
- 'message.created',
1574
- 'message.updated',
1575
- 'reaction.added',
1576
- 'message.flagged',
1577
- 'chat.created',
1578
- 'chat.label.updated',
1579
- 'ticket.created',
1580
- 'ticket.updated',
1581
- ],
1582
- },
1583
- {
1584
- label: 'Reaction',
1585
- value: 'reaction.reaction',
1586
- validTriggers: ['reaction.added'],
1587
- },
1588
- ];
1589
-
1590
- export const variablesExclusionList: Record<
1591
- Rule['trigger'],
1592
- Array<
1593
- | keyof AppendTypes<{ message: MessageVariablesType }, '.'>
1594
- | keyof AppendTypes<{ sender: SenderVariablesType }, '.'>
1595
- | keyof AppendTypes<{ chat: ChatVariablesType }, '.'>
1596
- | keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>
1597
- | keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>
1598
- >
1599
- > = {
1600
- 'ticket.created': ['ticket.is_deleted'],
1601
- 'chat.created': [
1602
- 'chat.chat_id',
1603
- 'chat.labels',
1604
- 'chat.has_flagged_messages',
1605
- 'chat.assigned_to',
1606
- ],
1607
- 'message.created': [
1608
- 'message.author',
1609
- 'message.performed_by',
1610
- 'message.flag_status',
1611
- 'sender.is_internal',
1612
- ],
1613
- 'ticket.updated': ['ticket.is_deleted'],
1614
- 'reaction.added': [],
1615
- 'message.updated': [],
1616
- 'message.flagged': [],
1617
- 'chat.label.updated': [],
1618
- };
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 Priority' },
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
+ allow_messages_from_org_phones?: boolean;
766
+ }
767
+
768
+ export type SendMessageAction = {
769
+ id: string;
770
+ type: 'send_message';
771
+ metadata: {
772
+ message: string;
773
+ media?: {
774
+ url: string;
775
+ type: 'image' | 'video' | 'audio' | 'document';
776
+ name: string;
777
+ };
778
+ maintain_flag_status: 'true' | 'false';
779
+ debounce_messages: 'true' | 'false';
780
+ debounce_message_time:
781
+ | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
782
+ | null
783
+ | undefined;
784
+ };
785
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
786
+ };
787
+
788
+ export type NotifyHttpAction = {
789
+ id: string;
790
+ type: 'notify_http';
791
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
792
+ metadata: {
793
+ url: string;
794
+ };
795
+ };
796
+
797
+ export type CreateTicketAction = {
798
+ id: string;
799
+ type: 'create_ticket';
800
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
801
+ metadata: {
802
+ priority?: '0' | '1' | '2' | '3' | '4';
803
+ label?: string;
804
+ append_to_latest_ticket?: 'true' | 'false';
805
+ round_robin?: 'true' | 'false';
806
+ assignee?: string;
807
+ };
808
+ };
809
+
810
+ export type FlagMessageAction = {
811
+ id: string;
812
+ type: 'flag_message';
813
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
814
+ metadata: {
815
+ flag: 'true' | 'false';
816
+ };
817
+ };
818
+
819
+ export type AssignTicketAction = {
820
+ id: string;
821
+ type: 'assign_ticket';
822
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
823
+ metadata: {
824
+ assignee: string;
825
+ round_robin: 'true' | 'false';
826
+ };
827
+ };
828
+
829
+ export type CloseTicketAction = {
830
+ id: string;
831
+ type: 'close_ticket';
832
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
833
+ metadata: {
834
+ closing_note: string;
835
+ };
836
+ };
837
+
838
+ export type AddChatLabelAction = {
839
+ id: string;
840
+ type: 'add_chat_label';
841
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
842
+ metadata: {
843
+ label: string;
844
+ };
845
+ };
846
+
847
+ export type AddTicketLabelAction = {
848
+ id: string;
849
+ type: 'add_ticket_label';
850
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
851
+ metadata: {
852
+ label: string;
853
+ };
854
+ };
855
+
856
+ export type AssignChatAction = {
857
+ id: string;
858
+ type: 'assign_chat';
859
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
860
+ metadata: {
861
+ assignee: string;
862
+ round_robin: 'true' | 'false';
863
+ };
864
+ };
865
+
866
+ export type ForwardMessageAction = {
867
+ id: string;
868
+ type: 'forward_message';
869
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
870
+ metadata: {
871
+ chat_id: string;
872
+ prefix: string;
873
+ };
874
+ };
875
+
876
+ export type SendEmailAction = {
877
+ id: string;
878
+ type: 'send_email';
879
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
880
+ metadata: {
881
+ email: string;
882
+ subject: string;
883
+ body: string;
884
+ };
885
+ };
886
+
887
+ export type ReplyToMessageAction = {
888
+ id: string;
889
+ type: 'reply_to_message';
890
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
891
+ metadata: {
892
+ message: string;
893
+ media?: {
894
+ url: string;
895
+ type: 'image' | 'video' | 'audio' | 'document';
896
+ name: string;
897
+ };
898
+ maintain_flag_status: 'true' | 'false';
899
+ debounce_messages: 'true' | 'false';
900
+ debounce_message_time:
901
+ | `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`
902
+ | null
903
+ | undefined;
904
+ };
905
+ };
906
+
907
+ export type UpdateCustomPropertyAction = {
908
+ id: string;
909
+ type: 'update_custom_property';
910
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
911
+ metadata: {
912
+ property_id: string;
913
+ value: string;
914
+ };
915
+ };
916
+
917
+ export type DeleteMessageAction = {
918
+ id: string;
919
+ type: 'delete_message';
920
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
921
+ metadata: {};
922
+ };
923
+
924
+ export type SendSlackNotificationAction = {
925
+ id: string;
926
+ type: 'send_slack_notification';
927
+ delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
928
+ metadata: {
929
+ slack_payload: string;
930
+ webhook_url: string;
931
+ };
932
+ };
933
+
934
+ export type Action =
935
+ | SendMessageAction
936
+ | NotifyHttpAction
937
+ | CreateTicketAction
938
+ | FlagMessageAction
939
+ | AssignTicketAction
940
+ | CloseTicketAction
941
+ | AddChatLabelAction
942
+ | AddTicketLabelAction
943
+ | AssignChatAction
944
+ | ForwardMessageAction
945
+ | SendEmailAction
946
+ | ReplyToMessageAction
947
+ | UpdateCustomPropertyAction
948
+ | DeleteMessageAction
949
+ | SendSlackNotificationAction;
950
+
951
+ export const isSendMessageOrReplyToMessageAction = (
952
+ action: Action
953
+ ): action is SendMessageAction | ReplyToMessageAction => {
954
+ return ['send_message', 'reply_to_message'].includes(action.type);
955
+ };
956
+
957
+ export type Rule = OverrideProperties<
958
+ Tables<'tbl_automation_rules'>,
959
+ {
960
+ actions: Action[];
961
+ conditions: Conditions;
962
+ trigger:
963
+ | 'message.created'
964
+ | 'message.updated'
965
+ | 'chat.created'
966
+ | 'ticket.updated'
967
+ | 'ticket.created'
968
+ | 'reaction.added'
969
+ | 'chat.label.updated'
970
+ | 'message.flagged';
971
+ }
972
+ >;
973
+
974
+ export const RuleNameMap: Record<
975
+ Rule['trigger'],
976
+ {
977
+ title: string;
978
+ description: string;
979
+ base_conditions: {
980
+ org_phone: boolean;
981
+ };
982
+ }
983
+ > = {
984
+ 'message.created': {
985
+ title: 'New Message Received',
986
+ description: 'When a new message is received from an external contact',
987
+ base_conditions: {
988
+ org_phone: true,
989
+ },
990
+ },
991
+ 'chat.created': {
992
+ title: 'New Chat Created',
993
+ description: 'When a new chat is created',
994
+ base_conditions: {
995
+ org_phone: true,
996
+ },
997
+ },
998
+ 'ticket.created': {
999
+ title: 'New Ticket Created',
1000
+ description: 'When a new ticket is created',
1001
+ base_conditions: {
1002
+ org_phone: false,
1003
+ },
1004
+ },
1005
+ 'reaction.added': {
1006
+ title: 'New Reaction Added',
1007
+ description: 'When a reaction is added on a message',
1008
+ base_conditions: {
1009
+ org_phone: true,
1010
+ },
1011
+ },
1012
+ 'message.updated': {
1013
+ title: 'Message Updated',
1014
+ description: 'When a message is updated',
1015
+ base_conditions: {
1016
+ org_phone: true,
1017
+ },
1018
+ },
1019
+ 'ticket.updated': {
1020
+ title: 'Ticket Updated',
1021
+ description: 'When a ticket is updated',
1022
+ base_conditions: {
1023
+ org_phone: false,
1024
+ },
1025
+ },
1026
+ 'chat.label.updated': {
1027
+ title: 'Chat Label Added/Removed',
1028
+ description: 'When labels on chats are updated',
1029
+ base_conditions: {
1030
+ org_phone: false,
1031
+ },
1032
+ },
1033
+ 'message.flagged': {
1034
+ title: 'Message Flagged',
1035
+ description: 'When a message is flagged',
1036
+ base_conditions: {
1037
+ org_phone: true,
1038
+ },
1039
+ },
1040
+ };
1041
+
1042
+ export const ActionNameMap: Record<
1043
+ Action['type'],
1044
+ {
1045
+ title: string;
1046
+ description: string;
1047
+ inputs: Record<
1048
+ string,
1049
+ {
1050
+ id: string;
1051
+ type:
1052
+ | 'text'
1053
+ | 'dropdown'
1054
+ | 'editor'
1055
+ | 'date'
1056
+ | 'file'
1057
+ | 'textarea'
1058
+ | 'dynamic'
1059
+ | 'json_editor';
1060
+ value:
1061
+ | 'ticket.labels'
1062
+ | 'org.members'
1063
+ | 'chat.labels'
1064
+ | 'org.chats'
1065
+ | {
1066
+ id: string;
1067
+ value: string;
1068
+ label: string;
1069
+ }[]
1070
+ | null
1071
+ | 'org.custom_properties'
1072
+ | 'custom_property_values'
1073
+ | 'debounce_messages';
1074
+ label: string;
1075
+ placeholder: string;
1076
+ info?: string;
1077
+ required: boolean;
1078
+ }
1079
+ >;
1080
+ validTriggers: Rule['trigger'][];
1081
+ }
1082
+ > = {
1083
+ send_message: {
1084
+ title: 'Send Message',
1085
+ description: 'Send a message',
1086
+ inputs: {
1087
+ message: {
1088
+ id: 'message',
1089
+ type: 'editor',
1090
+ label: 'Message',
1091
+ placeholder: 'Enter message',
1092
+ value: null,
1093
+ required: true,
1094
+ },
1095
+ media: {
1096
+ id: 'media',
1097
+ type: 'file',
1098
+ label: 'Media',
1099
+ placeholder: 'Upload media',
1100
+ value: null,
1101
+ required: false,
1102
+ },
1103
+ maintain_flag_status: {
1104
+ id: 'maintain_flag_status',
1105
+ type: 'dropdown',
1106
+ label: 'Maintain Flag Status',
1107
+ placeholder: 'Select...',
1108
+ value: [
1109
+ { id: 'true', value: 'true', label: 'True' },
1110
+ { id: 'false', value: 'false', label: 'False' },
1111
+ ],
1112
+ required: true,
1113
+ },
1114
+ debounce_messages: {
1115
+ id: 'debounce_messages',
1116
+ type: 'dropdown',
1117
+ label: 'Enable Cooldown Period',
1118
+ placeholder: 'Select...',
1119
+ value: [
1120
+ { id: 'true', value: 'true', label: 'True' },
1121
+ { id: 'false', value: 'false', label: 'False' },
1122
+ ],
1123
+ info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1124
+ required: false,
1125
+ },
1126
+ debounce_message_time: {
1127
+ id: 'debounce_message_time',
1128
+ type: 'dynamic',
1129
+ label: 'Cooldown Period',
1130
+ placeholder: 'Enter time',
1131
+ value: 'debounce_messages',
1132
+ required: false,
1133
+ },
1134
+ },
1135
+ validTriggers: [
1136
+ 'message.created',
1137
+ 'message.updated',
1138
+ 'chat.created',
1139
+ 'ticket.updated',
1140
+ 'ticket.created',
1141
+ 'reaction.added',
1142
+ 'message.flagged',
1143
+ 'chat.label.updated',
1144
+ ],
1145
+ },
1146
+ reply_to_message: {
1147
+ title: 'Reply to message',
1148
+ description: 'Send a message with the quoted message',
1149
+ inputs: {
1150
+ message: {
1151
+ id: 'message',
1152
+ type: 'editor',
1153
+ label: 'Message',
1154
+ placeholder: 'Enter message',
1155
+ value: null,
1156
+ required: true,
1157
+ },
1158
+ media: {
1159
+ id: 'media',
1160
+ type: 'file',
1161
+ label: 'Media',
1162
+ placeholder: 'Upload media',
1163
+ value: null,
1164
+ required: false,
1165
+ },
1166
+ maintain_flag_status: {
1167
+ id: 'maintain_flag_status',
1168
+ type: 'dropdown',
1169
+ label: 'Maintain Flag Status',
1170
+ placeholder: 'Select...',
1171
+ value: [
1172
+ { id: 'true', value: 'true', label: 'True' },
1173
+ { id: 'false', value: 'false', label: 'False' },
1174
+ ],
1175
+ required: true,
1176
+ },
1177
+ debounce_messages: {
1178
+ id: 'debounce_messages',
1179
+ type: 'dropdown',
1180
+ label: 'Enable Cooldown Period',
1181
+ placeholder: 'Select...',
1182
+ value: [
1183
+ { id: 'true', value: 'true', label: 'True' },
1184
+ { id: 'false', value: 'false', label: 'False' },
1185
+ ],
1186
+ info: 'If enabled, only one message per chat will be sent in the specified cooldown period',
1187
+ required: false,
1188
+ },
1189
+ debounce_message_time: {
1190
+ id: 'debounce_message_time',
1191
+ type: 'dynamic',
1192
+ label: 'Cooldown Period',
1193
+ placeholder: 'Enter time',
1194
+ value: 'debounce_messages',
1195
+ required: false,
1196
+ },
1197
+ },
1198
+ validTriggers: [
1199
+ 'message.created',
1200
+ 'message.updated',
1201
+ 'reaction.added',
1202
+ 'message.flagged',
1203
+ ],
1204
+ },
1205
+ delete_message: {
1206
+ title: 'Delete Message',
1207
+ description: 'Delete a message',
1208
+ inputs: {},
1209
+ validTriggers: [
1210
+ 'message.created',
1211
+ 'message.updated',
1212
+ 'reaction.added',
1213
+ 'message.flagged',
1214
+ ],
1215
+ },
1216
+ notify_http: {
1217
+ title: 'Notify HTTP',
1218
+ description: 'Notify an HTTP endpoint',
1219
+ inputs: {
1220
+ url: {
1221
+ id: 'url',
1222
+ type: 'text',
1223
+ label: 'URL',
1224
+ placeholder: 'Enter URL',
1225
+ value: null,
1226
+ required: true,
1227
+ },
1228
+ },
1229
+ validTriggers: [
1230
+ 'message.created',
1231
+ 'message.updated',
1232
+ 'chat.created',
1233
+ 'ticket.updated',
1234
+ 'ticket.created',
1235
+ 'reaction.added',
1236
+ 'message.flagged',
1237
+ 'chat.label.updated',
1238
+ ],
1239
+ },
1240
+ create_ticket: {
1241
+ title: 'Create Ticket or Attach Message To Latest Ticket',
1242
+ description: 'Create a ticket or attach message to latest ticket',
1243
+ inputs: {
1244
+ append_to_latest_ticket: {
1245
+ id: 'append_to_latest_ticket',
1246
+ type: 'dropdown',
1247
+ value: [
1248
+ { id: 'true', value: 'true', label: 'True' },
1249
+ { id: 'false', value: 'false', label: 'False' },
1250
+ ],
1251
+ label: 'Attach message to latest ticket (if available)',
1252
+ placeholder: 'Select...',
1253
+ info: 'If enabled, the message will be appended to the latest open ticket (if available) else a new ticket will be created',
1254
+ required: false,
1255
+ },
1256
+ priority: {
1257
+ id: 'priority',
1258
+ type: 'dropdown',
1259
+ value: [
1260
+ { id: '0', value: '0', label: 'No Prioriy' },
1261
+ { id: '1', value: '1', label: 'Low' },
1262
+ { id: '2', value: '2', label: 'Medium' },
1263
+ { id: '3', value: '3', label: 'High' },
1264
+ { id: '4', value: '4', label: 'Urgent' },
1265
+ ],
1266
+ label: 'Priority (New Ticket)',
1267
+ placeholder: 'Select priority',
1268
+ info: 'Only applicable for create ticket. If no priority is selected, the ticket will have no priority.',
1269
+ required: false,
1270
+ },
1271
+ label: {
1272
+ id: 'label',
1273
+ type: 'dropdown',
1274
+ value: 'ticket.labels',
1275
+ label: 'Label (New Ticket)',
1276
+ placeholder: 'Select label',
1277
+ info: 'Only applicable for create ticket. If no label is selected, the ticket will have no label.',
1278
+ required: false,
1279
+ },
1280
+ round_robin: {
1281
+ id: 'round_robin',
1282
+ type: 'dropdown',
1283
+ value: [
1284
+ { id: 'true', value: 'true', label: 'True' },
1285
+ { id: 'false', value: 'false', label: 'False' },
1286
+ ],
1287
+ label: 'Enable Round Robin (New Ticket: Assignee)',
1288
+ placeholder: 'Select...',
1289
+ info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1290
+ required: false,
1291
+ },
1292
+ assignee: {
1293
+ id: 'assignee',
1294
+ type: 'dynamic',
1295
+ value: 'org.members',
1296
+ label: 'Assignee (New Ticket)',
1297
+ placeholder: 'Select assignee',
1298
+ 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",
1299
+ required: false,
1300
+ },
1301
+ },
1302
+ validTriggers: [
1303
+ 'message.created',
1304
+ 'message.updated',
1305
+ 'reaction.added',
1306
+ 'message.flagged',
1307
+ ],
1308
+ },
1309
+ flag_message: {
1310
+ title: 'Update flag status',
1311
+ description: 'Flag/Unflag a message',
1312
+ inputs: {
1313
+ flag: {
1314
+ id: 'flag',
1315
+ type: 'dropdown',
1316
+ value: [
1317
+ { id: 'flag', value: 'true', label: 'True' },
1318
+ { id: 'unflag', value: 'false', label: 'False' },
1319
+ ],
1320
+ label: 'Flag status',
1321
+ placeholder: 'Select flag',
1322
+ required: true,
1323
+ },
1324
+ },
1325
+ validTriggers: [
1326
+ 'message.created',
1327
+ 'message.updated',
1328
+ 'reaction.added',
1329
+ 'message.flagged',
1330
+ ],
1331
+ },
1332
+ assign_ticket: {
1333
+ title: 'Assign Ticket',
1334
+ description: 'Assign a ticket',
1335
+ inputs: {
1336
+ round_robin: {
1337
+ id: 'round_robin',
1338
+ type: 'dropdown',
1339
+ value: [
1340
+ { id: 'true', value: 'true', label: 'True' },
1341
+ { id: 'false', value: 'false', label: 'False' },
1342
+ ],
1343
+ label: 'Enable Round Robin',
1344
+ placeholder: 'Select...',
1345
+ info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1346
+ required: false,
1347
+ },
1348
+ assignee: {
1349
+ id: 'assignee',
1350
+ type: 'dynamic',
1351
+ value: 'org.members',
1352
+ label: 'Assignee',
1353
+ placeholder: 'Select assignee',
1354
+ 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",
1355
+ required: true,
1356
+ },
1357
+ },
1358
+ validTriggers: ['ticket.updated', 'ticket.created'],
1359
+ },
1360
+ close_ticket: {
1361
+ title: 'Close Ticket',
1362
+ description: 'Close a ticket',
1363
+ inputs: {
1364
+ closing_note: {
1365
+ id: 'closing_note',
1366
+ type: 'textarea',
1367
+ label: 'Closing Note',
1368
+ placeholder: 'Enter closing note',
1369
+ value: null,
1370
+ required: false,
1371
+ },
1372
+ },
1373
+ validTriggers: ['ticket.updated', 'ticket.created'],
1374
+ },
1375
+ add_chat_label: {
1376
+ title: 'Add Chat Label',
1377
+ description: 'Add a label to referred chat',
1378
+ inputs: {
1379
+ label: {
1380
+ id: 'label',
1381
+ type: 'dropdown',
1382
+ value: 'chat.labels',
1383
+ label: 'Label',
1384
+ placeholder: 'Select label',
1385
+ required: true,
1386
+ },
1387
+ },
1388
+ validTriggers: [
1389
+ 'message.created',
1390
+ 'message.updated',
1391
+ 'chat.created',
1392
+ 'ticket.updated',
1393
+ 'ticket.created',
1394
+ 'reaction.added',
1395
+ 'chat.label.updated',
1396
+ 'message.flagged',
1397
+ ],
1398
+ },
1399
+ add_ticket_label: {
1400
+ title: 'Add Ticket Label',
1401
+ description: 'Add a label to referred ticket',
1402
+ inputs: {
1403
+ label: {
1404
+ id: 'label',
1405
+ type: 'dropdown',
1406
+ value: 'ticket.labels',
1407
+ label: 'Label',
1408
+ placeholder: 'Select label',
1409
+ required: true,
1410
+ },
1411
+ },
1412
+ validTriggers: ['ticket.updated', 'ticket.created'],
1413
+ },
1414
+ update_custom_property: {
1415
+ description: 'Update a chat custom property',
1416
+ title: 'Update Chat Custom Property',
1417
+ validTriggers: [
1418
+ 'message.created',
1419
+ 'message.updated',
1420
+ 'chat.created',
1421
+ 'ticket.updated',
1422
+ 'ticket.created',
1423
+ 'reaction.added',
1424
+ 'message.flagged',
1425
+ 'chat.label.updated',
1426
+ ],
1427
+ inputs: {
1428
+ property_id: {
1429
+ id: 'property_id',
1430
+ type: 'dropdown',
1431
+ value: 'org.custom_properties',
1432
+ label: 'Property',
1433
+ placeholder: 'Select property',
1434
+ required: true,
1435
+ },
1436
+ value: {
1437
+ id: 'property_id',
1438
+ type: 'dynamic',
1439
+ label: 'Value',
1440
+ placeholder: 'Enter value',
1441
+ value: 'custom_property_values',
1442
+ required: true,
1443
+ },
1444
+ },
1445
+ },
1446
+ assign_chat: {
1447
+ title: 'Assign Chat',
1448
+ description: 'Assign a chat',
1449
+ inputs: {
1450
+ round_robin: {
1451
+ id: 'round_robin',
1452
+ type: 'dropdown',
1453
+ value: [
1454
+ { id: 'true', value: 'true', label: 'True' },
1455
+ { id: 'false', value: 'false', label: 'False' },
1456
+ ],
1457
+ label: 'Enable Round Robin',
1458
+ placeholder: 'Select...',
1459
+ info: 'If enabled, the chat will be assigned to the next available agent in the list',
1460
+ required: false,
1461
+ },
1462
+ assignee: {
1463
+ id: 'assignee',
1464
+ type: 'dynamic',
1465
+ value: 'org.members',
1466
+ label: 'Assignee',
1467
+ placeholder: 'Select assignee',
1468
+ required: true,
1469
+ },
1470
+ },
1471
+ validTriggers: [
1472
+ 'message.created',
1473
+ 'message.updated',
1474
+ 'chat.created',
1475
+ 'ticket.updated',
1476
+ 'ticket.created',
1477
+ 'reaction.added',
1478
+ 'chat.label.updated',
1479
+ 'message.flagged',
1480
+ ],
1481
+ },
1482
+ forward_message: {
1483
+ title: 'Forward Message',
1484
+ description: 'Forward a message',
1485
+ inputs: {
1486
+ chat_id: {
1487
+ id: 'chat_id',
1488
+ type: 'dropdown',
1489
+ value: 'org.chats',
1490
+ label: 'Chat',
1491
+ placeholder: 'Select chat',
1492
+ required: true,
1493
+ },
1494
+ },
1495
+ validTriggers: [
1496
+ 'message.created',
1497
+ 'message.updated',
1498
+ 'ticket.updated',
1499
+ 'ticket.created',
1500
+ 'reaction.added',
1501
+ 'message.flagged',
1502
+ ],
1503
+ },
1504
+ send_email: {
1505
+ title: 'Send Email',
1506
+ description: 'Send an email',
1507
+ inputs: {
1508
+ email: {
1509
+ id: 'email',
1510
+ type: 'text',
1511
+ label: 'Email',
1512
+ placeholder: 'Enter email',
1513
+ value: null,
1514
+ required: true,
1515
+ },
1516
+ subject: {
1517
+ id: 'subject',
1518
+ type: 'editor',
1519
+ label: 'Subject',
1520
+ placeholder: 'Enter subject',
1521
+ value: null,
1522
+ required: true,
1523
+ },
1524
+ body: {
1525
+ id: 'body',
1526
+ type: 'editor',
1527
+ label: 'Body',
1528
+ placeholder: 'Enter body',
1529
+ value: null,
1530
+ required: true,
1531
+ },
1532
+ },
1533
+ validTriggers: [
1534
+ 'message.created',
1535
+ 'message.updated',
1536
+ 'chat.created',
1537
+ 'ticket.updated',
1538
+ 'ticket.created',
1539
+ 'reaction.added',
1540
+ 'message.flagged',
1541
+ 'chat.label.updated',
1542
+ ],
1543
+ },
1544
+ send_slack_notification: {
1545
+ title: 'Send Slack Webhook Notification',
1546
+ description: 'Send a slack webhook notification to a channel',
1547
+ validTriggers: [
1548
+ 'message.created',
1549
+ 'message.updated',
1550
+ 'chat.created',
1551
+ 'ticket.updated',
1552
+ 'ticket.created',
1553
+ 'reaction.added',
1554
+ 'message.flagged',
1555
+ 'chat.label.updated',
1556
+ ],
1557
+ inputs: {
1558
+ webhook_url: {
1559
+ type: 'text',
1560
+ id: 'webhook_url',
1561
+ label: 'Webhook URL',
1562
+ placeholder: 'Enter webhook URL',
1563
+ value: null,
1564
+ required: true,
1565
+ },
1566
+ slack_payload: {
1567
+ type: 'json_editor',
1568
+ id: 'slack_payload',
1569
+ label: 'Slack Notification Payload',
1570
+ placeholder: 'Enter payload',
1571
+ value: null,
1572
+ required: true,
1573
+ },
1574
+ },
1575
+ },
1576
+ };
1577
+
1578
+ type editorVariablesList =
1579
+ | 'chat.assigned_to'
1580
+ | 'chat.chat_id'
1581
+ | 'chat.chat_name'
1582
+ | 'chat.chat_type'
1583
+ | 'chat.org_phone'
1584
+ | 'chat.org_id'
1585
+ | 'chat.group_description'
1586
+ | 'ticket.assignee'
1587
+ | 'ticket.due_date'
1588
+ | 'ticket.priority'
1589
+ | 'ticket.status'
1590
+ | 'ticket.subject'
1591
+ | 'ticket.ticket_id'
1592
+ | 'ticket.raised_by'
1593
+ | 'ticket.created_at'
1594
+ | 'sender.is_internal'
1595
+ | 'sender.is_admin'
1596
+ | 'sender.contact_name'
1597
+ | 'sender.contact_id'
1598
+ | 'reaction.sender_id'
1599
+ | 'reaction.reaction'
1600
+ | 'message.message_id'
1601
+ | 'message.timestamp'
1602
+ | 'message.sender_phone'
1603
+ | 'message.message_type'
1604
+ | 'message.media'
1605
+ | 'message.body';
1606
+
1607
+ export const editorVariables: Array<{
1608
+ label: string;
1609
+ value: editorVariablesList;
1610
+ validTriggers: Rule['trigger'][];
1611
+ }> = [
1612
+ {
1613
+ label: 'Ticket ID',
1614
+ value: 'ticket.ticket_id',
1615
+ validTriggers: ['ticket.updated', 'ticket.created'],
1616
+ },
1617
+ {
1618
+ value: 'ticket.assignee',
1619
+ label: 'Ticket Assignee',
1620
+ validTriggers: ['ticket.updated', 'ticket.created'],
1621
+ },
1622
+ {
1623
+ value: 'ticket.due_date',
1624
+ label: 'Ticket Due Date',
1625
+ validTriggers: ['ticket.updated', 'ticket.created'],
1626
+ },
1627
+ {
1628
+ value: 'ticket.priority',
1629
+ label: 'Ticket Priority',
1630
+ validTriggers: ['ticket.updated', 'ticket.created'],
1631
+ },
1632
+ {
1633
+ value: 'ticket.status',
1634
+ label: 'Ticket Status',
1635
+ validTriggers: ['ticket.updated', 'ticket.created'],
1636
+ },
1637
+ {
1638
+ value: 'ticket.subject',
1639
+ label: 'Ticket Subject',
1640
+ validTriggers: ['ticket.updated', 'ticket.created'],
1641
+ },
1642
+ {
1643
+ label: 'Message Body',
1644
+ value: 'message.body',
1645
+ validTriggers: [
1646
+ 'message.created',
1647
+ 'message.updated',
1648
+ 'reaction.added',
1649
+ 'message.flagged',
1650
+ 'ticket.created',
1651
+ 'ticket.updated',
1652
+ ],
1653
+ },
1654
+ {
1655
+ value: 'message.media',
1656
+ label: 'Message Media',
1657
+ validTriggers: [
1658
+ 'message.created',
1659
+ 'message.updated',
1660
+ 'reaction.added',
1661
+ 'message.flagged',
1662
+ 'ticket.created',
1663
+ 'ticket.updated',
1664
+ ],
1665
+ },
1666
+ {
1667
+ value: 'message.message_id',
1668
+ label: 'Message ID',
1669
+ validTriggers: [
1670
+ 'message.created',
1671
+ 'message.updated',
1672
+ 'reaction.added',
1673
+ 'message.flagged',
1674
+ 'ticket.created',
1675
+ 'ticket.updated',
1676
+ ],
1677
+ },
1678
+ {
1679
+ value: 'message.message_type',
1680
+ label: 'Message Type',
1681
+ validTriggers: [
1682
+ 'message.created',
1683
+ 'message.updated',
1684
+ 'reaction.added',
1685
+ 'message.flagged',
1686
+ 'ticket.created',
1687
+ 'ticket.updated',
1688
+ ],
1689
+ },
1690
+ {
1691
+ value: 'message.sender_phone',
1692
+ label: 'Sender Phone',
1693
+ validTriggers: [
1694
+ 'message.created',
1695
+ 'message.updated',
1696
+ 'reaction.added',
1697
+ 'message.flagged',
1698
+ 'ticket.created',
1699
+ 'ticket.updated',
1700
+ ],
1701
+ },
1702
+ {
1703
+ value: 'message.timestamp',
1704
+ label: 'Message Timestamp',
1705
+ validTriggers: [
1706
+ 'message.created',
1707
+ 'message.updated',
1708
+ 'reaction.added',
1709
+ 'message.flagged',
1710
+ 'ticket.created',
1711
+ 'ticket.updated',
1712
+ ],
1713
+ },
1714
+ {
1715
+ label: 'Sender Name',
1716
+ value: 'sender.contact_name',
1717
+ validTriggers: [
1718
+ 'message.created',
1719
+ 'message.updated',
1720
+ 'reaction.added',
1721
+ 'message.flagged',
1722
+ 'ticket.created',
1723
+ 'ticket.updated',
1724
+ ],
1725
+ },
1726
+ {
1727
+ value: 'sender.is_admin',
1728
+ label: 'Sender Is Admin',
1729
+ validTriggers: [
1730
+ 'message.created',
1731
+ 'message.updated',
1732
+ 'reaction.added',
1733
+ 'message.flagged',
1734
+ 'ticket.created',
1735
+ 'ticket.updated',
1736
+ ],
1737
+ },
1738
+ {
1739
+ value: 'sender.is_internal',
1740
+ label: 'Sender Is Internal',
1741
+ validTriggers: [
1742
+ 'message.created',
1743
+ 'message.updated',
1744
+ 'reaction.added',
1745
+ 'message.flagged',
1746
+ 'ticket.created',
1747
+ 'ticket.updated',
1748
+ ],
1749
+ },
1750
+ {
1751
+ label: 'Reaction',
1752
+ value: 'reaction.reaction',
1753
+ validTriggers: ['reaction.added'],
1754
+ },
1755
+ {
1756
+ value: 'reaction.sender_id',
1757
+ label: 'Reaction Sender Phone',
1758
+ validTriggers: ['reaction.added'],
1759
+ },
1760
+ {
1761
+ label: 'Chat Name',
1762
+ value: 'chat.chat_name',
1763
+ validTriggers: [
1764
+ 'message.created',
1765
+ 'message.updated',
1766
+ 'reaction.added',
1767
+ 'message.flagged',
1768
+ 'chat.created',
1769
+ 'chat.label.updated',
1770
+ 'ticket.created',
1771
+ 'ticket.updated',
1772
+ ],
1773
+ },
1774
+ {
1775
+ value: 'chat.assigned_to',
1776
+ label: 'Chat Assigned To',
1777
+ validTriggers: [
1778
+ 'message.created',
1779
+ 'message.updated',
1780
+ 'reaction.added',
1781
+ 'message.flagged',
1782
+ 'chat.created',
1783
+ 'chat.label.updated',
1784
+ 'ticket.created',
1785
+ 'ticket.updated',
1786
+ ],
1787
+ },
1788
+ {
1789
+ value: 'chat.chat_id',
1790
+ label: 'Chat ID',
1791
+ validTriggers: [
1792
+ 'message.created',
1793
+ 'message.updated',
1794
+ 'reaction.added',
1795
+ 'message.flagged',
1796
+ 'chat.created',
1797
+ 'chat.label.updated',
1798
+ 'ticket.created',
1799
+ 'ticket.updated',
1800
+ ],
1801
+ },
1802
+ {
1803
+ value: 'chat.chat_type',
1804
+ label: 'Chat Type',
1805
+ validTriggers: [
1806
+ 'message.created',
1807
+ 'message.updated',
1808
+ 'reaction.added',
1809
+ 'message.flagged',
1810
+ 'chat.created',
1811
+ 'chat.label.updated',
1812
+ 'ticket.created',
1813
+ 'ticket.updated',
1814
+ ],
1815
+ },
1816
+ {
1817
+ value: 'chat.org_id',
1818
+ label: 'Chat Org ID',
1819
+ validTriggers: [
1820
+ 'message.created',
1821
+ 'message.updated',
1822
+ 'reaction.added',
1823
+ 'message.flagged',
1824
+ 'chat.created',
1825
+ 'chat.label.updated',
1826
+ 'ticket.created',
1827
+ 'ticket.updated',
1828
+ ],
1829
+ },
1830
+ {
1831
+ value: 'chat.org_phone',
1832
+ label: 'Chat Org Phone',
1833
+ validTriggers: [
1834
+ 'message.created',
1835
+ 'message.updated',
1836
+ 'reaction.added',
1837
+ 'message.flagged',
1838
+ 'chat.created',
1839
+ 'chat.label.updated',
1840
+ 'ticket.created',
1841
+ 'ticket.updated',
1842
+ ],
1843
+ },
1844
+ ];
1845
+
1846
+ export const variablesExclusionList: Record<
1847
+ Rule['trigger'],
1848
+ Array<
1849
+ | keyof AppendTypes<{ message: MessageVariablesType }, '.'>
1850
+ | keyof AppendTypes<{ sender: SenderVariablesType }, '.'>
1851
+ | keyof AppendTypes<{ chat: ChatVariablesType }, '.'>
1852
+ | keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>
1853
+ | keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>
1854
+ >
1855
+ > = {
1856
+ 'ticket.created': ['ticket.is_deleted'],
1857
+ 'chat.created': [
1858
+ 'chat.chat_id',
1859
+ 'chat.labels',
1860
+ 'chat.has_flagged_messages',
1861
+ 'chat.assigned_to',
1862
+ ],
1863
+ 'message.created': [
1864
+ 'message.author',
1865
+ 'message.performed_by',
1866
+ 'message.flag_status',
1867
+ 'sender.is_internal',
1868
+ ],
1869
+ 'ticket.updated': ['ticket.is_deleted'],
1870
+ 'reaction.added': [],
1871
+ 'message.updated': [],
1872
+ 'message.flagged': [],
1873
+ 'chat.label.updated': [],
1874
+ };