@periskope/types 0.6.254 → 0.6.255

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/src/types.ts CHANGED
@@ -1,1210 +1,1229 @@
1
- import type { default as _Stripe } from 'stripe';
2
- import { Merge, OverrideProperties } from 'type-fest';
3
- import { Filter, Rule } from './rules.types';
4
- import { Tables, TablesInsert, TablesUpdate } from './supabase.types';
5
-
6
- /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
7
-
8
- /* ------------------------------ PERISKOPE TYPES ------------------------------ */
9
-
10
- export enum AllPlans {
11
- FREE_TRIAL = 'free-trial',
12
- // MONTHLY_STARTER = 'monthly-starter',
13
- // YEARLY_STARTER = 'yearly-starter',
14
- // MONTHLY_PRO = 'monthly-pro',
15
- // YEARLY_PRO = 'yearly-pro',
16
- ENTERPRISE = 'enterprise',
17
- MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
18
- YEARLY_STARTER_SINGLE = 'yearly-starter-single',
19
- MONTHLY_PRO_SINGLE = 'monthly-pro-single',
20
- YEARLY_PRO_SINGLE = 'yearly-pro-single',
21
- }
22
-
23
- export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
24
-
25
- export type Enterprise = `${string}-enterprise`;
26
-
27
- export type OrgPlanEnterprise = {
28
- subscription_id: string;
29
- plan_id: Enterprise;
30
- interval: number;
31
- frequency: Frequency;
32
- user_limit: number;
33
- phone_limit: number;
34
- current_period_start: number;
35
- current_period_end: number | null;
36
- additional_user_limit?: number;
37
- additional_phone_limit?: number;
38
- };
39
-
40
- export type OrgPlanNonEnterprise = {
41
- subscription_id: string;
42
- plan_id: AllPlans;
43
- interval: number;
44
- frequency: Frequency;
45
- user_limit: number;
46
- phone_limit: number;
47
- current_period_end: number;
48
- current_period_start: number;
49
- additional_user_limit?: number;
50
- additional_phone_limit?: number;
51
- };
52
-
53
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
54
- ? OrgPlanEnterprise
55
- : T extends AllPlans
56
- ? OrgPlanNonEnterprise
57
- : never;
58
-
59
- export type MicrosurveyData = {
60
- key: string;
61
- text: string;
62
- checked: boolean;
63
- }[];
64
-
65
- export type OrgPreferences = {
66
- disable_ai_flagging?: boolean;
67
- disable_allow_exports?: boolean;
68
- sync_phone_contacts?: boolean;
69
- mask_phone_numbers?: boolean;
70
- show_sender_names?: boolean;
71
- closed_chats?: Record<string, number>;
72
- auto_read_muted_chats?: boolean;
73
- };
74
-
75
- type OrgPreferenceKey = keyof OrgPreferences;
76
-
77
- export type OrgPreferencesValue = {
78
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
79
- }[OrgPreferenceKey];
80
-
81
- export type CustomPropertySectionType = {
82
- id: string;
83
- name: string;
84
- order: number;
85
- type: 'chat' | 'ticket';
86
- properties_order?: {
87
- [id: string]: number;
88
- };
89
- };
90
-
91
- export enum CustomPropertyValueType {
92
- DROPDOWN = 'dropdown',
93
- TEXT = 'text',
94
- DATE = 'date',
95
- FILE = 'file',
96
- PICKLIST = 'picklist',
97
- DEPENDENT_DROPDOWN = 'dependent_dropdown',
98
- }
99
-
100
- export type CustomPropertyMetadataType = {
101
- section_id?: string;
102
- };
103
-
104
- export type CustomPropertyTextPropertiesType = {
105
- property_value_type: CustomPropertyValueType.TEXT;
106
- property_value: null;
107
- property_metadata: CustomPropertyMetadataType;
108
- };
109
-
110
- export type CustomPropertyDropdownPropertiesType = {
111
- property_value_type: CustomPropertyValueType.DROPDOWN;
112
- property_value: {
113
- [key: string]: string;
114
- };
115
- property_metadata: CustomPropertyMetadataType;
116
- };
117
-
118
- export type CustomPropertyPicklistPropertiesType = {
119
- property_value_type: CustomPropertyValueType.PICKLIST;
120
- property_value: {
121
- [key: string]: string;
122
- };
123
- property_metadata: CustomPropertyMetadataType;
124
- };
125
-
126
- export type CustomPropertyDependentDropdownPropertiesType = {
127
- property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
128
- property_value: {
129
- level_1: {
130
- value: string;
131
- label: string;
132
- level_2: {
133
- value: string;
134
- label: string;
135
- level_3: {
136
- value: string;
137
- label: string;
138
- }[];
139
- }[];
140
- }[];
141
- };
142
- property_metadata: Merge<
143
- CustomPropertyMetadataType,
144
- {
145
- level_names: {
146
- level_1: string;
147
- level_2: string;
148
- level_3: string;
149
- };
150
- }
151
- >;
152
- };
153
-
154
- export type CustomPropertyFilePropertiesType = {
155
- property_value_type: CustomPropertyValueType.FILE;
156
- property_value: null;
157
- property_metadata: CustomPropertyMetadataType;
158
- };
159
-
160
- export type CustomPropertyDatePropertiesType = {
161
- property_value_type: CustomPropertyValueType.DATE;
162
- property_value: null;
163
- property_metadata: CustomPropertyMetadataType;
164
- };
165
-
166
- export type CustomPropertyType = OverrideProperties<
167
- Tables<'tbl_custom_properties'>,
168
- | CustomPropertyDependentDropdownPropertiesType
169
- | CustomPropertyTextPropertiesType
170
- | CustomPropertyDropdownPropertiesType
171
- | CustomPropertyPicklistPropertiesType
172
- | CustomPropertyFilePropertiesType
173
- | CustomPropertyDatePropertiesType
174
- >;
175
-
176
- export type OrgMetadata = {
177
- phone_number: string;
178
- ticket_prefix: string;
179
- referralSource?: string;
180
- surveyData?: MicrosurveyData;
181
- preferences?: OrgPreferences;
182
- hubspot: {
183
- hubspot_pipelines?: {
184
- id: string;
185
- label: string;
186
- default_stage: { id: string; label: string };
187
- }[];
188
- hubspot_hidden_fields?: string[];
189
- };
190
- partition?: boolean;
191
- tickets: {
192
- prefix?: string;
193
- emoji_ticketing: {
194
- is_enabled?: boolean;
195
- is_message_enabled?: boolean;
196
- message_template?: string;
197
- };
198
- };
199
- attribution?: Object;
200
- affiliate_id?: string;
201
- custom_properties?: {
202
- sections?: CustomPropertySectionType[];
203
- };
204
- rules?: {
205
- limit?: number;
206
- };
207
- ai?: {
208
- flag_prompt?: string;
209
- };
210
- display_language?: string;
211
- };
212
-
213
- export type GroupTemplateType = OverrideProperties<
214
- Tables<'tbl_group_templates'>,
215
- {
216
- group_metadata: {
217
- messagesAdminsOnly?: boolean;
218
- infoAdminsOnly?: boolean;
219
- addMembersAdminsOnly?: boolean;
220
- description?: string;
221
- admins?: string[];
222
- };
223
- }
224
- >;
225
-
226
- type AccessScopes = {
227
- feature_flags: Record<string, boolean>;
228
- integrations: boolean;
229
- rules: boolean;
230
- exports: boolean;
231
- };
232
-
233
- export type OrgMembersType = OverrideProperties<
234
- Tables<'tbl_org_members'>,
235
- {
236
- member_metadata: {
237
- shift_times: {
238
- [day in
239
- | 'monday'
240
- | 'tuesday'
241
- | 'wednesday'
242
- | 'thursday'
243
- | 'friday'
244
- | 'saturday'
245
- | 'sunday']?: [[string, string]];
246
- };
247
- override_status: boolean;
248
- [key: string]: any
249
- };
250
- }
251
- >;
252
-
253
- export type OrgType = OverrideProperties<
254
- Merge<
255
- Tables<'tbl_org'>,
256
- {
257
- user: OrgMembersType;
258
- members: OrgMembersType[];
259
- phones: Tables<'tbl_org_phones'>[];
260
- labels: Tables<'tbl_org_labels'>[];
261
- quick_replies: Tables<'tbl_quick_replies'>[];
262
- custom_properties: CustomPropertyType[];
263
- subscription_status: 'active' | 'inactive' | 'unpaid';
264
- is_enterprise: boolean;
265
- is_free_trial: boolean;
266
- is_hubspot_connected: boolean;
267
- is_freshdesk_connected: boolean;
268
- is_zohodesk_connected: boolean;
269
- access_scopes: AccessScopes;
270
- rules: Rule[];
271
- phone_limit: number;
272
- user_limit: number;
273
- }
274
- >,
275
- {
276
- org_plan: OrgPlan<AllPlans | Enterprise>;
277
- stripe_customer_details: _Stripe.Customer | null;
278
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
279
- stripe_customer_id: _Stripe.Customer['id'] | null;
280
- org_metadata: OrgMetadata;
281
- }
282
- >;
283
-
284
- export type ChatMemberType = Merge<
285
- Tables<'tbl_chat_participants'>,
286
- Tables<'tbl_contacts'>
287
- >;
288
-
289
- export type ChatType = Merge<
290
- Tables<'view_chats'>,
291
- {
292
- chat_id: string;
293
- latest_message: MessageType | null;
294
- latest_message_timestamp: number | null;
295
- members: { [key: string]: ChatMemberType } | null;
296
- chat_type: 'user' | 'group' | 'business' | 'unknown';
297
- chat_access: { [key: string]: boolean };
298
- label_ids: { [key: string]: boolean };
299
- chat_org_phones?: string[];
300
- message_unread_count: number | null;
301
- hubspot_metadata: {
302
- id: string;
303
- type: string;
304
- hubId: string;
305
- object_data: HubspotObjectDataType;
306
- } | null;
307
- info_admins_only: boolean;
308
- messages_admins_only: boolean;
309
- unread_count?: { [key: string]: number };
310
- active_phone: string | null;
311
- flag_count_map?: { [key: string]: number };
312
- is_archived?: boolean;
313
- is_pinned?: boolean;
314
- closed_at?: number | null;
315
- common_chats?: string[];
316
- freshdesk_metadata?: Record<string, any>;
317
- zohodesk_metadata?: Record<string, any>;
318
- pinned_messages?: {
319
- message_id: string;
320
- pinned_at: number;
321
- expires_at: number;
322
- }[];
323
- }
324
- >;
325
-
326
- /* -------------------------------------------------------------------------- */
327
- /* MESSAGE */
328
- /* -------------------------------------------------------------------------- */
329
-
330
- export type MediaType = {
331
- path?: string;
332
- mimetype?: string;
333
- filename?: string;
334
- dimensions?: { width: number; height: number; ar: number };
335
- size?: number;
336
- thumbnail?: string;
337
- filedata?: string;
338
- compress?: boolean;
339
- };
340
-
341
- export type MessageType = Merge<
342
- OverrideProperties<
343
- TablesInsert<'tbl_chat_messages'>,
344
- {
345
- message_id: string;
346
- org_id: string;
347
- org_phone: string;
348
- chat_id: string;
349
- message_type: (typeof SUPPORTED_TYPES)[number];
350
- media: MediaType | null;
351
- flag_metadata?: MessageFlagType | null;
352
- poll_info?: PollSendType | null;
353
- poll_results?: PollResultType | null;
354
- delivery_info?: DeliveryInfoType | null;
355
- raw_data?: {
356
- translations?: Record<string, string>;
357
- [key: string]: unknown;
358
- } | null;
359
- }
360
- >,
361
- {
362
- reactions?: ReactionType[];
363
- message_payload?: SingleMessagePayload;
364
- highlight?: number;
365
- is_private_note?: boolean;
366
- }
367
- >;
368
-
369
- export type MessageFlagType = {
370
- status: boolean;
371
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
372
- response_id?: string;
373
- response_timestamp?: string;
374
- response_email?: string;
375
- flagged_by?: string;
376
- flagged_at?: string;
377
- };
378
-
379
- export type MessageSendType = {
380
- queue_id: string;
381
- queue_position: string;
382
- };
383
-
384
- export type MessageBroadcastType = {
385
- broadcast_id: string;
386
- };
387
-
388
- /* -------------------------------------------------------------------------- */
389
-
390
- export type TicketType = OverrideProperties<
391
- Tables<'tbl_chat_tickets'>,
392
- {
393
- label_ids: { [key: string]: boolean };
394
- hubspot_metadata: {
395
- id?: string;
396
- type?: string;
397
- hubId?: string;
398
- pipeline: {
399
- id: string;
400
- label: string;
401
- };
402
- object_data?: HubspotObjectDataType;
403
- } | null;
404
- freshdesk_metadata: Record<string, string>;
405
- close_ticket_metadata?:
406
- | {
407
- closed_by: string;
408
- closed_at: string;
409
- closed_message?: string | null;
410
- send_reply_message_id?: string | null;
411
- }
412
- | any;
413
- }
414
- >;
415
-
416
- export type ContactType = Merge<
417
- Tables<'tbl_contacts'>,
418
- {
419
- chats: ChatType[] | null;
420
- chat_ids?: string[];
421
- }
422
- >;
423
- export type ReactionType = Tables<'tbl_chat_reactions'>;
424
-
425
- export type NotificationType = Tables<'tbl_chat_notifications'>;
426
-
427
- export type ChatAccessType = Merge<
428
- TablesUpdate<'tbl_org_members'>,
429
- {
430
- has_access?: boolean;
431
- email: string | null;
432
- }
433
- >;
434
-
435
- export type QueueJobTypes = {
436
- addedTimestamp: number;
437
- attemptsMade: number;
438
- attemptsStarted: number;
439
- data: {
440
- body: string;
441
- chat_id: string;
442
- };
443
- finishedTimestamp: number;
444
- id: string;
445
- message_id: string;
446
- processedTimestamp: number;
447
- stacktrace: string[];
448
- status: string;
449
- };
450
-
451
- export type PhoneQueueStatusType = {
452
- active: number;
453
- failed: number;
454
- completed: number;
455
- is_running: boolean;
456
- pending: number;
457
- };
458
-
459
- export type PhoneType = OverrideProperties<
460
- Tables<'tbl_org_phones'>,
461
- {
462
- queue_status: {
463
- [key: string]: PhoneQueueStatusType;
464
- };
465
- }
466
- >;
467
-
468
- export type PhoneInfoType = Merge<
469
- Pick<
470
- PhoneType,
471
- | 'created_at'
472
- | 'first_connected_at'
473
- | 'is_ready'
474
- | 'label_ids'
475
- | 'org_id'
476
- | 'org_phone'
477
- | 'phone_id'
478
- | 'phone_image'
479
- | 'phone_name'
480
- | 'qr_code'
481
- | 'updated_at'
482
- | 'wa_state'
483
- >,
484
- {
485
- labels: string[];
486
- }
487
- >;
488
-
489
- /* -------------------------------- CONSTANTS ------------------------------- */
490
-
491
- export const labelColors = [
492
- '#9333EA',
493
- '#0D9488',
494
- '#DB2777',
495
- '#2563EB',
496
- '#F97316',
497
- ];
498
-
499
- export const enumChatColors = [
500
- '#B4876E',
501
- '#A5B337',
502
- '#06CF9C',
503
- '#25D366',
504
- '#02A698',
505
- '#7D9EF1',
506
- '#007BFC',
507
- '#5E47DE',
508
- '#7F66FF',
509
- '#9333EA',
510
- '#FA6533',
511
- '#C4532D',
512
- '#DC2626',
513
- '#FF2E74',
514
- '#DB2777',
515
- ] as const;
516
-
517
- export type RepeatDaysType =
518
- | 'monday'
519
- | 'tuesday'
520
- | 'wednesday'
521
- | 'thursday'
522
- | 'friday'
523
- | 'saturday'
524
- | 'sunday';
525
- export type RepeatIntervalType = 'day' | 'week' | 'month';
526
-
527
- /* -------------------------- LISTING ENDPOINT -------------------------- */
528
-
529
- type ListingType = {
530
- from?: number;
531
- to?: number;
532
- count?: number;
533
- };
534
-
535
- export type ListNotificationsType = Merge<
536
- ListingType,
537
- {
538
- notifictions?: NotificationType[];
539
- }
540
- >;
541
-
542
- export type ListChatMessagesType = Merge<
543
- ListingType,
544
- {
545
- messages?: MessageType[];
546
- }
547
- >;
548
-
549
- export type ListContactsType = Merge<
550
- ListingType,
551
- {
552
- contacts?: ContactType[];
553
- }
554
- >;
555
-
556
- export type ListTicketsType = Merge<
557
- ListingType,
558
- {
559
- tickets?: TicketType[];
560
- }
561
- >;
562
-
563
- export type ListChatsType = Merge<
564
- ListingType,
565
- {
566
- chats?: ChatType[];
567
- }
568
- >;
569
-
570
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
571
-
572
- export const SUPPORTED_TYPES = [
573
- 'chat',
574
- 'sticker',
575
- 'image',
576
- 'video',
577
- 'document',
578
- 'vcard',
579
- 'multi_vcard',
580
- 'audio',
581
- 'ptt',
582
- 'poll_creation',
583
- 'location',
584
- 'ciphertext',
585
- ] as const;
586
-
587
- export type SendMessageContent = {
588
- message_type?: (typeof SUPPORTED_TYPES)[number];
589
- body?: string;
590
- media?: MediaType;
591
- contact_ids?: string[];
592
- location?: {
593
- latitude: string;
594
- longitude: string;
595
- options?: { name?: string; address?: string; url?: string };
596
- };
597
- poll?: PollSendType;
598
- quoted_message_id?: string;
599
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
600
- broadcast_id?: string;
601
- performed_by?: string;
602
- options?: Record<string, any>;
603
- };
604
-
605
- export type QuickReplyContent = Omit<
606
- SendMessageContent,
607
- 'broadcast_id' | 'variables'
608
- >;
609
-
610
- export type ScheduleMessagePayload = {
611
- scheduled_id?: string;
612
- is_repeat?: boolean | null;
613
- scheduled_at: string;
614
- repeat_config?: {
615
- timezone?: string;
616
- repeat_ends?: string;
617
- repeat_interval?: RepeatIntervalType;
618
- repeat_value?: number;
619
- repeat_days?: RepeatDaysType[];
620
- };
621
- };
622
-
623
- export type BroadcastVariableType = {
624
- chat_id: string;
625
- values: { [key: string]: string };
626
- };
627
-
628
- export type BroadcastMessagePayload = SendMessageContent & {
629
- chat_ids: string[];
630
- broadcast_id?: string;
631
- variables?: BroadcastVariableType[];
632
- delay?: number;
633
- };
634
-
635
- export type SingleMessagePayload = SendMessageContent & {
636
- chat_id: string;
637
- job_id?: string;
638
- priority?: number;
639
- };
640
-
641
- export type MessageAttachmentFileTypes =
642
- | 'image'
643
- | 'audio'
644
- | 'document'
645
- | 'video';
646
-
647
- export type AttachmentFileType = {
648
- result: string;
649
- file: File | null;
650
- type: MessageAttachmentFileTypes;
651
- localFileURL?: string;
652
- };
653
-
654
- export type AttachmentLinkType = {
655
- link: {
656
- url: string;
657
- type: MessageAttachmentFileTypes;
658
- name: string;
659
- mimetype?: string;
660
- };
661
- };
662
-
663
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
664
-
665
- /* -------------------------------- BROADCAST ------------------------------- */
666
-
667
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
668
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
669
- } & {
670
- chats: ChatType[];
671
- };
672
-
673
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
674
-
675
- export type ChatLogType = {
676
- log: Tables<'view_chat_logs'>;
677
- operations: Tables<'tbl_chat_logs'>[];
678
- };
679
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
680
-
681
- export type ChatParticipantOperationPayload = {
682
- participant_ids: string[];
683
- chat_ids: string[];
684
- performed_by: string;
685
- };
686
-
687
- export type ChatOperationReturn = {
688
- [participant_id: string]: {
689
- is_success: boolean;
690
- message?: string;
691
- code?: number;
692
- isInviteV4Sent?: boolean;
693
- };
694
- };
695
-
696
- /* ----------------------- BILLING - STRIPE ----------------------- */
697
-
698
- export type StripeSubscription = _Stripe.Subscription;
699
- export type StripeCustomer = _Stripe.Customer;
700
- export type StripeCoupon = _Stripe.Coupon;
701
- export type StripePrice = _Stripe.Price;
702
- export type Stripe = _Stripe;
703
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
704
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
705
-
706
- /* -------------------------------- REALTIME -------------------------------- */
707
-
708
- export type PhoneStateType = {
709
- loading: boolean;
710
- state: string;
711
- sync: number;
712
- percent: number | null;
713
- message?: string;
714
- error?: string;
715
- };
716
-
717
- /* ------------------------------- INTEGRATIONS ----------------------------- */
718
-
719
- export type ChatInfoType = Merge<
720
- ChatType,
721
- {
722
- members: {
723
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
724
- } | null;
725
- chat_labels: string | null;
726
- custom_properties: { [key: string]: string } | null;
727
- }
728
- >;
729
-
730
- export type TicketInfoType = {
731
- chat: ChatInfoType;
732
- message: {
733
- body: string;
734
- chat_id: string;
735
- org_phone: string;
736
- timestamp: string;
737
- media_path: string;
738
- message_id: string;
739
- sender_name: string;
740
- performed_by: string;
741
- sender_phone: string;
742
- };
743
- ticket: {
744
- org_id: string;
745
- status: string;
746
- subject: string;
747
- assignee: string;
748
- due_date: string;
749
- priority: 0 | 1 | 2 | 3 | 4;
750
- raised_by: string;
751
- ticket_id: string;
752
- created_at: string;
753
- assigned_by: string;
754
- ticket_labels: string;
755
- quoted_message_id: string;
756
- ticket_custom_properties: { [key: string]: string } | null;
757
- };
758
- attached_messages: {
759
- body: string;
760
- chat_id: string;
761
- org_phone: string;
762
- timestamp: string;
763
- media_path: string;
764
- message_id: string;
765
- sender_name: string;
766
- performed_by: string;
767
- sender_phone: string;
768
- }[];
769
- };
770
-
771
- export type IntegrationLogObjectType =
772
- | 'chat'
773
- | 'message'
774
- | 'reaction'
775
- | 'ticket'
776
- | 'phone';
777
- export enum IntegrationLogType {
778
- NEW_CHAT = 'chat.created',
779
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
780
- NEW_MESSAGE = 'message.created',
781
- MESSAGE_UPDATED = 'message.updated',
782
- MESSAGE_DELETED = 'message.deleted',
783
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
784
- REACTION_CREATED = 'reaction.created',
785
- REACTION_UPDATED = 'reaction.updated',
786
- NEW_TICKET = 'ticket.created',
787
- TICKET_UPDATED = 'ticket.updated',
788
- TICKET_DELETED = 'ticket.deleted',
789
- MESSAGE_FLAGGED = 'message.flagged',
790
- MESSAGE_UNFLAGGED = 'message.unflagged',
791
- PHONE_DISCONNECTED = 'org.phone.disconnected',
792
- PHONE_CONNECTED = 'org.phone.connected',
793
- PHONE_UPDATED = 'org.phone.updated',
794
- PHONE_QR_UPDATED = 'org.phone.qr',
795
- }
796
-
797
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
798
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
799
- ? TicketInfoType
800
- : T extends IntegrationLogType.NEW_CHAT
801
- ? Tables<'tbl_chats'>
802
- : T extends
803
- | IntegrationLogType.NEW_MESSAGE
804
- | IntegrationLogType.MESSAGE_UPDATED
805
- | IntegrationLogType.MESSAGE_DELETED
806
- | IntegrationLogType.MESSAGE_ACK_UPDATED
807
- | IntegrationLogType.MESSAGE_FLAGGED
808
- | IntegrationLogType.MESSAGE_UNFLAGGED
809
- ? Tables<'tbl_chat_messages'>
810
- : T extends
811
- | IntegrationLogType.REACTION_CREATED
812
- | IntegrationLogType.REACTION_UPDATED
813
- ? Tables<'tbl_chat_reactions'>
814
- : T extends
815
- | IntegrationLogType.PHONE_DISCONNECTED
816
- | IntegrationLogType.PHONE_CONNECTED
817
- | IntegrationLogType.PHONE_UPDATED
818
- | IntegrationLogType.PHONE_QR_UPDATED
819
- ? Tables<'tbl_org_phones'>
820
- : {
821
- [key: string]: unknown;
822
- };
823
-
824
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
825
- OverrideProperties<
826
- Tables<'tbl_integration_logs'>,
827
- {
828
- integration_name: T;
829
- metadata: {
830
- event: IntegrationLogMetadataType<T> & {
831
- event_type: string;
832
- org_id: string;
833
- previous_attributes: {
834
- [key: string]: unknown;
835
- };
836
- };
837
- hook_id: string;
838
- name: string;
839
- };
840
- }
841
- >;
842
-
843
- export type APIAuthDetails = {
844
- org_details: Tables<'view_org'> | null;
845
- phone_details: Tables<'tbl_org_phones'> | null;
846
- token_details: Tables<'tbl_integration_tokens'> | null;
847
- };
848
-
849
- export type WebhookDataType = OverrideProperties<
850
- Tables<'tbl_integration_hooks'>,
851
- {
852
- integration_name: string[];
853
- }
854
- >;
855
-
856
- export type HubspotObjectDataType = {
857
- createdAt: string;
858
- archived: boolean;
859
- id: string;
860
- type: 'contacts' | 'tickets' | 'companies';
861
- properties: Record<
862
- string,
863
- {
864
- groupLabel: string;
865
- groupName: string;
866
- propertyKeyName: string;
867
- propertyKey: string;
868
- propertyInternalValue: string;
869
- propertyValue: string;
870
- propertyType: string;
871
- propertyFieldType: string;
872
- }[]
873
- >;
874
- };
875
-
876
- /* ---------------------------- USER PREFERENCES ---------------------------- */
877
-
878
- export type UserPreferences = {
879
- theme: 'light' | 'dark';
880
- language: 'en' | 'es';
881
- left_sidebar_open: boolean;
882
- right_sidepanel_open: boolean;
883
- sync_wa_unread_count: boolean;
884
- pinned_chats: string[];
885
- archived_chats: string[];
886
- closed_chats: Record<string, number>;
887
- periskope_chat_limit: number;
888
- notifications: Record<string, boolean>;
889
- };
890
-
891
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
892
-
893
- export type PollSendType = {
894
- pollName: string;
895
- pollOptions: string[];
896
- options?: {
897
- allowMultipleAnswers?: boolean;
898
- messageSecret?: number[] | null;
899
- pollId?: string;
900
- };
901
- };
902
-
903
- export type PollResultType = {
904
- [name: string]: Record<string, string>;
905
- };
906
-
907
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
908
-
909
- export type CreateGroupOptions = {
910
- messagesAdminsOnly?: boolean;
911
- infoAdminsOnly?: boolean;
912
- addMembersAdminsOnly?: boolean;
913
- image?: string;
914
- name?: string;
915
- description?: string;
916
- initiated_by?: string;
917
- admins?: string[];
918
- };
919
-
920
- /* ------------------------------ DELIVERY INFO ----------------------------- */
921
-
922
- export type DeliveryInfoType = {
923
- delivered: Record<string, number | undefined>;
924
- read: Record<string, number | undefined>;
925
- pending: string[];
926
- read_count: number;
927
- delivered_count: number;
928
- };
929
-
930
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
931
-
932
- export type OrgCreditsType = {
933
- org_id: string;
934
- recurring_allowance: number; // recurring credits replenished every cycle
935
- recurring_balance: number; // recurring credits remaining in current cycle
936
- topup_balance: number; // topup credits remaining
937
- total_credits_used: number; // total credits used in current cycle
938
- next_renewal_date: string;
939
- topup_credits_used: number; // topup credits used in current cycle
940
- recurring_credits_used: number; // recurring credits used in current cycle
941
- };
942
-
943
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
944
-
945
- export type ChatRuleInfoType = Merge<
946
- Pick<
947
- Tables<'view_chats'>,
948
- | 'assigned_to'
949
- | 'chat_id'
950
- | 'chat_name'
951
- | 'chat_type'
952
- | 'created_at'
953
- | 'group_description'
954
- | 'info_admins_only'
955
- | 'org_id'
956
- | 'org_phone'
957
- | 'chat_org_phones'
958
- | 'messages_admins_only'
959
- | 'custom_properties'
960
- | 'initiated_by'
961
- >,
962
- {
963
- has_flagged_messages: boolean;
964
- labels: string[];
965
- members: string[];
966
- custom_properties: { [key: string]: string } | null;
967
- }
968
- >;
969
-
970
- export type SenderRuleInfoType = Merge<
971
- Omit<
972
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
973
- | 'verified_name'
974
- | 'verified_level'
975
- | 'updated_at'
976
- | 'short_name'
977
- | 'pushname'
978
- | 'periskope_name'
979
- | 'org_phone'
980
- | 'number'
981
- | 'name'
982
- | 'label_ids'
983
- | 'is_wa_contact'
984
- | 'is_user'
985
- | 'is_my_contact'
986
- | 'is_me'
987
- | 'is_imported'
988
- | 'is_group'
989
- | 'is_blocked'
990
- | 'contact_color'
991
- | 'business_profile'
992
- | 'id'
993
- | 'contact_image'
994
- | 'contact_type'
995
- | 'chat_id'
996
- | 'is_business'
997
- | 'is_enterprise'
998
- | 'is_super_admin'
999
- >,
1000
- {
1001
- is_internal: boolean;
1002
- labels: string[] | null;
1003
- }
1004
- >;
1005
-
1006
- export type MessageRuleInfoType = {
1007
- chat: ChatRuleInfoType;
1008
- sender: SenderRuleInfoType;
1009
- message: OverrideProperties<
1010
- Omit<
1011
- Tables<'tbl_chat_messages'>,
1012
- | 'vcards'
1013
- | 'updated_at'
1014
- | 'unique_id'
1015
- | 'token'
1016
- | 'to'
1017
- | 'sent_message_id'
1018
- | 'raw_data'
1019
- | 'delivery_info'
1020
- | 'poll_results'
1021
- | 'poll_info'
1022
- | 'order_id'
1023
- | 'mentioned_ids'
1024
- | 'media_key'
1025
- | 'location'
1026
- | 'links'
1027
- | 'is_status'
1028
- | 'is_starred'
1029
- | 'is_gif'
1030
- | 'is_forwarded'
1031
- | 'is_ephemeral'
1032
- | 'is_deleted'
1033
- | 'fts'
1034
- | 'quoted_message_id'
1035
- | 'invite_v4'
1036
- | 'id'
1037
- | 'has_reaction'
1038
- | 'has_media'
1039
- | 'duration'
1040
- | 'broadcast'
1041
- | 'broadcast_id'
1042
- | 'device_type'
1043
- | 'forwarding_score'
1044
- | 'from'
1045
- | 'from_me'
1046
- | 'prev_body'
1047
- | 'flag_response_time'
1048
- | 'flag_metadata'
1049
- | 'ack'
1050
- >,
1051
- {
1052
- media: MediaType | null;
1053
- }
1054
- >;
1055
- };
1056
-
1057
- export type ReactionRuleInfoType = {
1058
- chat: ChatRuleInfoType;
1059
- sender: SenderRuleInfoType;
1060
- message: MessageRuleInfoType['message'];
1061
- reaction: Pick<
1062
- Tables<'tbl_chat_reactions'>,
1063
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1064
- >;
1065
- };
1066
-
1067
- export type TicketRuleInfoType = {
1068
- chat: ChatRuleInfoType;
1069
- sender: SenderRuleInfoType;
1070
- ticket: Merge<
1071
- Pick<
1072
- Tables<'tbl_chat_tickets'>,
1073
- | 'org_id'
1074
- | 'status'
1075
- | 'chat_id'
1076
- | 'subject'
1077
- | 'assignee'
1078
- | 'due_date'
1079
- | 'priority'
1080
- | 'raised_by'
1081
- | 'ticket_id'
1082
- | 'created_at'
1083
- | 'is_deleted'
1084
- >,
1085
- {
1086
- labels: string[] | null;
1087
- custom_properties: { [key: string]: string } | null;
1088
- }
1089
- >;
1090
- message: MessageRuleInfoType['message'];
1091
- };
1092
- export type FeatureFlagReturnType = Record<string, boolean>;
1093
-
1094
- export type RuleLogsType = OverrideProperties<
1095
- Tables<'tbl_rules_logs'>,
1096
- {
1097
- actions_progress: {
1098
- action_id: string;
1099
- action_type: Rule['actions'][number]['type'];
1100
- action_delay: Rule['actions'][number]['delay'];
1101
- ran_at: string | null;
1102
- action_status: 'success' | 'failed' | 'pending';
1103
- action_response: {
1104
- success: boolean;
1105
- data: Record<string, unknown> | null;
1106
- error: {
1107
- message: string;
1108
- name: string;
1109
- stack?: string;
1110
- _error?: Error | Record<string, unknown>;
1111
- } | null;
1112
- };
1113
- }[];
1114
- metadata: {
1115
- conditions: Rule['conditions'];
1116
- actions: Rule['actions'];
1117
- rule_metadata: Pick<
1118
- Rule,
1119
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1120
- >;
1121
- data: Record<string, unknown>;
1122
- };
1123
- conditions_progress: {
1124
- is_valid: boolean;
1125
- validation_progress: Record<
1126
- string,
1127
- {
1128
- res: boolean;
1129
- filter: Filter;
1130
- value: unknown;
1131
- }
1132
- >;
1133
- checked_at: string | null;
1134
- };
1135
- }
1136
- >;
1137
-
1138
- /************************** TASKS ***************************/
1139
-
1140
- export type TaskType = OverrideProperties<
1141
- Tables<'tbl_org_tasks'>,
1142
- {
1143
- reminder_setting: {
1144
- remind_in:
1145
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1146
- | string
1147
- | null;
1148
- repeat?: {
1149
- frequency: number;
1150
- interval: 'days' | 'weeks' | 'months' | 'years';
1151
- end: 'never' | 'after' | 'on';
1152
- on?: string;
1153
- };
1154
- } | null;
1155
- associated_object_metadata:
1156
- | {
1157
- type: 'chat';
1158
- index: 'chat_id';
1159
- id: string;
1160
- object: ChatType;
1161
- }
1162
- | {
1163
- type: 'message';
1164
- index: 'message_id';
1165
- id: string;
1166
- object: MessageType;
1167
- }
1168
- | {
1169
- type: 'ticket';
1170
- index: 'ticket_id';
1171
- id: string;
1172
- object: TicketType;
1173
- }
1174
- | null;
1175
- status: 'open' | 'inprogress' | 'closed';
1176
- priority: 1 | 2 | 3;
1177
- completed_metadata?: {
1178
- completed_at: string;
1179
- completed_by: string;
1180
- } | null;
1181
- type: 'todo' | 'chat' | 'message' | 'ticket';
1182
- }
1183
- >;
1184
-
1185
- type Choice = {
1186
- id: number;
1187
- label: string;
1188
- value: string;
1189
- position: number;
1190
- };
1191
-
1192
- export type FreshdeskCustomFieldType = {
1193
- id: number;
1194
- name: string;
1195
- label: string;
1196
- position: number;
1197
- required_for_agents: boolean;
1198
- archived: boolean;
1199
- customers_can_edit: boolean;
1200
- label_for_customers: string;
1201
- required_for_customers: boolean;
1202
- customers_can_filter: boolean;
1203
- required_for_closure: boolean;
1204
- displayed_to_customers: boolean;
1205
- type: string;
1206
- default: boolean;
1207
- created_at: string;
1208
- updated_at: string;
1209
- choices?: Choice[];
1210
- };
1
+ import type { default as _Stripe } from 'stripe';
2
+ import { Merge, OverrideProperties } from 'type-fest';
3
+ import { Filter, Rule } from './rules.types';
4
+ import { Tables, TablesInsert, TablesUpdate } from './supabase.types';
5
+
6
+ /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
7
+
8
+ /* ------------------------------ PERISKOPE TYPES ------------------------------ */
9
+
10
+ export enum AllPlans {
11
+ FREE_TRIAL = 'free-trial',
12
+ // MONTHLY_STARTER = 'monthly-starter',
13
+ // YEARLY_STARTER = 'yearly-starter',
14
+ // MONTHLY_PRO = 'monthly-pro',
15
+ // YEARLY_PRO = 'yearly-pro',
16
+ ENTERPRISE = 'enterprise',
17
+ MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
18
+ YEARLY_STARTER_SINGLE = 'yearly-starter-single',
19
+ MONTHLY_PRO_SINGLE = 'monthly-pro-single',
20
+ YEARLY_PRO_SINGLE = 'yearly-pro-single',
21
+ }
22
+
23
+ export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
24
+
25
+ export type Enterprise = `${string}-enterprise`;
26
+
27
+ export type OrgPlanEnterprise = {
28
+ subscription_id: string;
29
+ plan_id: Enterprise;
30
+ interval: number;
31
+ frequency: Frequency;
32
+ user_limit: number;
33
+ phone_limit: number;
34
+ current_period_start: number;
35
+ current_period_end: number | null;
36
+ additional_user_limit?: number;
37
+ additional_phone_limit?: number;
38
+ };
39
+
40
+ export type OrgPlanNonEnterprise = {
41
+ subscription_id: string;
42
+ plan_id: AllPlans;
43
+ interval: number;
44
+ frequency: Frequency;
45
+ user_limit: number;
46
+ phone_limit: number;
47
+ current_period_end: number;
48
+ current_period_start: number;
49
+ additional_user_limit?: number;
50
+ additional_phone_limit?: number;
51
+ };
52
+
53
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
54
+ ? OrgPlanEnterprise
55
+ : T extends AllPlans
56
+ ? OrgPlanNonEnterprise
57
+ : never;
58
+
59
+ export type MicrosurveyData = {
60
+ key: string;
61
+ text: string;
62
+ checked: boolean;
63
+ }[];
64
+
65
+ export type OrgPreferences = {
66
+ disable_ai_flagging?: boolean;
67
+ disable_allow_exports?: boolean;
68
+ sync_phone_contacts?: boolean;
69
+ mask_phone_numbers?: boolean;
70
+ show_sender_names?: boolean;
71
+ closed_chats?: Record<string, number>;
72
+ auto_read_muted_chats?: boolean;
73
+ };
74
+
75
+ type OrgPreferenceKey = keyof OrgPreferences;
76
+
77
+ export type OrgPreferencesValue = {
78
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
79
+ }[OrgPreferenceKey];
80
+
81
+ export type CustomPropertySectionType = {
82
+ id: string;
83
+ name: string;
84
+ order: number;
85
+ type: 'chat' | 'ticket';
86
+ properties_order?: {
87
+ [id: string]: number;
88
+ };
89
+ };
90
+
91
+ export enum CustomPropertyValueType {
92
+ DROPDOWN = 'dropdown',
93
+ TEXT = 'text',
94
+ DATE = 'date',
95
+ FILE = 'file',
96
+ PICKLIST = 'picklist',
97
+ DEPENDENT_DROPDOWN = 'dependent_dropdown',
98
+ }
99
+
100
+ export type CustomPropertyMetadataType = {
101
+ section_id?: string;
102
+ };
103
+
104
+ export type CustomPropertyTextPropertiesType = {
105
+ property_value_type: CustomPropertyValueType.TEXT;
106
+ property_value: null;
107
+ property_metadata: CustomPropertyMetadataType;
108
+ };
109
+
110
+ export type CustomPropertyDropdownPropertiesType = {
111
+ property_value_type: CustomPropertyValueType.DROPDOWN;
112
+ property_value: {
113
+ [key: string]: string;
114
+ };
115
+ property_metadata: CustomPropertyMetadataType;
116
+ };
117
+
118
+ export type CustomPropertyPicklistPropertiesType = {
119
+ property_value_type: CustomPropertyValueType.PICKLIST;
120
+ property_value: {
121
+ [key: string]: string;
122
+ };
123
+ property_metadata: CustomPropertyMetadataType;
124
+ };
125
+
126
+ export type CustomPropertyDependentDropdownPropertiesType = {
127
+ property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
128
+ property_value: {
129
+ level_1: {
130
+ value: string;
131
+ label: string;
132
+ level_2: {
133
+ value: string;
134
+ label: string;
135
+ level_3: {
136
+ value: string;
137
+ label: string;
138
+ }[];
139
+ }[];
140
+ }[];
141
+ };
142
+ property_metadata: Merge<
143
+ CustomPropertyMetadataType,
144
+ {
145
+ level_names: {
146
+ level_1: string;
147
+ level_2: string;
148
+ level_3: string;
149
+ };
150
+ }
151
+ >;
152
+ };
153
+
154
+ export type CustomPropertyFilePropertiesType = {
155
+ property_value_type: CustomPropertyValueType.FILE;
156
+ property_value: null;
157
+ property_metadata: CustomPropertyMetadataType;
158
+ };
159
+
160
+ export type CustomPropertyDatePropertiesType = {
161
+ property_value_type: CustomPropertyValueType.DATE;
162
+ property_value: null;
163
+ property_metadata: CustomPropertyMetadataType;
164
+ };
165
+
166
+ export type CustomPropertyType = OverrideProperties<
167
+ Tables<'tbl_custom_properties'>,
168
+ | CustomPropertyDependentDropdownPropertiesType
169
+ | CustomPropertyTextPropertiesType
170
+ | CustomPropertyDropdownPropertiesType
171
+ | CustomPropertyPicklistPropertiesType
172
+ | CustomPropertyFilePropertiesType
173
+ | CustomPropertyDatePropertiesType
174
+ >;
175
+
176
+ export type OrgMetadata = {
177
+ phone_number: string;
178
+ ticket_prefix: string;
179
+ referralSource?: string;
180
+ surveyData?: MicrosurveyData;
181
+ preferences?: OrgPreferences;
182
+ hubspot: {
183
+ hubspot_pipelines?: {
184
+ id: string;
185
+ label: string;
186
+ default_stage: { id: string; label: string };
187
+ }[];
188
+ hubspot_hidden_fields?: string[];
189
+ };
190
+ partition?: boolean;
191
+ tickets: {
192
+ prefix?: string;
193
+ emoji_ticketing: {
194
+ is_enabled?: boolean;
195
+ is_message_enabled?: boolean;
196
+ message_template?: string;
197
+ };
198
+ };
199
+ attribution?: Object;
200
+ affiliate_id?: string;
201
+ custom_properties?: {
202
+ sections?: CustomPropertySectionType[];
203
+ };
204
+ rules?: {
205
+ limit?: number;
206
+ };
207
+ ai?: {
208
+ flag_prompt?: string;
209
+ };
210
+ display_language?: string;
211
+ };
212
+
213
+ export type GroupTemplateType = OverrideProperties<
214
+ Tables<'tbl_group_templates'>,
215
+ {
216
+ group_metadata: {
217
+ messagesAdminsOnly?: boolean;
218
+ infoAdminsOnly?: boolean;
219
+ addMembersAdminsOnly?: boolean;
220
+ description?: string;
221
+ admins?: string[];
222
+ };
223
+ }
224
+ >;
225
+
226
+ type AccessScopes = {
227
+ feature_flags: Record<string, boolean>;
228
+ integrations: boolean;
229
+ rules: boolean;
230
+ exports: boolean;
231
+ };
232
+
233
+ export type OrgMembersType = OverrideProperties<
234
+ Tables<'tbl_org_members'>,
235
+ {
236
+ member_metadata: {
237
+ shift_times: {
238
+ [day in
239
+ | 'monday'
240
+ | 'tuesday'
241
+ | 'wednesday'
242
+ | 'thursday'
243
+ | 'friday'
244
+ | 'saturday'
245
+ | 'sunday']?: [[string, string]];
246
+ };
247
+ override_status: boolean;
248
+ [key: string]: any;
249
+ };
250
+ }
251
+ >;
252
+
253
+ export type OrgType = OverrideProperties<
254
+ Merge<
255
+ Tables<'tbl_org'>,
256
+ {
257
+ user: OrgMembersType;
258
+ members: OrgMembersType[];
259
+ phones: Tables<'tbl_org_phones'>[];
260
+ labels: Tables<'tbl_org_labels'>[];
261
+ quick_replies: Tables<'tbl_quick_replies'>[];
262
+ custom_properties: CustomPropertyType[];
263
+ subscription_status: 'active' | 'inactive' | 'unpaid';
264
+ is_enterprise: boolean;
265
+ is_free_trial: boolean;
266
+ is_hubspot_connected: boolean;
267
+ is_freshdesk_connected: boolean;
268
+ is_zohodesk_connected: boolean;
269
+ access_scopes: AccessScopes;
270
+ rules: Rule[];
271
+ }
272
+ >,
273
+ {
274
+ org_plan: OrgPlan<AllPlans | Enterprise>;
275
+ stripe_customer_details: _Stripe.Customer | null;
276
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
277
+ stripe_customer_id: _Stripe.Customer['id'] | null;
278
+ org_metadata: OrgMetadata;
279
+ }
280
+ >;
281
+
282
+ export type ChatMemberType = Merge<
283
+ Tables<'tbl_chat_participants'>,
284
+ Tables<'tbl_contacts'>
285
+ >;
286
+
287
+ export type ChatType = Merge<
288
+ Tables<'view_chats'>,
289
+ {
290
+ chat_id: string;
291
+ latest_message: MessageType | null;
292
+ latest_message_timestamp: number | null;
293
+ members: { [key: string]: ChatMemberType } | null;
294
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
295
+ chat_access: { [key: string]: boolean };
296
+ label_ids: { [key: string]: boolean };
297
+ chat_org_phones?: string[];
298
+ message_unread_count: number | null;
299
+ hubspot_metadata: {
300
+ id: string;
301
+ type: string;
302
+ hubId: string;
303
+ object_data: HubspotObjectDataType;
304
+ } | null;
305
+ info_admins_only: boolean;
306
+ messages_admins_only: boolean;
307
+ unread_count?: { [key: string]: number };
308
+ active_phone: string | null;
309
+ flag_count_map?: { [key: string]: number };
310
+ is_archived?: boolean;
311
+ is_pinned?: boolean;
312
+ closed_at?: number | null;
313
+ common_chats?: string[];
314
+ freshdesk_metadata?: Record<string, any>;
315
+ zohodesk_metadata?: Record<string, any>;
316
+ pinned_messages?: {
317
+ message_id: string;
318
+ pinned_at: number;
319
+ expires_at: number;
320
+ }[];
321
+ }
322
+ >;
323
+
324
+ /* -------------------------------------------------------------------------- */
325
+ /* MESSAGE */
326
+ /* -------------------------------------------------------------------------- */
327
+
328
+ export type MediaType = {
329
+ path?: string;
330
+ mimetype?: string;
331
+ filename?: string;
332
+ dimensions?: { width: number; height: number; ar: number };
333
+ size?: number;
334
+ thumbnail?: string;
335
+ filedata?: string;
336
+ compress?: boolean;
337
+ };
338
+
339
+ export type MessageType = Merge<
340
+ OverrideProperties<
341
+ TablesInsert<'tbl_chat_messages'>,
342
+ {
343
+ message_id: string;
344
+ org_id: string;
345
+ org_phone: string;
346
+ chat_id: string;
347
+ message_type: (typeof SUPPORTED_TYPES)[number];
348
+ media: MediaType | null;
349
+ flag_metadata?: MessageFlagType | null;
350
+ poll_info?: PollSendType | null;
351
+ poll_results?: PollResultType | null;
352
+ delivery_info?: DeliveryInfoType | null;
353
+ raw_data?: {
354
+ translations?: Record<string, string>;
355
+ [key: string]: unknown;
356
+ } | null;
357
+ }
358
+ >,
359
+ {
360
+ reactions?: ReactionType[];
361
+ message_payload?: SingleMessagePayload;
362
+ highlight?: number;
363
+ is_private_note?: boolean;
364
+ }
365
+ >;
366
+
367
+ export type MessageFlagType = {
368
+ status: boolean;
369
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
370
+ response_id?: string;
371
+ response_timestamp?: string;
372
+ response_email?: string;
373
+ flagged_by?: string;
374
+ flagged_at?: string;
375
+ };
376
+
377
+ export type MessageSendType = {
378
+ queue_id: string;
379
+ queue_position: string;
380
+ };
381
+
382
+ export type MessageBroadcastType = {
383
+ broadcast_id: string;
384
+ };
385
+
386
+ /* -------------------------------------------------------------------------- */
387
+
388
+ export type TicketType = OverrideProperties<
389
+ Tables<'tbl_chat_tickets'>,
390
+ {
391
+ label_ids: { [key: string]: boolean };
392
+ hubspot_metadata: {
393
+ id?: string;
394
+ type?: string;
395
+ hubId?: string;
396
+ pipeline: {
397
+ id: string;
398
+ label: string;
399
+ };
400
+ object_data?: HubspotObjectDataType;
401
+ } | null;
402
+ freshdesk_metadata: Record<string, string>;
403
+ close_ticket_metadata?:
404
+ | {
405
+ closed_by: string;
406
+ closed_at: string;
407
+ closed_message?: string | null;
408
+ send_reply_message_id?: string | null;
409
+ }
410
+ | any;
411
+ }
412
+ >;
413
+
414
+ export type ContactType = Merge<
415
+ Tables<'tbl_contacts'>,
416
+ {
417
+ chats: ChatType[] | null;
418
+ chat_ids?: string[];
419
+ }
420
+ >;
421
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
422
+
423
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
424
+
425
+ export type ChatAccessType = Merge<
426
+ TablesUpdate<'tbl_org_members'>,
427
+ {
428
+ has_access?: boolean;
429
+ email: string | null;
430
+ }
431
+ >;
432
+
433
+ export type QueueJobTypes = {
434
+ addedTimestamp: number;
435
+ attemptsMade: number;
436
+ attemptsStarted: number;
437
+ data: {
438
+ body: string;
439
+ chat_id: string;
440
+ };
441
+ finishedTimestamp: number;
442
+ id: string;
443
+ message_id: string;
444
+ processedTimestamp: number;
445
+ stacktrace: string[];
446
+ status: string;
447
+ };
448
+
449
+ export type PhoneQueueStatusType = {
450
+ active: number;
451
+ failed: number;
452
+ completed: number;
453
+ is_running: boolean;
454
+ pending: number;
455
+ };
456
+
457
+ export type PhoneType = OverrideProperties<
458
+ Tables<'tbl_org_phones'>,
459
+ {
460
+ queue_status: {
461
+ [key: string]: PhoneQueueStatusType;
462
+ };
463
+ }
464
+ >;
465
+
466
+ export type PhoneInfoType = Merge<
467
+ Pick<
468
+ PhoneType,
469
+ | 'created_at'
470
+ | 'first_connected_at'
471
+ | 'is_ready'
472
+ | 'label_ids'
473
+ | 'org_id'
474
+ | 'org_phone'
475
+ | 'phone_id'
476
+ | 'phone_image'
477
+ | 'phone_name'
478
+ | 'qr_code'
479
+ | 'updated_at'
480
+ | 'wa_state'
481
+ >,
482
+ {
483
+ labels: string[];
484
+ }
485
+ >;
486
+
487
+ /* -------------------------------- CONSTANTS ------------------------------- */
488
+
489
+ export const labelColors = [
490
+ '#9333EA',
491
+ '#0D9488',
492
+ '#DB2777',
493
+ '#2563EB',
494
+ '#F97316',
495
+ ];
496
+
497
+ export const enumChatColors = [
498
+ '#B4876E',
499
+ '#A5B337',
500
+ '#06CF9C',
501
+ '#25D366',
502
+ '#02A698',
503
+ '#7D9EF1',
504
+ '#007BFC',
505
+ '#5E47DE',
506
+ '#7F66FF',
507
+ '#9333EA',
508
+ '#FA6533',
509
+ '#C4532D',
510
+ '#DC2626',
511
+ '#FF2E74',
512
+ '#DB2777',
513
+ ] as const;
514
+
515
+ export type RepeatDaysType =
516
+ | 'monday'
517
+ | 'tuesday'
518
+ | 'wednesday'
519
+ | 'thursday'
520
+ | 'friday'
521
+ | 'saturday'
522
+ | 'sunday';
523
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
524
+
525
+ /* -------------------------- LISTING ENDPOINT -------------------------- */
526
+
527
+ type ListingType = {
528
+ from?: number;
529
+ to?: number;
530
+ count?: number;
531
+ };
532
+
533
+ export type ListNotificationsType = Merge<
534
+ ListingType,
535
+ {
536
+ notifictions?: NotificationType[];
537
+ }
538
+ >;
539
+
540
+ export type ListChatMessagesType = Merge<
541
+ ListingType,
542
+ {
543
+ messages?: MessageType[];
544
+ }
545
+ >;
546
+
547
+ export type ListContactsType = Merge<
548
+ ListingType,
549
+ {
550
+ contacts?: ContactType[];
551
+ }
552
+ >;
553
+
554
+ export type ListTicketsType = Merge<
555
+ ListingType,
556
+ {
557
+ tickets?: TicketType[];
558
+ }
559
+ >;
560
+
561
+ export type ListChatsType = Merge<
562
+ ListingType,
563
+ {
564
+ chats?: ChatType[];
565
+ }
566
+ >;
567
+
568
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
569
+
570
+ export const SUPPORTED_TYPES = [
571
+ 'chat',
572
+ 'sticker',
573
+ 'image',
574
+ 'video',
575
+ 'document',
576
+ 'vcard',
577
+ 'multi_vcard',
578
+ 'audio',
579
+ 'ptt',
580
+ 'poll_creation',
581
+ 'location',
582
+ 'ciphertext',
583
+ ] as const;
584
+
585
+ export type SendMessageContent = {
586
+ message_type?: (typeof SUPPORTED_TYPES)[number];
587
+ body?: string;
588
+ media?: MediaType;
589
+ contact_ids?: string[];
590
+ location?: {
591
+ latitude: string;
592
+ longitude: string;
593
+ options?: { name?: string; address?: string; url?: string };
594
+ };
595
+ poll?: PollSendType;
596
+ quoted_message_id?: string;
597
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
598
+ broadcast_id?: string;
599
+ performed_by?: string;
600
+ options?: Record<string, any>;
601
+ };
602
+
603
+ export type QuickReplyContent = Omit<
604
+ SendMessageContent,
605
+ 'broadcast_id' | 'variables'
606
+ >;
607
+
608
+ export type ScheduleMessagePayload = {
609
+ scheduled_id?: string;
610
+ is_repeat?: boolean | null;
611
+ scheduled_at: string;
612
+ repeat_config?: {
613
+ timezone?: string;
614
+ repeat_ends?: string;
615
+ repeat_interval?: RepeatIntervalType;
616
+ repeat_value?: number;
617
+ repeat_days?: RepeatDaysType[];
618
+ };
619
+ };
620
+
621
+ export type BroadcastVariableType = {
622
+ chat_id: string;
623
+ values: { [key: string]: string };
624
+ };
625
+
626
+ export type BroadcastMessagePayload = SendMessageContent & {
627
+ chat_ids: string[];
628
+ broadcast_id?: string;
629
+ variables?: BroadcastVariableType[];
630
+ delay?: number;
631
+ };
632
+
633
+ export type SingleMessagePayload = SendMessageContent & {
634
+ chat_id: string;
635
+ job_id?: string;
636
+ priority?: number;
637
+ };
638
+
639
+ export type MessageAttachmentFileTypes =
640
+ | 'image'
641
+ | 'audio'
642
+ | 'document'
643
+ | 'video';
644
+
645
+ export type AttachmentFileType = {
646
+ result: string;
647
+ file: File | null;
648
+ type: MessageAttachmentFileTypes;
649
+ localFileURL?: string;
650
+ };
651
+
652
+ export type AttachmentLinkType = {
653
+ link: {
654
+ url: string;
655
+ type: MessageAttachmentFileTypes;
656
+ name: string;
657
+ mimetype?: string;
658
+ };
659
+ };
660
+
661
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
662
+
663
+ /* -------------------------------- BROADCAST ------------------------------- */
664
+
665
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
666
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
667
+ } & {
668
+ chats: ChatType[];
669
+ };
670
+
671
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
672
+
673
+ export type ChatLogType = {
674
+ log: Tables<'view_chat_logs'>;
675
+ operations: Tables<'tbl_chat_logs'>[];
676
+ };
677
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
678
+
679
+ export type ChatParticipantOperationPayload = {
680
+ participant_ids: string[];
681
+ chat_ids: string[];
682
+ performed_by: string;
683
+ };
684
+
685
+ export type ChatOperationReturn = {
686
+ [participant_id: string]: {
687
+ is_success: boolean;
688
+ message?: string;
689
+ code?: number;
690
+ isInviteV4Sent?: boolean;
691
+ };
692
+ };
693
+
694
+ /* ----------------------- BILLING - STRIPE ----------------------- */
695
+
696
+ export type StripeSubscription = _Stripe.Subscription;
697
+ export type StripeCustomer = _Stripe.Customer;
698
+ export type StripeCoupon = _Stripe.Coupon;
699
+ export type StripePrice = _Stripe.Price;
700
+ export type Stripe = _Stripe;
701
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
702
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
703
+
704
+ /* -------------------------------- REALTIME -------------------------------- */
705
+
706
+ export type PhoneStateType = {
707
+ loading: boolean;
708
+ state: string;
709
+ sync: number;
710
+ percent: number | null;
711
+ message?: string;
712
+ error?: string;
713
+ };
714
+
715
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
716
+
717
+ export type ChatInfoType = Merge<
718
+ ChatType,
719
+ {
720
+ members: {
721
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
722
+ } | null;
723
+ chat_labels: string | null;
724
+ custom_properties: { [key: string]: string } | null;
725
+ }
726
+ >;
727
+
728
+ export type TicketInfoType = {
729
+ chat: ChatInfoType;
730
+ message: {
731
+ body: string;
732
+ chat_id: string;
733
+ org_phone: string;
734
+ timestamp: string;
735
+ media_path: string;
736
+ message_id: string;
737
+ sender_name: string;
738
+ performed_by: string;
739
+ sender_phone: string;
740
+ };
741
+ ticket: {
742
+ org_id: string;
743
+ status: string;
744
+ subject: string;
745
+ assignee: string;
746
+ due_date: string;
747
+ priority: 0 | 1 | 2 | 3 | 4;
748
+ raised_by: string;
749
+ ticket_id: string;
750
+ created_at: string;
751
+ assigned_by: string;
752
+ ticket_labels: string;
753
+ quoted_message_id: string;
754
+ ticket_custom_properties: { [key: string]: string } | null;
755
+ };
756
+ attached_messages: {
757
+ body: string;
758
+ chat_id: string;
759
+ org_phone: string;
760
+ timestamp: string;
761
+ media_path: string;
762
+ message_id: string;
763
+ sender_name: string;
764
+ performed_by: string;
765
+ sender_phone: string;
766
+ }[];
767
+ };
768
+
769
+ export type IntegrationLogObjectType =
770
+ | 'chat'
771
+ | 'message'
772
+ | 'reaction'
773
+ | 'ticket'
774
+ | 'phone';
775
+ export enum IntegrationLogType {
776
+ NEW_CHAT = 'chat.created',
777
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
778
+ NEW_MESSAGE = 'message.created',
779
+ MESSAGE_UPDATED = 'message.updated',
780
+ MESSAGE_DELETED = 'message.deleted',
781
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
782
+ REACTION_CREATED = 'reaction.created',
783
+ REACTION_UPDATED = 'reaction.updated',
784
+ NEW_TICKET = 'ticket.created',
785
+ TICKET_UPDATED = 'ticket.updated',
786
+ TICKET_DELETED = 'ticket.deleted',
787
+ MESSAGE_FLAGGED = 'message.flagged',
788
+ MESSAGE_UNFLAGGED = 'message.unflagged',
789
+ PHONE_DISCONNECTED = 'org.phone.disconnected',
790
+ PHONE_CONNECTED = 'org.phone.connected',
791
+ PHONE_UPDATED = 'org.phone.updated',
792
+ PHONE_QR_UPDATED = 'org.phone.qr',
793
+ }
794
+
795
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
796
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
797
+ ? TicketInfoType
798
+ : T extends IntegrationLogType.NEW_CHAT
799
+ ? Tables<'tbl_chats'>
800
+ : T extends
801
+ | IntegrationLogType.NEW_MESSAGE
802
+ | IntegrationLogType.MESSAGE_UPDATED
803
+ | IntegrationLogType.MESSAGE_DELETED
804
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
805
+ | IntegrationLogType.MESSAGE_FLAGGED
806
+ | IntegrationLogType.MESSAGE_UNFLAGGED
807
+ ? Tables<'tbl_chat_messages'>
808
+ : T extends
809
+ | IntegrationLogType.REACTION_CREATED
810
+ | IntegrationLogType.REACTION_UPDATED
811
+ ? Tables<'tbl_chat_reactions'>
812
+ : T extends
813
+ | IntegrationLogType.PHONE_DISCONNECTED
814
+ | IntegrationLogType.PHONE_CONNECTED
815
+ | IntegrationLogType.PHONE_UPDATED
816
+ | IntegrationLogType.PHONE_QR_UPDATED
817
+ ? Tables<'tbl_org_phones'>
818
+ : {
819
+ [key: string]: unknown;
820
+ };
821
+
822
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
823
+ OverrideProperties<
824
+ Tables<'tbl_integration_logs'>,
825
+ {
826
+ integration_name: T;
827
+ metadata: {
828
+ event: IntegrationLogMetadataType<T> & {
829
+ event_type: string;
830
+ org_id: string;
831
+ previous_attributes: {
832
+ [key: string]: unknown;
833
+ };
834
+ };
835
+ hook_id: string;
836
+ name: string;
837
+ };
838
+ }
839
+ >;
840
+
841
+ export type APIAuthDetails = {
842
+ org_details: Tables<'view_org'> | null;
843
+ phone_details: Tables<'tbl_org_phones'> | null;
844
+ token_details: Tables<'tbl_integration_tokens'> | null;
845
+ };
846
+
847
+ export type WebhookDataType = OverrideProperties<
848
+ Tables<'tbl_integration_hooks'>,
849
+ {
850
+ integration_name: string[];
851
+ }
852
+ >;
853
+
854
+ export type HubspotObjectDataType = {
855
+ createdAt: string;
856
+ archived: boolean;
857
+ id: string;
858
+ type: 'contacts' | 'tickets' | 'companies';
859
+ properties: Record<
860
+ string,
861
+ {
862
+ groupLabel: string;
863
+ groupName: string;
864
+ propertyKeyName: string;
865
+ propertyKey: string;
866
+ propertyInternalValue: string;
867
+ propertyValue: string;
868
+ propertyType: string;
869
+ propertyFieldType: string;
870
+ }[]
871
+ >;
872
+ };
873
+
874
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
875
+
876
+ export type UserPreferences = {
877
+ theme: 'light' | 'dark';
878
+ language: 'en' | 'es';
879
+ left_sidebar_open: boolean;
880
+ right_sidepanel_open: boolean;
881
+ sync_wa_unread_count: boolean;
882
+ pinned_chats: string[];
883
+ archived_chats: string[];
884
+ closed_chats: Record<string, number>;
885
+ periskope_chat_limit: number;
886
+ notifications: Record<string, boolean>;
887
+ };
888
+
889
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
890
+
891
+ export interface MostActiveMember {
892
+ sender_phone: string;
893
+ total_messages: number;
894
+ }
895
+
896
+ export interface GroupAnalyticsResult {
897
+ total_messages: number;
898
+ total_joins: number;
899
+ total_leaves: number;
900
+ total_removes: number;
901
+ total_reactions: number;
902
+ most_active_members: MostActiveMember[];
903
+ }
904
+
905
+ export interface TimeRange {
906
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
907
+ endDateTime: string;
908
+ }
909
+
910
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
911
+
912
+ export type PollSendType = {
913
+ pollName: string;
914
+ pollOptions: string[];
915
+ options?: {
916
+ allowMultipleAnswers?: boolean;
917
+ messageSecret?: number[] | null;
918
+ pollId?: string;
919
+ };
920
+ };
921
+
922
+ export type PollResultType = {
923
+ [name: string]: Record<string, string>;
924
+ };
925
+
926
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
927
+
928
+ export type CreateGroupOptions = {
929
+ messagesAdminsOnly?: boolean;
930
+ infoAdminsOnly?: boolean;
931
+ addMembersAdminsOnly?: boolean;
932
+ image?: string;
933
+ name?: string;
934
+ description?: string;
935
+ initiated_by?: string;
936
+ admins?: string[];
937
+ };
938
+
939
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
940
+
941
+ export type DeliveryInfoType = {
942
+ delivered: Record<string, number | undefined>;
943
+ read: Record<string, number | undefined>;
944
+ pending: string[];
945
+ read_count: number;
946
+ delivered_count: number;
947
+ };
948
+
949
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
950
+
951
+ export type OrgCreditsType = {
952
+ org_id: string;
953
+ recurring_allowance: number; // recurring credits replenished every cycle
954
+ recurring_balance: number; // recurring credits remaining in current cycle
955
+ topup_balance: number; // topup credits remaining
956
+ total_credits_used: number; // total credits used in current cycle
957
+ next_renewal_date: string;
958
+ topup_credits_used: number; // topup credits used in current cycle
959
+ recurring_credits_used: number; // recurring credits used in current cycle
960
+ };
961
+
962
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
963
+
964
+ export type ChatRuleInfoType = Merge<
965
+ Pick<
966
+ Tables<'view_chats'>,
967
+ | 'assigned_to'
968
+ | 'chat_id'
969
+ | 'chat_name'
970
+ | 'chat_type'
971
+ | 'created_at'
972
+ | 'group_description'
973
+ | 'info_admins_only'
974
+ | 'org_id'
975
+ | 'org_phone'
976
+ | 'chat_org_phones'
977
+ | 'messages_admins_only'
978
+ | 'custom_properties'
979
+ | 'initiated_by'
980
+ >,
981
+ {
982
+ has_flagged_messages: boolean;
983
+ labels: string[];
984
+ members: string[];
985
+ custom_properties: { [key: string]: string } | null;
986
+ }
987
+ >;
988
+
989
+ export type SenderRuleInfoType = Merge<
990
+ Omit<
991
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
992
+ | 'verified_name'
993
+ | 'verified_level'
994
+ | 'updated_at'
995
+ | 'short_name'
996
+ | 'pushname'
997
+ | 'periskope_name'
998
+ | 'org_phone'
999
+ | 'number'
1000
+ | 'name'
1001
+ | 'label_ids'
1002
+ | 'is_wa_contact'
1003
+ | 'is_user'
1004
+ | 'is_my_contact'
1005
+ | 'is_me'
1006
+ | 'is_imported'
1007
+ | 'is_group'
1008
+ | 'is_blocked'
1009
+ | 'contact_color'
1010
+ | 'business_profile'
1011
+ | 'id'
1012
+ | 'contact_image'
1013
+ | 'contact_type'
1014
+ | 'chat_id'
1015
+ | 'is_business'
1016
+ | 'is_enterprise'
1017
+ | 'is_super_admin'
1018
+ >,
1019
+ {
1020
+ is_internal: boolean;
1021
+ labels: string[] | null;
1022
+ }
1023
+ >;
1024
+
1025
+ export type MessageRuleInfoType = {
1026
+ chat: ChatRuleInfoType;
1027
+ sender: SenderRuleInfoType;
1028
+ message: OverrideProperties<
1029
+ Omit<
1030
+ Tables<'tbl_chat_messages'>,
1031
+ | 'vcards'
1032
+ | 'updated_at'
1033
+ | 'unique_id'
1034
+ | 'token'
1035
+ | 'to'
1036
+ | 'sent_message_id'
1037
+ | 'raw_data'
1038
+ | 'delivery_info'
1039
+ | 'poll_results'
1040
+ | 'poll_info'
1041
+ | 'order_id'
1042
+ | 'mentioned_ids'
1043
+ | 'media_key'
1044
+ | 'location'
1045
+ | 'links'
1046
+ | 'is_status'
1047
+ | 'is_starred'
1048
+ | 'is_gif'
1049
+ | 'is_forwarded'
1050
+ | 'is_ephemeral'
1051
+ | 'is_deleted'
1052
+ | 'fts'
1053
+ | 'quoted_message_id'
1054
+ | 'invite_v4'
1055
+ | 'id'
1056
+ | 'has_reaction'
1057
+ | 'has_media'
1058
+ | 'duration'
1059
+ | 'broadcast'
1060
+ | 'broadcast_id'
1061
+ | 'device_type'
1062
+ | 'forwarding_score'
1063
+ | 'from'
1064
+ | 'from_me'
1065
+ | 'prev_body'
1066
+ | 'flag_response_time'
1067
+ | 'flag_metadata'
1068
+ | 'ack'
1069
+ >,
1070
+ {
1071
+ media: MediaType | null;
1072
+ }
1073
+ >;
1074
+ };
1075
+
1076
+ export type ReactionRuleInfoType = {
1077
+ chat: ChatRuleInfoType;
1078
+ sender: SenderRuleInfoType;
1079
+ message: MessageRuleInfoType['message'];
1080
+ reaction: Pick<
1081
+ Tables<'tbl_chat_reactions'>,
1082
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1083
+ >;
1084
+ };
1085
+
1086
+ export type TicketRuleInfoType = {
1087
+ chat: ChatRuleInfoType;
1088
+ sender: SenderRuleInfoType;
1089
+ ticket: Merge<
1090
+ Pick<
1091
+ Tables<'tbl_chat_tickets'>,
1092
+ | 'org_id'
1093
+ | 'status'
1094
+ | 'chat_id'
1095
+ | 'subject'
1096
+ | 'assignee'
1097
+ | 'due_date'
1098
+ | 'priority'
1099
+ | 'raised_by'
1100
+ | 'ticket_id'
1101
+ | 'created_at'
1102
+ | 'is_deleted'
1103
+ >,
1104
+ {
1105
+ labels: string[] | null;
1106
+ custom_properties: { [key: string]: string } | null;
1107
+ }
1108
+ >;
1109
+ message: MessageRuleInfoType['message'];
1110
+ };
1111
+ export type FeatureFlagReturnType = Record<string, boolean>;
1112
+
1113
+ export type RuleLogsType = OverrideProperties<
1114
+ Tables<'tbl_rules_logs'>,
1115
+ {
1116
+ actions_progress: {
1117
+ action_id: string;
1118
+ action_type: Rule['actions'][number]['type'];
1119
+ action_delay: Rule['actions'][number]['delay'];
1120
+ ran_at: string | null;
1121
+ action_status: 'success' | 'failed' | 'pending';
1122
+ action_response: {
1123
+ success: boolean;
1124
+ data: Record<string, unknown> | null;
1125
+ error: {
1126
+ message: string;
1127
+ name: string;
1128
+ stack?: string;
1129
+ _error?: Error | Record<string, unknown>;
1130
+ } | null;
1131
+ };
1132
+ }[];
1133
+ metadata: {
1134
+ conditions: Rule['conditions'];
1135
+ actions: Rule['actions'];
1136
+ rule_metadata: Pick<
1137
+ Rule,
1138
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1139
+ >;
1140
+ data: Record<string, unknown>;
1141
+ };
1142
+ conditions_progress: {
1143
+ is_valid: boolean;
1144
+ validation_progress: Record<
1145
+ string,
1146
+ {
1147
+ res: boolean;
1148
+ filter: Filter;
1149
+ value: unknown;
1150
+ }
1151
+ >;
1152
+ checked_at: string | null;
1153
+ };
1154
+ }
1155
+ >;
1156
+
1157
+ /************************** TASKS ***************************/
1158
+
1159
+ export type TaskType = OverrideProperties<
1160
+ Tables<'tbl_org_tasks'>,
1161
+ {
1162
+ reminder_setting: {
1163
+ remind_in:
1164
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1165
+ | string
1166
+ | null;
1167
+ repeat?: {
1168
+ frequency: number;
1169
+ interval: 'days' | 'weeks' | 'months' | 'years';
1170
+ end: 'never' | 'after' | 'on';
1171
+ on?: string;
1172
+ };
1173
+ } | null;
1174
+ associated_object_metadata:
1175
+ | {
1176
+ type: 'chat';
1177
+ index: 'chat_id';
1178
+ id: string;
1179
+ object: ChatType;
1180
+ }
1181
+ | {
1182
+ type: 'message';
1183
+ index: 'message_id';
1184
+ id: string;
1185
+ object: MessageType;
1186
+ }
1187
+ | {
1188
+ type: 'ticket';
1189
+ index: 'ticket_id';
1190
+ id: string;
1191
+ object: TicketType;
1192
+ }
1193
+ | null;
1194
+ status: 'open' | 'inprogress' | 'closed';
1195
+ priority: 1 | 2 | 3;
1196
+ completed_metadata?: {
1197
+ completed_at: string;
1198
+ completed_by: string;
1199
+ } | null;
1200
+ type: 'todo' | 'chat' | 'message' | 'ticket';
1201
+ }
1202
+ >;
1203
+
1204
+ type Choice = {
1205
+ id: number;
1206
+ label: string;
1207
+ value: string;
1208
+ position: number;
1209
+ };
1210
+
1211
+ export type FreshdeskCustomFieldType = {
1212
+ id: number;
1213
+ name: string;
1214
+ label: string;
1215
+ position: number;
1216
+ required_for_agents: boolean;
1217
+ archived: boolean;
1218
+ customers_can_edit: boolean;
1219
+ label_for_customers: string;
1220
+ required_for_customers: boolean;
1221
+ customers_can_filter: boolean;
1222
+ required_for_closure: boolean;
1223
+ displayed_to_customers: boolean;
1224
+ type: string;
1225
+ default: boolean;
1226
+ created_at: string;
1227
+ updated_at: string;
1228
+ choices?: Choice[];
1229
+ };