@periskope/types 0.6.150 → 0.6.151

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 DELETED
@@ -1,1495 +0,0 @@
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
- CONTAINS: {
138
- name: 'contains',
139
- input: true,
140
- },
141
- NCONTAINS: {
142
- name: 'does not contain',
143
- input: true,
144
- },
145
- EQ: {
146
- name: 'equals to',
147
- input: true,
148
- },
149
- NEQ: {
150
- name: 'not equals to',
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 receive 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: 'Quoted Message',
274
- filters: ['IS'],
275
- type: 'boolean',
276
- variable_type: 'boolean',
277
- },
278
- 'message.media': {
279
- text: 'Message Media',
280
- type: 'boolean',
281
- filters: ['KNOWN', 'NKNOWN'],
282
- variable_type: 'boolean',
283
- },
284
- 'message.performed_by': {
285
- text: 'Message Performed By',
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: 'text', 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: 'document', value: 'document', label: 'Document' },
328
- ],
329
- filters: ['EQ', 'NEQ'],
330
- variable_type: 'string',
331
- },
332
- 'message.author': {
333
- text: 'Message Author',
334
- type: 'string',
335
- filters: ['EQ', 'NEQ'],
336
- hidden: true,
337
- variable_type: 'string',
338
- },
339
- 'message.ack': {
340
- text: 'Message acknowledment status',
341
- type: 'dropdown',
342
- value: [
343
- { id: '0', value: 0, label: '0' },
344
- { id: '1', value: 1, label: '1' },
345
- { id: '2', value: 2, label: '2' },
346
- { id: '3', value: 3, label: '3' },
347
- ],
348
- filters: ['EQ'],
349
- variable_type: 'number',
350
- },
351
- };
352
-
353
- export const SenderVariableNameMap: Record<
354
- keyof AppendTypes<{ sender: SenderVariablesType }, '.'>,
355
- VariableNameValueType
356
- > = {
357
- 'sender.is_business': {
358
- text: 'Sender is business',
359
- type: 'boolean',
360
- filters: ['IS'],
361
- variable_type: 'boolean',
362
- },
363
- 'sender.is_enterprise': {
364
- text: 'Sender is enterprise',
365
- type: 'boolean',
366
- filters: ['IS'],
367
- variable_type: 'boolean',
368
- },
369
- 'sender.is_internal': {
370
- text: 'Sender is internal',
371
- type: 'boolean',
372
- filters: ['IS'],
373
- variable_type: 'boolean',
374
- },
375
- 'sender.contact_name': {
376
- text: 'Sender Name',
377
- type: 'string',
378
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
379
- placeholder: 'e.g. John Doe',
380
- variable_type: 'string',
381
- },
382
- 'sender.contact_id': {
383
- text: 'Sender Contact Phone',
384
- type: 'string',
385
- filters: ['EQ', 'NEQ'],
386
- placeholder: 'e.g. 919876543210',
387
- variable_type: 'string',
388
- },
389
- 'sender.labels': {
390
- text: 'Sender Labels',
391
- type: 'dropdown',
392
- value: 'org.labels',
393
- filters: ['EQ', 'NEQ'],
394
- variable_type: 'string',
395
- },
396
- 'sender.org_id': {
397
- text: 'Org ID',
398
- type: 'string',
399
- filters: ['EQ', 'NEQ'],
400
- hidden: true,
401
- variable_type: 'string',
402
- },
403
- 'sender.is_super_admin': {
404
- text: 'Sender is super admin',
405
- type: 'dropdown',
406
- filters: ['EQ', 'NEQ'],
407
- value: [
408
- {
409
- id: 'true',
410
- value: true,
411
- label: 'True',
412
- },
413
- {
414
- id: 'false',
415
- value: false,
416
- label: 'False',
417
- },
418
- ],
419
- variable_type: 'boolean',
420
- },
421
- 'sender.is_admin': {
422
- text: 'Sender is admin',
423
- type: 'dropdown',
424
- filters: ['EQ', 'NEQ'],
425
- value: [
426
- {
427
- id: 'true',
428
- value: true,
429
- label: 'True',
430
- },
431
- {
432
- id: 'false',
433
- value: false,
434
- label: 'False',
435
- },
436
- ],
437
- variable_type: 'boolean',
438
- },
439
- };
440
-
441
- export const ChatVariableNameMap: Record<
442
- keyof AppendTypes<{ chat: ChatVariablesType }, '.'>,
443
- VariableNameValueType
444
- > = {
445
- 'chat.assigned_to': {
446
- text: 'Chat Assignee',
447
- type: 'dropdown',
448
- value: 'org.members',
449
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
450
- variable_type: 'string',
451
- },
452
- 'chat.chat_name': {
453
- text: 'Chat Name',
454
- type: 'string',
455
- filters: ['EQ', 'NEQ', 'CONTAINS', 'NCONTAINS'],
456
- placeholder: 'e.g. Support Chat',
457
- variable_type: 'string',
458
- },
459
- 'chat.org_phone': {
460
- text: 'Chat Org Phone',
461
- type: 'dropdown',
462
- value: 'org.org_phones',
463
- filters: ['EQ', 'NEQ'],
464
- variable_type: 'string',
465
- },
466
- 'chat.chat_type': {
467
- text: 'Chat Type',
468
- type: 'dropdown',
469
- value: [
470
- { id: 'user', value: 'user', label: 'User' },
471
- { id: 'group', value: 'group', label: 'Group' },
472
- ],
473
- filters: ['EQ', 'NEQ'],
474
- variable_type: 'string',
475
- },
476
- 'chat.members': {
477
- text: 'Chat Members',
478
- type: 'string',
479
- filters: ['CONTAINS', 'NCONTAINS'],
480
- placeholder: 'e.g. 919876543210',
481
- variable_type: 'string',
482
- },
483
- 'chat.labels': {
484
- text: 'Chat Labels',
485
- type: 'dropdown',
486
- value: 'org.labels',
487
- filters: ['CONTAINS', 'NCONTAINS'],
488
- variable_type: 'string',
489
- },
490
- 'chat.chat_id': {
491
- text: 'Chat ID',
492
- type: 'string',
493
- filters: ['EQ', 'NEQ'],
494
- placeholder: 'e.g. 12027747916749@c.us',
495
- variable_type: 'string',
496
- },
497
- 'chat.chat_org_phones': {
498
- text: 'Chat Org Phones',
499
- type: 'dropdown',
500
- filters: ['CONTAINS', 'NCONTAINS'],
501
- hidden: true,
502
- variable_type: 'string',
503
- },
504
- 'chat.org_id': {
505
- text: 'Org ID',
506
- type: 'string',
507
- filters: [],
508
- hidden: true,
509
- variable_type: 'string',
510
- },
511
- 'chat.messages_admins_only': {
512
- text: 'Chat Messages Admins Only',
513
- type: 'boolean',
514
- filters: ['EQ', 'NEQ'],
515
- value: [
516
- {
517
- id: 'true',
518
- value: true,
519
- label: 'True',
520
- },
521
- {
522
- id: 'false',
523
- value: false,
524
- label: 'False',
525
- },
526
- ],
527
- variable_type: 'boolean',
528
- },
529
- 'chat.is_muted': {
530
- text: 'Chat is muted',
531
- type: 'boolean',
532
- filters: ['EQ', 'NEQ'],
533
- value: [
534
- {
535
- id: 'true',
536
- value: true,
537
- label: 'True',
538
- },
539
- {
540
- id: 'false',
541
- value: false,
542
- label: 'False',
543
- },
544
- ],
545
- variable_type: 'boolean',
546
- },
547
- 'chat.is_exited': {
548
- text: 'Chat is exited',
549
- type: 'boolean',
550
- filters: ['EQ', 'NEQ'],
551
- value: [
552
- {
553
- id: 'true',
554
- value: true,
555
- label: 'True',
556
- },
557
- {
558
- id: 'false',
559
- value: false,
560
- label: 'False',
561
- },
562
- ],
563
- variable_type: 'boolean',
564
- },
565
- 'chat.info_admins_only': {
566
- text: 'Chat Info Admins Only',
567
- type: 'boolean',
568
- filters: ['EQ', 'NEQ'],
569
- value: [
570
- {
571
- id: 'true',
572
- value: true,
573
- label: 'True',
574
- },
575
- {
576
- id: 'false',
577
- value: false,
578
- label: 'False',
579
- },
580
- ],
581
- variable_type: 'boolean',
582
- },
583
- 'chat.has_flagged_messages': {
584
- text: 'Chat has flagged messages',
585
- type: 'boolean',
586
- filters: ['EQ', 'NEQ'],
587
- value: [
588
- {
589
- id: 'true',
590
- value: true,
591
- label: 'True',
592
- },
593
- {
594
- id: 'false',
595
- value: false,
596
- label: 'False',
597
- },
598
- ],
599
- variable_type: 'boolean',
600
- },
601
- 'chat.group_description': {
602
- text: 'Group Description',
603
- type: 'string',
604
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
605
- placeholder: 'e.g. Group description',
606
- variable_type: 'string',
607
- },
608
- 'chat.custom_properties': {
609
- text: 'Chat Custom Properties',
610
- type: 'dropdown',
611
- value: 'org.custom_properties',
612
- filters: ['EQ', 'NEQ'],
613
- hidden: true,
614
- variable_type: 'string',
615
- },
616
- 'chat.created_at': {
617
- text: 'Chat Created At',
618
- type: 'day-time',
619
- filters: ['LT', 'LTE', 'GT', 'GTE', 'ON'],
620
- variable_type: 'day-time',
621
- },
622
- };
623
-
624
- export const TicketVariableNameMap: Record<
625
- keyof AppendTypes<{ ticket: TicketVariablesType }, '.'>,
626
- VariableNameValueType
627
- > = {
628
- 'ticket.subject': {
629
- text: 'Ticket Subject',
630
- type: 'string',
631
- filters: ['CONTAINS', 'NCONTAINS', 'EQ', 'NEQ'],
632
- placeholder: 'e.g. Test ticket',
633
- variable_type: 'string',
634
- },
635
- 'ticket.status': {
636
- text: 'Ticket Status',
637
- type: 'dropdown',
638
- value: [
639
- { id: 'open', value: 'open', label: 'Open' },
640
- { id: 'closed', value: 'closed', label: 'Closed' },
641
- { id: 'inprogress', value: 'inprogress', label: 'In progress' },
642
- ],
643
- filters: ['EQ', 'NEQ'],
644
- variable_type: 'string',
645
- },
646
- 'ticket.priority': {
647
- text: 'Ticket Priority',
648
- type: 'dropdown',
649
- value: [
650
- { id: '0', value: 0, label: 'No Prioriy' },
651
- { id: '1', value: 1, label: 'Low' },
652
- { id: '2', value: 2, label: 'Medium' },
653
- { id: '3', value: 3, label: 'High' },
654
- { id: '4', value: 4, label: 'Urgent' },
655
- ],
656
- filters: ['EQ', 'NEQ'],
657
- variable_type: 'number',
658
- },
659
- 'ticket.assignee': {
660
- text: 'Ticket Assignee',
661
- type: 'dropdown',
662
- value: 'org.members',
663
- filters: ['EQ', 'NEQ', 'KNOWN', 'NKNOWN'],
664
- variable_type: 'string',
665
- },
666
- 'ticket.labels': {
667
- text: 'Ticket Labels',
668
- type: 'dropdown',
669
- value: 'org.labels',
670
- filters: ['EQ', 'NEQ'],
671
- variable_type: 'string',
672
- },
673
- 'ticket.is_deleted': {
674
- text: 'Ticket is deleted',
675
- type: 'boolean',
676
- value: [
677
- {
678
- id: 'true',
679
- value: true,
680
- label: 'True',
681
- },
682
- {
683
- id: 'false',
684
- value: false,
685
- label: 'False',
686
- },
687
- ],
688
- filters: ['IS'],
689
- variable_type: 'boolean',
690
- },
691
- 'ticket.raised_by': {
692
- text: 'Ticket Raised By',
693
- type: 'dropdown',
694
- value: 'org.members',
695
- filters: ['EQ', 'NEQ'],
696
- variable_type: 'string',
697
- },
698
- 'ticket.due_date': {
699
- text: 'Ticket Due Date',
700
- type: 'date',
701
- filters: ['KNOWN', 'NKNOWN'],
702
- variable_type: 'date',
703
- hidden: true,
704
- },
705
- 'ticket.ticket_id': {
706
- text: 'Ticket ID',
707
- type: 'string',
708
- filters: ['EQ', 'NEQ'],
709
- hidden: true,
710
- variable_type: 'string',
711
- },
712
- 'ticket.org_id': {
713
- text: 'Org ID',
714
- type: 'string',
715
- filters: ['EQ', 'NEQ'],
716
- hidden: true,
717
- variable_type: 'string',
718
- },
719
- 'ticket.custom_properties': {
720
- text: 'Ticket Custom Properties',
721
- type: 'dropdown',
722
- value: 'org.custom_properties',
723
- filters: ['EQ', 'NEQ'],
724
- hidden: true,
725
- variable_type: 'string',
726
- },
727
- 'ticket.created_at': {
728
- text: 'Ticket Created At',
729
- type: 'day-time',
730
- filters: ['LT', 'LTE', 'GT', 'GTE', 'ON'],
731
- variable_type: 'day-time',
732
- },
733
- 'ticket.chat_id': {
734
- text: 'Chat ID',
735
- type: 'string',
736
- filters: ['EQ', 'NEQ'],
737
- hidden: true,
738
- variable_type: 'string',
739
- },
740
- };
741
-
742
- export const ReactionVariableNameMap: Record<
743
- keyof AppendTypes<{ reaction: ReactionVariablesType }, '.'>,
744
- VariableNameValueType
745
- > = {
746
- 'reaction.reaction': {
747
- text: 'Reaction',
748
- type: 'string',
749
- filters: ['EQ', 'NEQ'],
750
- placeholder: 'e.g. 👍',
751
- variable_type: 'string',
752
- },
753
- 'reaction.sender_id': {
754
- text: 'Reaction Sender Phone',
755
- type: 'string',
756
- filters: ['EQ', 'NEQ'],
757
- placeholder: 'e.g. 919876543210',
758
- variable_type: 'string',
759
- },
760
- 'reaction.message_id': {
761
- text: 'Reaction Message ID',
762
- type: 'string',
763
- filters: ['EQ', 'NEQ'],
764
- hidden: true,
765
- variable_type: 'string',
766
- },
767
- 'reaction.chat_id': {
768
- text: 'Chat ID',
769
- type: 'string',
770
- filters: ['EQ', 'NEQ'],
771
- hidden: true,
772
- variable_type: 'string',
773
- },
774
- 'reaction.reaction_id': {
775
- text: 'Reaction ID',
776
- type: 'string',
777
- filters: ['EQ', 'NEQ'],
778
- hidden: true,
779
- variable_type: 'string',
780
- },
781
- };
782
-
783
- export enum FilterConditionMap {
784
- 'CONTAINS' = 'contains',
785
- 'NCONTAINS' = 'does not contain',
786
- 'EQ' = '=',
787
- 'NEQ' = '<>',
788
- 'LT' = '<',
789
- 'LTE' = '<=',
790
- 'GT' = '>',
791
- 'GTE' = '>=',
792
- 'KNOWN' = 'is known',
793
- 'NKNOWN' = 'is not known',
794
- 'IS' = '=',
795
- 'NIS' = '<>',
796
- }
797
-
798
- interface FilterGroup {
799
- filters: Filter[];
800
- condition: 'allOf' | 'anyOf';
801
- }
802
-
803
- export interface Conditions {
804
- filters: FilterGroup[];
805
- condition: 'allOf' | 'anyOf';
806
- variables: string[];
807
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
808
- org_phones: string[];
809
- }
810
-
811
- export type SendMessageAction = {
812
- id: string;
813
- type: 'send_message';
814
- metadata: {
815
- message: string;
816
- media?: {
817
- url: string;
818
- type: 'image' | 'video' | 'audio' | 'document';
819
- name: string;
820
- };
821
- maintain_flag_status: 'true' | 'false';
822
- };
823
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
824
- };
825
-
826
- export type NotifyHttpAction = {
827
- id: string;
828
- type: 'notify_http';
829
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
830
- metadata: {
831
- url: string;
832
- };
833
- };
834
-
835
- export type CreateTicketAction = {
836
- id: string;
837
- type: 'create_ticket';
838
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
839
- metadata: {
840
- assignee?: string;
841
- priority?: '0' | '1' | '2' | '3' | '4';
842
- label?: string;
843
- };
844
- };
845
-
846
- export type FlagMessageAction = {
847
- id: string;
848
- type: 'flag_message';
849
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
850
- metadata: {
851
- flag: 'true' | 'false';
852
- };
853
- };
854
-
855
- export type AssignTicketAction = {
856
- id: string;
857
- type: 'assign_ticket';
858
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
859
- metadata: {
860
- assignee: string;
861
- round_robin: 'true' | 'false';
862
- };
863
- };
864
-
865
- export type CloseTicketAction = {
866
- id: string;
867
- type: 'close_ticket';
868
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
869
- metadata: {
870
- closing_note: string;
871
- };
872
- };
873
-
874
- export type AddChatLabelAction = {
875
- id: string;
876
- type: 'add_chat_label';
877
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
878
- metadata: {
879
- label: string;
880
- };
881
- };
882
-
883
- export type AddTicketLabelAction = {
884
- id: string;
885
- type: 'add_ticket_label';
886
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
887
- metadata: {
888
- label: string;
889
- };
890
- };
891
-
892
- export type AssignChatAction = {
893
- id: string;
894
- type: 'assign_chat';
895
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
896
- metadata: {
897
- assignee: string;
898
- round_robin: 'true' | 'false';
899
- };
900
- };
901
-
902
- export type ForwardMessageAction = {
903
- id: string;
904
- type: 'forward_message';
905
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
906
- metadata: {
907
- chat_id: string;
908
- prefix: string;
909
- };
910
- };
911
-
912
- export type SendEmailAction = {
913
- id: string;
914
- type: 'send_email';
915
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
916
- metadata: {
917
- email: string;
918
- subject: string;
919
- body: string;
920
- };
921
- };
922
-
923
- export type ReplyToMessageAction = {
924
- id: string;
925
- type: 'reply_to_message';
926
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
927
- metadata: {
928
- message: string;
929
- media?: {
930
- url: string;
931
- type: 'image' | 'video' | 'audio' | 'document';
932
- name: string;
933
- };
934
- maintain_flag_status: boolean;
935
- };
936
- };
937
-
938
- export type UpdateCustomPropertyAction = {
939
- id: string;
940
- type: 'update_custom_property';
941
- delay: `${number} ${'seconds' | 'minutes' | 'hours' | 'days'}`;
942
- metadata: {
943
- property_id: string;
944
- value: string;
945
- };
946
- };
947
-
948
- export type Action =
949
- | SendMessageAction
950
- | NotifyHttpAction
951
- | CreateTicketAction
952
- | FlagMessageAction
953
- | AssignTicketAction
954
- | CloseTicketAction
955
- | AddChatLabelAction
956
- | AddTicketLabelAction
957
- | AssignChatAction
958
- | ForwardMessageAction
959
- | SendEmailAction
960
- | ReplyToMessageAction
961
- | UpdateCustomPropertyAction;
962
-
963
- export const isSendMessageAction = (
964
- action: Action
965
- ): action is SendMessageAction => {
966
- return action.type === 'send_message';
967
- };
968
-
969
- export type Rule = OverrideProperties<
970
- Tables<'tbl_automation_rules'>,
971
- {
972
- actions: Action[];
973
- conditions: Conditions;
974
- trigger:
975
- | 'message.created'
976
- | 'message.updated'
977
- | 'chat.created'
978
- | 'ticket.updated'
979
- | 'ticket.created'
980
- | 'reaction.added'
981
- | 'chat.label.updated'
982
- | 'message.flagged';
983
- }
984
- >;
985
-
986
- export const RuleNameMap: Record<
987
- Rule['trigger'],
988
- {
989
- title: string;
990
- description: string;
991
- base_conditions: {
992
- org_phone: boolean;
993
- };
994
- }
995
- > = {
996
- 'message.created': {
997
- title: 'New Message Received',
998
- description: 'When a new message is sent or received',
999
- base_conditions: {
1000
- org_phone: true,
1001
- },
1002
- },
1003
- 'chat.created': {
1004
- title: 'New Chat Created',
1005
- description: 'When a new chat is created',
1006
- base_conditions: {
1007
- org_phone: true,
1008
- },
1009
- },
1010
- 'ticket.created': {
1011
- title: 'New Ticket Created',
1012
- description: 'When a new ticket is created',
1013
- base_conditions: {
1014
- org_phone: false,
1015
- },
1016
- },
1017
- 'reaction.added': {
1018
- title: 'New Reaction Added',
1019
- description: 'When a reaction is added on a message',
1020
- base_conditions: {
1021
- org_phone: true,
1022
- },
1023
- },
1024
- 'message.updated': {
1025
- title: 'Message Updated',
1026
- description: 'When a message is updated',
1027
- base_conditions: {
1028
- org_phone: true,
1029
- },
1030
- },
1031
- 'ticket.updated': {
1032
- title: 'Ticket Updated',
1033
- description: 'When a ticket is updated',
1034
- base_conditions: {
1035
- org_phone: false,
1036
- },
1037
- },
1038
- 'chat.label.updated': {
1039
- title: 'Chat Label Added/Removed',
1040
- description: 'When labels on chats are updated',
1041
- base_conditions: {
1042
- org_phone: false,
1043
- },
1044
- },
1045
- 'message.flagged': {
1046
- title: 'Message Flagged',
1047
- description: 'When a message is flagged',
1048
- base_conditions: {
1049
- org_phone: true,
1050
- },
1051
- },
1052
- };
1053
-
1054
- export const ActionNameMap: Record<
1055
- Action['type'],
1056
- {
1057
- title: string;
1058
- description: string;
1059
- inputs: Record<
1060
- string,
1061
- {
1062
- id: string;
1063
- type:
1064
- | 'text'
1065
- | 'dropdown'
1066
- | 'editor'
1067
- | 'date'
1068
- | 'file'
1069
- | 'textarea'
1070
- | 'dynamic';
1071
- value:
1072
- | 'ticket.labels'
1073
- | 'org.members'
1074
- | 'chat.labels'
1075
- | 'org.chats'
1076
- | {
1077
- id: string;
1078
- value: string;
1079
- label: string;
1080
- }[]
1081
- | null
1082
- | 'org.custom_properties'
1083
- | 'custom_property_values';
1084
- label: string;
1085
- placeholder: string;
1086
- info?: string;
1087
- }
1088
- >;
1089
- validTriggers: Rule['trigger'][];
1090
- }
1091
- > = {
1092
- send_message: {
1093
- title: 'Send Message',
1094
- description: 'Send a message',
1095
- inputs: {
1096
- message: {
1097
- id: 'message',
1098
- type: 'editor',
1099
- label: 'Message',
1100
- placeholder: 'Enter message',
1101
- value: null,
1102
- },
1103
- media: {
1104
- id: 'media',
1105
- type: 'file',
1106
- label: 'Media',
1107
- placeholder: 'Upload media',
1108
- value: null,
1109
- },
1110
- maintain_flag_status: {
1111
- id: 'maintain_flag_status',
1112
- type: 'dropdown',
1113
- label: 'Maintain Flag Status',
1114
- placeholder: 'Select...',
1115
- value: [
1116
- { id: 'true', value: 'true', label: 'True' },
1117
- { id: 'false', value: 'false', label: 'False' },
1118
- ],
1119
- },
1120
- },
1121
- validTriggers: [
1122
- 'message.created',
1123
- 'message.updated',
1124
- 'chat.created',
1125
- 'ticket.updated',
1126
- 'ticket.created',
1127
- 'reaction.added',
1128
- 'message.flagged',
1129
- 'chat.label.updated',
1130
- ],
1131
- },
1132
- reply_to_message: {
1133
- title: 'Reply to message',
1134
- description: 'Send a message with the quoted message',
1135
- inputs: {
1136
- message: {
1137
- id: 'message',
1138
- type: 'editor',
1139
- label: 'Message',
1140
- placeholder: 'Enter message',
1141
- value: null,
1142
- },
1143
- media: {
1144
- id: 'media',
1145
- type: 'file',
1146
- label: 'Media',
1147
- placeholder: 'Upload media',
1148
- value: null,
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
- },
1160
- },
1161
- validTriggers: [
1162
- 'message.created',
1163
- 'message.updated',
1164
- 'reaction.added',
1165
- 'message.flagged',
1166
- ],
1167
- },
1168
- notify_http: {
1169
- title: 'Notify HTTP',
1170
- description: 'Notify an HTTP endpoint',
1171
- inputs: {
1172
- url: {
1173
- id: 'url',
1174
- type: 'text',
1175
- label: 'URL',
1176
- placeholder: 'Enter URL',
1177
- value: null,
1178
- },
1179
- },
1180
- validTriggers: [
1181
- 'message.created',
1182
- 'message.updated',
1183
- 'chat.created',
1184
- 'ticket.updated',
1185
- 'ticket.created',
1186
- 'reaction.added',
1187
- 'message.flagged',
1188
- 'chat.label.updated',
1189
- ],
1190
- },
1191
- create_ticket: {
1192
- title: 'Create Ticket',
1193
- description: 'Create a ticket',
1194
- inputs: {
1195
- assignee: {
1196
- id: 'assignee',
1197
- type: 'dropdown',
1198
- value: 'org.members',
1199
- label: 'Assignee',
1200
- placeholder: 'Select assignee',
1201
- },
1202
- priority: {
1203
- id: 'priority',
1204
- type: 'dropdown',
1205
- value: [
1206
- { id: '0', value: '0', label: 'No Prioriy' },
1207
- { id: '1', value: '1', label: 'Low' },
1208
- { id: '2', value: '2', label: 'Medium' },
1209
- { id: '3', value: '3', label: 'High' },
1210
- { id: '4', value: '4', label: 'Urgent' },
1211
- ],
1212
- label: 'Priority',
1213
- placeholder: 'Select priority',
1214
- },
1215
- label: {
1216
- id: 'label',
1217
- type: 'dropdown',
1218
- value: 'ticket.labels',
1219
- label: 'Label',
1220
- placeholder: 'Select label',
1221
- },
1222
- },
1223
- validTriggers: [
1224
- 'message.created',
1225
- 'message.updated',
1226
- 'reaction.added',
1227
- 'message.flagged',
1228
- ],
1229
- },
1230
- flag_message: {
1231
- title: 'Update flag status',
1232
- description: 'Flag/Unflag a message',
1233
- inputs: {
1234
- flag: {
1235
- id: 'flag',
1236
- type: 'dropdown',
1237
- value: [
1238
- { id: 'flag', value: 'true', label: 'TRUE' },
1239
- { id: 'unflag', value: 'false', label: 'FALSE' },
1240
- ],
1241
- label: 'Flag status',
1242
- placeholder: 'Select flag',
1243
- },
1244
- },
1245
- validTriggers: ['message.created', 'message.updated', 'reaction.added'],
1246
- },
1247
- assign_ticket: {
1248
- title: 'Assign Ticket',
1249
- description: 'Assign a ticket',
1250
- inputs: {
1251
- round_robin: {
1252
- id: 'round_robin',
1253
- type: 'dropdown',
1254
- value: [
1255
- { id: 'true', value: 'true', label: 'True' },
1256
- { id: 'false', value: 'false', label: 'False' },
1257
- ],
1258
- label: 'Enable Round Robin',
1259
- placeholder: 'Select...',
1260
- info: 'If enabled, the ticket will be assigned to the next available agent in the list',
1261
- },
1262
- assignee: {
1263
- id: 'email',
1264
- type: 'dynamic',
1265
- value: 'org.members',
1266
- label: 'Assignee',
1267
- placeholder: 'Select assignee',
1268
- 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",
1269
- },
1270
- },
1271
- validTriggers: ['ticket.updated', 'ticket.created'],
1272
- },
1273
- close_ticket: {
1274
- title: 'Close Ticket',
1275
- description: 'Close a ticket',
1276
- inputs: {
1277
- closing_note: {
1278
- id: 'closing_note',
1279
- type: 'textarea',
1280
- label: 'Closing Note',
1281
- placeholder: 'Enter closing note',
1282
- value: null,
1283
- },
1284
- },
1285
- validTriggers: ['ticket.updated', 'ticket.created'],
1286
- },
1287
- add_chat_label: {
1288
- title: 'Add Chat Label',
1289
- description: 'Add a label to referred chat',
1290
- inputs: {
1291
- label: {
1292
- id: 'label',
1293
- type: 'dropdown',
1294
- value: 'chat.labels',
1295
- label: 'Label',
1296
- placeholder: 'Select label',
1297
- },
1298
- },
1299
- validTriggers: [
1300
- 'message.created',
1301
- 'message.updated',
1302
- 'chat.created',
1303
- 'ticket.updated',
1304
- 'ticket.created',
1305
- 'reaction.added',
1306
- 'chat.label.updated',
1307
- ],
1308
- },
1309
- add_ticket_label: {
1310
- title: 'Add Ticket Label',
1311
- description: 'Add a label to referred ticket',
1312
- inputs: {
1313
- label: {
1314
- id: 'label',
1315
- type: 'dropdown',
1316
- value: 'ticket.labels',
1317
- label: 'Label',
1318
- placeholder: 'Select label',
1319
- },
1320
- },
1321
- validTriggers: ['ticket.updated', 'ticket.created'],
1322
- },
1323
- update_custom_property: {
1324
- description: 'Update a chat custom property',
1325
- title: 'Update Chat Custom Property',
1326
- validTriggers: [
1327
- 'message.created',
1328
- 'message.updated',
1329
- 'chat.created',
1330
- 'ticket.updated',
1331
- 'ticket.created',
1332
- 'reaction.added',
1333
- 'message.flagged',
1334
- ],
1335
- inputs: {
1336
- property_id: {
1337
- id: 'property_id',
1338
- type: 'dropdown',
1339
- value: 'org.custom_properties',
1340
- label: 'Property',
1341
- placeholder: 'Select property',
1342
- },
1343
- value: {
1344
- id: 'property_id',
1345
- type: 'dynamic',
1346
- label: 'Value',
1347
- placeholder: 'Enter value',
1348
- value: 'custom_property_values',
1349
- },
1350
- },
1351
- },
1352
- assign_chat: {
1353
- title: 'Assign Chat',
1354
- description: 'Assign a chat',
1355
- inputs: {
1356
- round_robin: {
1357
- id: 'round_robin',
1358
- type: 'dropdown',
1359
- value: [
1360
- { id: 'true', value: 'true', label: 'True' },
1361
- { id: 'false', value: 'false', label: 'False' },
1362
- ],
1363
- label: 'Enable Round Robin',
1364
- placeholder: 'Select...',
1365
- info: 'If enabled, the chat will be assigned to the next available agent in the list',
1366
- },
1367
- assignee: {
1368
- id: 'assignee',
1369
- type: 'dynamic',
1370
- value: 'org.members',
1371
- label: 'Assignee',
1372
- placeholder: 'Select assignee',
1373
- },
1374
- },
1375
- validTriggers: [
1376
- 'message.created',
1377
- 'message.updated',
1378
- 'chat.created',
1379
- 'ticket.updated',
1380
- 'ticket.created',
1381
- 'reaction.added',
1382
- 'chat.label.updated',
1383
- ],
1384
- },
1385
- forward_message: {
1386
- title: 'Forward Message',
1387
- description: 'Forward a message',
1388
- inputs: {
1389
- chat_id: {
1390
- id: 'chat_id',
1391
- type: 'dropdown',
1392
- value: 'org.chats',
1393
- label: 'Chat',
1394
- placeholder: 'Select chat',
1395
- },
1396
- // prefix: {
1397
- // id: 'prefix',
1398
- // type: 'editor',
1399
- // label: 'Prefix',
1400
- // placeholder: 'Enter prefix',
1401
- // value: null,
1402
- // },
1403
- },
1404
- validTriggers: [
1405
- 'message.created',
1406
- 'message.updated',
1407
- 'chat.created',
1408
- 'ticket.updated',
1409
- 'ticket.created',
1410
- 'reaction.added',
1411
- 'message.flagged',
1412
- ],
1413
- },
1414
- send_email: {
1415
- title: 'Send Email',
1416
- description: 'Send an email',
1417
- inputs: {
1418
- email: {
1419
- id: 'email',
1420
- type: 'text',
1421
- label: 'Email',
1422
- placeholder: 'Enter email',
1423
- value: null,
1424
- },
1425
- subject: {
1426
- id: 'subject',
1427
- type: 'text',
1428
- label: 'Subject',
1429
- placeholder: 'Enter subject',
1430
- value: null,
1431
- },
1432
- body: {
1433
- id: 'body',
1434
- type: 'editor',
1435
- label: 'Body',
1436
- placeholder: 'Enter body',
1437
- value: null,
1438
- },
1439
- },
1440
- validTriggers: [
1441
- 'message.created',
1442
- 'message.updated',
1443
- 'chat.created',
1444
- 'ticket.updated',
1445
- 'ticket.created',
1446
- 'reaction.added',
1447
- 'message.flagged',
1448
- 'chat.label.updated',
1449
- ],
1450
- },
1451
- };
1452
-
1453
- export const editorVariables: Array<{
1454
- label: string;
1455
- value: string;
1456
- validTriggers: Rule['trigger'][];
1457
- }> = [
1458
- {
1459
- label: 'Message Body',
1460
- value: 'message.body',
1461
- validTriggers: [
1462
- 'message.created',
1463
- 'message.updated',
1464
- 'reaction.added',
1465
- 'message.flagged',
1466
- ],
1467
- },
1468
- {
1469
- label: 'Sender Name',
1470
- value: 'sender.contact_name',
1471
- validTriggers: [
1472
- 'message.created',
1473
- 'message.updated',
1474
- 'reaction.added',
1475
- 'message.flagged',
1476
- ],
1477
- },
1478
- {
1479
- label: 'Chat Name',
1480
- value: 'chat.chat_name',
1481
- validTriggers: [
1482
- 'message.created',
1483
- 'message.updated',
1484
- 'reaction.added',
1485
- 'message.flagged',
1486
- 'chat.created',
1487
- 'chat.label.updated',
1488
- ],
1489
- },
1490
- {
1491
- label: 'Ticket ID',
1492
- value: 'ticket.ticket_id',
1493
- validTriggers: ['ticket.updated', 'ticket.created'],
1494
- },
1495
- ];