@periskope/types 0.6.309 → 0.6.310

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,1510 +1,1511 @@
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
- editorState?: string;
661
- };
662
-
663
- export type QuickReplyContent = Omit<
664
- SendMessageContent,
665
- 'broadcast_id' | 'variables'
666
- >;
667
-
668
- export type ScheduleMessagePayload = {
669
- scheduled_id?: string;
670
- is_repeat?: boolean | null;
671
- scheduled_at: string;
672
- repeat_config?: {
673
- timezone?: string;
674
- repeat_ends?: string;
675
- repeat_interval?: RepeatIntervalType;
676
- repeat_value?: number;
677
- repeat_days?: RepeatDaysType[];
678
- };
679
- };
680
-
681
- export type BroadcastVariableType = {
682
- chat_id: string;
683
- values: { [key: string]: string };
684
- };
685
-
686
- export type BroadcastMessagePayload = SendMessageContent & {
687
- chat_ids: string[];
688
- broadcast_id?: string;
689
- variables?: BroadcastVariableType[];
690
- delay?: number;
691
- };
692
-
693
- export type SingleMessagePayload = SendMessageContent & {
694
- chat_id: string;
695
- job_id?: string;
696
- priority?: number;
697
- };
698
-
699
- export type MessageAttachmentFileTypes =
700
- | 'image'
701
- | 'audio'
702
- | 'document'
703
- | 'video';
704
-
705
- export type AttachmentFileType = {
706
- result: string;
707
- file: File | null;
708
- type: MessageAttachmentFileTypes;
709
- localFileURL?: string;
710
- };
711
-
712
- export type AttachmentLinkType = {
713
- link: {
714
- url: string;
715
- type: MessageAttachmentFileTypes;
716
- name: string;
717
- mimetype?: string;
718
- };
719
- };
720
-
721
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
722
-
723
- /* -------------------------------- BROADCAST ------------------------------- */
724
-
725
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
726
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
727
- } & {
728
- chats: ChatType[];
729
- };
730
-
731
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
732
-
733
- export type ChatLogType = {
734
- log: Tables<'view_chat_logs'>;
735
- operations: Tables<'tbl_chat_logs'>[];
736
- };
737
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
738
-
739
- export type ChatParticipantOperationPayload = {
740
- participant_ids: string[];
741
- chat_ids: string[];
742
- performed_by: string;
743
- force_add_participants?: boolean;
744
- };
745
-
746
- export type ChatOperationReturn = {
747
- [participant_id: string]: {
748
- is_success: boolean;
749
- message?: string;
750
- code?: number;
751
- isInviteV4Sent?: boolean;
752
- };
753
- };
754
-
755
- /* ----------------------- BILLING - STRIPE ----------------------- */
756
-
757
- export type StripeSubscription = _Stripe.Subscription;
758
- export type StripeCustomer = _Stripe.Customer;
759
- export type StripeCoupon = _Stripe.Coupon;
760
- export type StripePrice = _Stripe.Price;
761
- export type Stripe = _Stripe;
762
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
763
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
764
-
765
- /* -------------------------------- REALTIME -------------------------------- */
766
-
767
- export type PhoneStateType = {
768
- loading: boolean;
769
- state: string;
770
- sync: number;
771
- percent: number | null;
772
- message?: string;
773
- error?: string;
774
- };
775
-
776
- /* ------------------------------- INTEGRATIONS ----------------------------- */
777
-
778
- export type ChatInfoType = Merge<
779
- ChatType,
780
- {
781
- members: {
782
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
783
- } | null;
784
- chat_labels: string | null;
785
- custom_properties: { [key: string]: string } | null;
786
- }
787
- >;
788
-
789
- export type TicketInfoType = {
790
- chat: ChatInfoType;
791
- message: {
792
- body: string;
793
- chat_id: string;
794
- org_phone: string;
795
- timestamp: string;
796
- media_path: string;
797
- message_id: string;
798
- sender_name: string;
799
- performed_by: string;
800
- sender_phone: string;
801
- };
802
- ticket: {
803
- org_id: string;
804
- status: string;
805
- subject: string;
806
- assignee: string;
807
- due_date: string;
808
- priority: 0 | 1 | 2 | 3 | 4;
809
- raised_by: string;
810
- ticket_id: string;
811
- created_at: string;
812
- assigned_by: string;
813
- ticket_labels: string;
814
- quoted_message_id: string;
815
- ticket_custom_properties: { [key: string]: string } | null;
816
- closed_at: string;
817
- closed_by: string;
818
- closed_message: string;
819
- first_assigned_at: string | null;
820
- is_deleted: boolean;
821
- };
822
- attached_messages: {
823
- body: string;
824
- chat_id: string;
825
- org_phone: string;
826
- timestamp: string;
827
- media_path: string;
828
- message_id: string;
829
- sender_name: string;
830
- performed_by: string;
831
- sender_phone: string;
832
- }[];
833
- };
834
-
835
- export type IntegrationLogObjectType =
836
- | 'chat'
837
- | 'message'
838
- | 'reaction'
839
- | 'ticket'
840
- | 'phone';
841
- export enum IntegrationLogType {
842
- NEW_CHAT = 'chat.created',
843
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
844
- NEW_MESSAGE = 'message.created',
845
- MESSAGE_UPDATED = 'message.updated',
846
- MESSAGE_DELETED = 'message.deleted',
847
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
848
- MESSAGE_FLAGGED = 'message.flagged',
849
- MESSAGE_UNFLAGGED = 'message.unflagged',
850
- MESSAGE_TICKET_ATTACHED = 'message.ticket.attached',
851
- REACTION_CREATED = 'reaction.created',
852
- REACTION_UPDATED = 'reaction.updated',
853
- NEW_TICKET = 'ticket.created',
854
- TICKET_UPDATED = 'ticket.updated',
855
- TICKET_DELETED = 'ticket.deleted',
856
- PHONE_DISCONNECTED = 'org.phone.disconnected',
857
- PHONE_CONNECTED = 'org.phone.connected',
858
- PHONE_UPDATED = 'org.phone.updated',
859
- PHONE_QR_UPDATED = 'org.phone.qr',
860
- }
861
-
862
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
863
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
864
- ? TicketInfoType
865
- : T extends IntegrationLogType.NEW_CHAT
866
- ? Tables<'tbl_chats'>
867
- : T extends
868
- | IntegrationLogType.NEW_MESSAGE
869
- | IntegrationLogType.MESSAGE_UPDATED
870
- | IntegrationLogType.MESSAGE_DELETED
871
- | IntegrationLogType.MESSAGE_ACK_UPDATED
872
- | IntegrationLogType.MESSAGE_FLAGGED
873
- | IntegrationLogType.MESSAGE_UNFLAGGED
874
- | IntegrationLogType.MESSAGE_TICKET_ATTACHED
875
- ? Tables<'tbl_chat_messages'>
876
- : T extends
877
- | IntegrationLogType.REACTION_CREATED
878
- | IntegrationLogType.REACTION_UPDATED
879
- ? Tables<'tbl_chat_reactions'>
880
- : T extends
881
- | IntegrationLogType.PHONE_DISCONNECTED
882
- | IntegrationLogType.PHONE_CONNECTED
883
- | IntegrationLogType.PHONE_UPDATED
884
- | IntegrationLogType.PHONE_QR_UPDATED
885
- ? Tables<'tbl_org_phones'>
886
- : {
887
- [key: string]: unknown;
888
- };
889
-
890
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
891
- OverrideProperties<
892
- Tables<'tbl_integration_logs'>,
893
- {
894
- integration_name: T;
895
- metadata: {
896
- event: IntegrationLogMetadataType<T> & {
897
- event_type: string;
898
- org_id: string;
899
- previous_attributes: {
900
- [key: string]: unknown;
901
- };
902
- };
903
- hook_id: string;
904
- name: string;
905
- };
906
- }
907
- >;
908
-
909
- export type APIAuthDetails = {
910
- org_details: Tables<'view_org'> | null;
911
- phone_details: Tables<'tbl_org_phones'> | null;
912
- token_details: Tables<'tbl_integration_tokens'> | null;
913
- };
914
-
915
- export type WebhookDataType = OverrideProperties<
916
- Tables<'tbl_integration_hooks'>,
917
- {
918
- integration_name: string[];
919
- }
920
- >;
921
-
922
- export type HubspotObjectDataType = {
923
- createdAt: string;
924
- archived: boolean;
925
- id: string;
926
- type: 'contacts' | 'tickets' | 'companies';
927
- properties: Record<
928
- string,
929
- {
930
- groupLabel: string;
931
- groupName: string;
932
- propertyKeyName: string;
933
- propertyKey: string;
934
- propertyInternalValue: string;
935
- propertyValue: string;
936
- propertyType: string;
937
- propertyFieldType: string;
938
- }[]
939
- >;
940
- };
941
-
942
- /* ---------------------------- USER PREFERENCES ---------------------------- */
943
-
944
- export type UserPreferences = {
945
- theme: 'light' | 'dark';
946
- language: 'en' | 'es';
947
- left_sidebar_open: boolean;
948
- right_sidepanel_open: boolean;
949
- sync_wa_unread_count: boolean;
950
- pinned_chats: string[];
951
- archived_chats: string[];
952
- closed_chats: Record<string, number>;
953
- periskope_chat_limit: number;
954
- notifications: Record<string, boolean>;
955
- };
956
-
957
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
958
-
959
- export interface MostActiveMember {
960
- sender_phone: string;
961
- total_messages: number;
962
- }
963
-
964
- export interface GroupAnalyticsResult {
965
- total_messages: number;
966
- total_joins: number;
967
- total_leaves: number;
968
- total_removes: number;
969
- total_reactions: number;
970
- most_active_members: MostActiveMember[];
971
- }
972
-
973
- export interface TimeRange {
974
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
975
- endDateTime: string;
976
- }
977
-
978
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
979
-
980
- export type PollSendType = {
981
- pollName: string;
982
- pollOptions: string[];
983
- options?: {
984
- allowMultipleAnswers?: boolean;
985
- messageSecret?: number[] | null;
986
- pollId?: string;
987
- };
988
- };
989
-
990
- export type PollResultType = {
991
- [name: string]: Record<string, string>;
992
- };
993
-
994
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
995
-
996
- export type CreateGroupOptions = {
997
- messagesAdminsOnly?: boolean;
998
- infoAdminsOnly?: boolean;
999
- addMembersAdminsOnly?: boolean;
1000
- image?: string;
1001
- name?: string;
1002
- description?: string;
1003
- initiated_by?: string;
1004
- admins?: string[];
1005
- force_add_participants?: boolean;
1006
- };
1007
-
1008
- /* ------------------------------ DELIVERY INFO ----------------------------- */
1009
-
1010
- export type DeliveryInfoType = {
1011
- delivered: Record<string, number | undefined>;
1012
- read: Record<string, number | undefined>;
1013
- pending: string[];
1014
- read_count: number;
1015
- delivered_count: number;
1016
- };
1017
-
1018
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1019
-
1020
- export type OrgCreditsType = {
1021
- org_id: string;
1022
- recurring_allowance: number; // recurring credits replenished every cycle
1023
- recurring_balance: number; // recurring credits remaining in current cycle
1024
- topup_balance: number; // topup credits remaining
1025
- total_credits_used: number; // total credits used in current cycle
1026
- next_renewal_date: string;
1027
- topup_credits_used: number; // topup credits used in current cycle
1028
- recurring_credits_used: number; // recurring credits used in current cycle
1029
- };
1030
-
1031
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
1032
-
1033
- export type ChatRuleInfoType = Merge<
1034
- Pick<
1035
- Tables<'view_chats'>,
1036
- | 'assigned_to'
1037
- | 'chat_id'
1038
- | 'chat_name'
1039
- | 'chat_type'
1040
- | 'created_at'
1041
- | 'group_description'
1042
- | 'info_admins_only'
1043
- | 'org_id'
1044
- | 'org_phone'
1045
- | 'chat_org_phones'
1046
- | 'messages_admins_only'
1047
- | 'custom_properties'
1048
- | 'initiated_by'
1049
- >,
1050
- {
1051
- has_flagged_messages: boolean;
1052
- labels: string[];
1053
- members: string[];
1054
- custom_properties: { [key: string]: string } | null;
1055
- }
1056
- >;
1057
-
1058
- export type SenderRuleInfoType = Merge<
1059
- Omit<
1060
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1061
- | 'verified_name'
1062
- | 'verified_level'
1063
- | 'updated_at'
1064
- | 'short_name'
1065
- | 'pushname'
1066
- | 'periskope_name'
1067
- | 'org_phone'
1068
- | 'number'
1069
- | 'name'
1070
- | 'label_ids'
1071
- | 'is_wa_contact'
1072
- | 'is_user'
1073
- | 'is_my_contact'
1074
- | 'is_me'
1075
- | 'is_imported'
1076
- | 'is_group'
1077
- | 'is_blocked'
1078
- | 'contact_color'
1079
- | 'business_profile'
1080
- | 'id'
1081
- | 'contact_image'
1082
- | 'contact_type'
1083
- | 'chat_id'
1084
- | 'is_business'
1085
- | 'is_enterprise'
1086
- | 'is_super_admin'
1087
- | 'contact_lid'
1088
- >,
1089
- {
1090
- is_internal: boolean;
1091
- labels: string[] | null;
1092
- }
1093
- >;
1094
-
1095
- export type MessageRuleInfoType = {
1096
- chat: ChatRuleInfoType;
1097
- sender: SenderRuleInfoType;
1098
- message: OverrideProperties<
1099
- Omit<
1100
- Tables<'tbl_chat_messages'>,
1101
- | 'vcards'
1102
- | 'updated_at'
1103
- | 'unique_id'
1104
- | 'token'
1105
- | 'to'
1106
- | 'sent_message_id'
1107
- | 'raw_data'
1108
- | 'delivery_info'
1109
- | 'poll_results'
1110
- | 'poll_info'
1111
- | 'order_id'
1112
- | 'mentioned_ids'
1113
- | 'media_key'
1114
- | 'location'
1115
- | 'links'
1116
- | 'is_status'
1117
- | 'is_starred'
1118
- | 'is_gif'
1119
- | 'is_forwarded'
1120
- | 'is_ephemeral'
1121
- | 'is_deleted'
1122
- | 'fts'
1123
- | 'quoted_message_id'
1124
- | 'invite_v4'
1125
- | 'id'
1126
- | 'has_reaction'
1127
- | 'has_media'
1128
- | 'duration'
1129
- | 'broadcast'
1130
- | 'broadcast_id'
1131
- | 'device_type'
1132
- | 'forwarding_score'
1133
- | 'from'
1134
- | 'from_me'
1135
- | 'prev_body'
1136
- | 'flag_response_time'
1137
- | 'flag_metadata'
1138
- | 'ack'
1139
- >,
1140
- {
1141
- media: MediaType | null;
1142
- }
1143
- >;
1144
- };
1145
-
1146
- export type ReactionRuleInfoType = {
1147
- chat: ChatRuleInfoType;
1148
- sender: SenderRuleInfoType;
1149
- message: MessageRuleInfoType['message'];
1150
- reaction: Pick<
1151
- Tables<'tbl_chat_reactions'>,
1152
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1153
- >;
1154
- };
1155
-
1156
- export type TicketRuleInfoType = {
1157
- chat: ChatRuleInfoType;
1158
- sender: SenderRuleInfoType;
1159
- ticket: Merge<
1160
- Pick<
1161
- Tables<'tbl_chat_tickets'>,
1162
- | 'org_id'
1163
- | 'status'
1164
- | 'chat_id'
1165
- | 'subject'
1166
- | 'assignee'
1167
- | 'due_date'
1168
- | 'priority'
1169
- | 'raised_by'
1170
- | 'ticket_id'
1171
- | 'created_at'
1172
- | 'is_deleted'
1173
- >,
1174
- {
1175
- labels: string[] | null;
1176
- custom_properties: { [key: string]: string } | null;
1177
- }
1178
- >;
1179
- message: MessageRuleInfoType['message'];
1180
- };
1181
- export type FeatureFlagReturnType = Record<string, boolean>;
1182
-
1183
- export type RuleLogsType = OverrideProperties<
1184
- Tables<'tbl_rules_logs'>,
1185
- {
1186
- actions_progress: {
1187
- action_id: string;
1188
- action_type: Rule['actions'][number]['type'];
1189
- action_delay: Rule['actions'][number]['delay'];
1190
- ran_at: string | null;
1191
- action_status: 'success' | 'failed' | 'pending';
1192
- action_response: {
1193
- success: boolean;
1194
- data: Record<string, unknown> | null;
1195
- error: {
1196
- message: string;
1197
- name: string;
1198
- stack?: string;
1199
- _error?: Error | Record<string, unknown>;
1200
- } | null;
1201
- };
1202
- }[];
1203
- metadata: {
1204
- conditions: Rule['conditions'];
1205
- actions: Rule['actions'];
1206
- rule_metadata: Pick<
1207
- Rule,
1208
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1209
- >;
1210
- data: Record<string, unknown>;
1211
- };
1212
- conditions_progress: {
1213
- is_valid: boolean;
1214
- validation_progress: Record<
1215
- string,
1216
- {
1217
- res: boolean;
1218
- filter: Filter;
1219
- value: unknown;
1220
- }
1221
- >;
1222
- checked_at: string | null;
1223
- };
1224
- }
1225
- >;
1226
-
1227
- /************************** TASKS ***************************/
1228
-
1229
- export type TaskType = OverrideProperties<
1230
- Tables<'tbl_org_tasks'>,
1231
- {
1232
- reminder_setting: {
1233
- remind_in:
1234
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1235
- | string
1236
- | null;
1237
- repeat?: {
1238
- frequency: number;
1239
- interval: 'days' | 'weeks' | 'months' | 'years';
1240
- end: 'never' | 'after' | 'on';
1241
- on?: string;
1242
- };
1243
- } | null;
1244
- associated_object_metadata:
1245
- | {
1246
- type: 'chat';
1247
- index: 'chat_id';
1248
- id: string;
1249
- object: ChatType;
1250
- }
1251
- | {
1252
- type: 'message';
1253
- index: 'message_id';
1254
- id: string;
1255
- object: MessageType;
1256
- }
1257
- | {
1258
- type: 'ticket';
1259
- index: 'ticket_id';
1260
- id: string;
1261
- object: TicketType;
1262
- }
1263
- | null;
1264
- status: 'open' | 'inprogress' | 'closed';
1265
- priority: 1 | 2 | 3;
1266
- completed_metadata?: {
1267
- completed_at: string;
1268
- completed_by: string;
1269
- } | null;
1270
- type: 'todo' | 'chat' | 'message' | 'ticket';
1271
- }
1272
- >;
1273
-
1274
- type Choice = {
1275
- id: number;
1276
- label: string;
1277
- value: string;
1278
- position: number;
1279
- };
1280
-
1281
- export type FreshdeskFieldType = {
1282
- id: number;
1283
- name: string;
1284
- type: string;
1285
- label: string;
1286
- default: boolean;
1287
- archived: boolean;
1288
- position: number;
1289
- created_at: string;
1290
- updated_at: string;
1291
- customers_can_edit: boolean;
1292
- label_for_customers: string;
1293
- required_for_agents: boolean;
1294
- customers_can_filter: boolean;
1295
- required_for_closure: boolean;
1296
- displayed_to_customers: boolean;
1297
- required_for_customers: boolean;
1298
- choices?: Choice[];
1299
- };
1300
-
1301
- export type OrgWarmup = OverrideProperties<
1302
- Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1303
- {
1304
- warmup_chats: { [key: string]: string };
1305
- }
1306
- >;
1307
-
1308
- /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1309
-
1310
- export type FreshdeskIntegrationTokenType = OverrideProperties<
1311
- Tables<'tbl_integration_tokens'>,
1312
- {
1313
- type: 'freshdesk';
1314
- token_metadata: {
1315
- url: string;
1316
- apiKey: string;
1317
- fields: {
1318
- ticket: FreshdeskFieldType[];
1319
- company: FreshdeskFieldType[];
1320
- contact: FreshdeskFieldType[];
1321
- };
1322
- automation: {
1323
- id: number | string;
1324
- meta: {
1325
- total_count: number;
1326
- total_active_count: 17;
1327
- };
1328
- name: string;
1329
- active: boolean;
1330
- events: Array<{
1331
- to?: string;
1332
- from?: string;
1333
- field_name: string;
1334
- value?: string;
1335
- }>;
1336
- actions: Array<{
1337
- url: string;
1338
- content: Record<string, string>;
1339
- field_name: string;
1340
- content_type: string;
1341
- request_type: string;
1342
- content_layout: string;
1343
- }>;
1344
- summary: {
1345
- events: Array<string>;
1346
- actions: Array<string>;
1347
- performer: string;
1348
- conditions: {
1349
- [key: string]: Array<string>;
1350
- };
1351
- };
1352
- outdated: boolean;
1353
- position: number;
1354
- performer: {
1355
- type: string;
1356
- };
1357
- conditions: Array<{
1358
- name: string;
1359
- match_type: string;
1360
- properties: Array<{
1361
- value: Array<string>;
1362
- operator: string;
1363
- field_name: string;
1364
- resource_type: string;
1365
- case_sensitive: boolean;
1366
- }>;
1367
- }>;
1368
- created_at: string;
1369
- updated_at: string;
1370
- description: string | null;
1371
- last_updated_by: string | number;
1372
- affected_tickets_count: number | null;
1373
- };
1374
- org_details: {
1375
- address: {
1376
- city: string;
1377
- state: string;
1378
- street: string;
1379
- country: string;
1380
- postalcode: string;
1381
- };
1382
- timezone: string;
1383
- bundle_id: string;
1384
- tier_type: string;
1385
- account_id: number;
1386
- cloud_type: string;
1387
- data_center: string;
1388
- account_name: string;
1389
- total_agents: {
1390
- full_time: number;
1391
- occasional: number;
1392
- collaborators: number;
1393
- field_service: number;
1394
- };
1395
- account_domain: string;
1396
- contact_person: {
1397
- email: string;
1398
- lastname: string;
1399
- firstname: string;
1400
- };
1401
- hipaa_compliant: boolean;
1402
- organisation_id: number;
1403
- organisation_name: string;
1404
- };
1405
- custom_fields: {
1406
- ticket: FreshdeskFieldType[];
1407
- company: FreshdeskFieldType[];
1408
- contact: FreshdeskFieldType[];
1409
- };
1410
- integration_org_id: string | number;
1411
- };
1412
- }
1413
- >;
1414
-
1415
- export type ZohodeskIntegrationTokenType = OverrideProperties<
1416
- Tables<'tbl_integration_tokens'>,
1417
- {
1418
- type: 'zohodesk';
1419
- token_metadata: {
1420
- scope: string;
1421
- domain: string;
1422
- fields: Array<{
1423
- id: string;
1424
- name: string;
1425
- type: string;
1426
- apiName: string;
1427
- toolTip: string;
1428
- i18NLabel: string;
1429
- maxLength: number;
1430
- isMandatory: boolean;
1431
- toolTipType: string;
1432
- displayLabel: string;
1433
- isCustomField: boolean;
1434
- isEncryptedField: boolean;
1435
- showToHelpCenter: boolean;
1436
- }>;
1437
- org_id: string;
1438
- webhooks: {
1439
- id: string;
1440
- url: string;
1441
- name: string;
1442
- type: string;
1443
- createdBy: string;
1444
- isEnabled: boolean;
1445
- createdTime: string;
1446
- description: string;
1447
- modifiedTime: string;
1448
- subscriptions: {
1449
- [key: string]: {
1450
- departmentIds: string[];
1451
- includePrevState: boolean;
1452
- };
1453
- };
1454
- ignoreSourceId: boolean | null;
1455
- includeEventsFrom: string[];
1456
- };
1457
- api_domain: string;
1458
- authDomain: string;
1459
- expires_in: number;
1460
- token_type: string;
1461
- departments: Array<{
1462
- id: string;
1463
- name: string;
1464
- hasLogo: boolean;
1465
- creatorId: string;
1466
- isDefault: boolean;
1467
- isEnabled: boolean;
1468
- chatStatus: string;
1469
- createdTime: string;
1470
- description: string | null;
1471
- sanitizedName: string;
1472
- nameInCustomerPortal: string;
1473
- isAssignToTeamEnabled: boolean;
1474
- isVisibleInCustomerPortal: boolean;
1475
- }>;
1476
- org_details: {
1477
- id: number;
1478
- fax: string;
1479
- zip: string;
1480
- city: string;
1481
- alias: string | null;
1482
- state: string;
1483
- mobile: string;
1484
- street: string;
1485
- country: string;
1486
- edition: string;
1487
- logoURL: string;
1488
- website: string;
1489
- isDefault: boolean;
1490
- portalURL: string;
1491
- faviconURL: string;
1492
- portalName: string;
1493
- companyName: string;
1494
- description: string | null;
1495
- phoneNumber: string | null;
1496
- currencyCode: string;
1497
- isAdminInOrg: boolean;
1498
- employeeCount: number;
1499
- currencyLocale: string;
1500
- currencySymbol: string;
1501
- primaryContact: string;
1502
- isSandboxPortal: boolean;
1503
- isPayloadEncryptionEnabled: boolean;
1504
- };
1505
- access_token: string;
1506
- refresh_token: string;
1507
- integration_org_id: string | number;
1508
- };
1509
- }
1510
- >;
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 FreshdeskFieldType = {
1281
+ id: number;
1282
+ name: string;
1283
+ type: string;
1284
+ label: string;
1285
+ default: boolean;
1286
+ archived: boolean;
1287
+ position: number;
1288
+ created_at: string;
1289
+ updated_at: string;
1290
+ customers_can_edit: boolean;
1291
+ label_for_customers: string;
1292
+ required_for_agents: boolean;
1293
+ customers_can_filter: boolean;
1294
+ required_for_closure: boolean;
1295
+ displayed_to_customers: boolean;
1296
+ required_for_customers: boolean;
1297
+ choices?: Choice[];
1298
+ };
1299
+
1300
+ export type OrgWarmup = OverrideProperties<
1301
+ Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1302
+ {
1303
+ warmup_chats: { [key: string]: string };
1304
+ }
1305
+ >;
1306
+
1307
+ /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1308
+
1309
+ export type FreshdeskIntegrationTokenType = OverrideProperties<
1310
+ Tables<'tbl_integration_tokens'>,
1311
+ {
1312
+ type: 'freshdesk';
1313
+ token_metadata: {
1314
+ url: string;
1315
+ apiKey: string;
1316
+ fields: {
1317
+ ticket: FreshdeskFieldType[];
1318
+ company: FreshdeskFieldType[];
1319
+ contact: FreshdeskFieldType[];
1320
+ };
1321
+ automation: {
1322
+ id: number | string;
1323
+ meta: {
1324
+ total_count: number;
1325
+ total_active_count: 17;
1326
+ };
1327
+ name: string;
1328
+ active: boolean;
1329
+ events: Array<{
1330
+ to?: string;
1331
+ from?: string;
1332
+ field_name: string;
1333
+ value?: string;
1334
+ }>;
1335
+ actions: Array<{
1336
+ url: string;
1337
+ content: Record<string, string>;
1338
+ field_name: string;
1339
+ content_type: string;
1340
+ request_type: string;
1341
+ content_layout: string;
1342
+ }>;
1343
+ summary: {
1344
+ events: Array<string>;
1345
+ actions: Array<string>;
1346
+ performer: string;
1347
+ conditions: {
1348
+ [key: string]: Array<string>;
1349
+ };
1350
+ };
1351
+ outdated: boolean;
1352
+ position: number;
1353
+ performer: {
1354
+ type: string;
1355
+ };
1356
+ conditions: Array<{
1357
+ name: string;
1358
+ match_type: string;
1359
+ properties: Array<{
1360
+ value: Array<string>;
1361
+ operator: string;
1362
+ field_name: string;
1363
+ resource_type: string;
1364
+ case_sensitive: boolean;
1365
+ }>;
1366
+ }>;
1367
+ created_at: string;
1368
+ updated_at: string;
1369
+ description: string | null;
1370
+ last_updated_by: string | number;
1371
+ affected_tickets_count: number | null;
1372
+ };
1373
+ org_details: {
1374
+ address: {
1375
+ city: string;
1376
+ state: string;
1377
+ street: string;
1378
+ country: string;
1379
+ postalcode: string;
1380
+ };
1381
+ timezone: string;
1382
+ bundle_id: string;
1383
+ tier_type: string;
1384
+ account_id: number;
1385
+ cloud_type: string;
1386
+ data_center: string;
1387
+ account_name: string;
1388
+ total_agents: {
1389
+ full_time: number;
1390
+ occasional: number;
1391
+ collaborators: number;
1392
+ field_service: number;
1393
+ };
1394
+ account_domain: string;
1395
+ contact_person: {
1396
+ email: string;
1397
+ lastname: string;
1398
+ firstname: string;
1399
+ };
1400
+ hipaa_compliant: boolean;
1401
+ organisation_id: number;
1402
+ organisation_name: string;
1403
+ };
1404
+ custom_fields: {
1405
+ ticket: FreshdeskFieldType[];
1406
+ company: FreshdeskFieldType[];
1407
+ contact: FreshdeskFieldType[];
1408
+ };
1409
+ integration_org_id: string | number;
1410
+ ticket_auto_creation?: boolean;
1411
+ };
1412
+ }
1413
+ >;
1414
+
1415
+ export type ZohodeskIntegrationTokenType = OverrideProperties<
1416
+ Tables<'tbl_integration_tokens'>,
1417
+ {
1418
+ type: 'zohodesk';
1419
+ token_metadata: {
1420
+ scope: string;
1421
+ domain: string;
1422
+ fields: Array<{
1423
+ id: string;
1424
+ name: string;
1425
+ type: string;
1426
+ apiName: string;
1427
+ toolTip: string;
1428
+ i18NLabel: string;
1429
+ maxLength: number;
1430
+ isMandatory: boolean;
1431
+ toolTipType: string;
1432
+ displayLabel: string;
1433
+ isCustomField: boolean;
1434
+ isEncryptedField: boolean;
1435
+ showToHelpCenter: boolean;
1436
+ }>;
1437
+ org_id: string;
1438
+ webhooks: {
1439
+ id: string;
1440
+ url: string;
1441
+ name: string;
1442
+ type: string;
1443
+ createdBy: string;
1444
+ isEnabled: boolean;
1445
+ createdTime: string;
1446
+ description: string;
1447
+ modifiedTime: string;
1448
+ subscriptions: {
1449
+ [key: string]: {
1450
+ departmentIds: string[];
1451
+ includePrevState: boolean;
1452
+ };
1453
+ };
1454
+ ignoreSourceId: boolean | null;
1455
+ includeEventsFrom: string[];
1456
+ };
1457
+ api_domain: string;
1458
+ authDomain: string;
1459
+ expires_in: number;
1460
+ token_type: string;
1461
+ departments: Array<{
1462
+ id: string;
1463
+ name: string;
1464
+ hasLogo: boolean;
1465
+ creatorId: string;
1466
+ isDefault: boolean;
1467
+ isEnabled: boolean;
1468
+ chatStatus: string;
1469
+ createdTime: string;
1470
+ description: string | null;
1471
+ sanitizedName: string;
1472
+ nameInCustomerPortal: string;
1473
+ isAssignToTeamEnabled: boolean;
1474
+ isVisibleInCustomerPortal: boolean;
1475
+ }>;
1476
+ org_details: {
1477
+ id: number;
1478
+ fax: string;
1479
+ zip: string;
1480
+ city: string;
1481
+ alias: string | null;
1482
+ state: string;
1483
+ mobile: string;
1484
+ street: string;
1485
+ country: string;
1486
+ edition: string;
1487
+ logoURL: string;
1488
+ website: string;
1489
+ isDefault: boolean;
1490
+ portalURL: string;
1491
+ faviconURL: string;
1492
+ portalName: string;
1493
+ companyName: string;
1494
+ description: string | null;
1495
+ phoneNumber: string | null;
1496
+ currencyCode: string;
1497
+ isAdminInOrg: boolean;
1498
+ employeeCount: number;
1499
+ currencyLocale: string;
1500
+ currencySymbol: string;
1501
+ primaryContact: string;
1502
+ isSandboxPortal: boolean;
1503
+ isPayloadEncryptionEnabled: boolean;
1504
+ };
1505
+ access_token: string;
1506
+ refresh_token: string;
1507
+ integration_org_id: string | number;
1508
+ ticket_auto_creation?: boolean;
1509
+ };
1510
+ }
1511
+ >;