@periskope/types 0.6.280 → 0.6.282

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