@periskope/types 0.6.299 → 0.6.301

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