@periskope/types 0.6.367 → 0.6.369

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,1698 +1,1616 @@
1
- import {
2
- Customer,
3
- Estimate,
4
- HostedPage,
5
- ItemPrice,
6
- Subscription,
7
- } from 'chargebee';
8
-
9
- import { Merge, OverrideProperties } from 'type-fest';
10
- import { Filter, Rule } from './rules.types';
11
- import { Tables, TablesInsert, TablesUpdate } from './supabase.types';
12
-
13
- /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
14
-
15
- /* ------------------------------ PERISKOPE TYPES ------------------------------ */
16
-
17
- export enum AllPlans {
18
- FREE_TRIAL = 'free-trial',
19
- // MONTHLY_STARTER = 'monthly-starter',
20
- // YEARLY_STARTER = 'yearly-starter',
21
- // MONTHLY_PRO = 'monthly-pro',
22
- // YEARLY_PRO = 'yearly-pro',
23
- ENTERPRISE = 'enterprise',
24
- MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
25
- YEARLY_STARTER_SINGLE = 'yearly-starter-single',
26
- MONTHLY_PRO_SINGLE = 'monthly-pro-single',
27
- YEARLY_PRO_SINGLE = 'yearly-pro-single',
28
- }
29
-
30
- export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
31
-
32
- export type Enterprise = `${string}-enterprise`;
33
-
34
- export type OrgPlanEnterprise = {
35
- subscription_id: string;
36
- plan_id: Enterprise;
37
- interval: number;
38
- frequency: Frequency;
39
- user_limit: number;
40
- phone_limit: number;
41
- current_period_start: number;
42
- current_period_end: number | null;
43
- additional_user_limit?: number;
44
- additional_phone_limit?: number;
45
- currency: string;
46
- cancelled_at?: number;
47
- cancel_schedule_created_at?: number;
48
- subscription_status?: string;
49
- };
50
-
51
- export type OrgPlanNonEnterprise = {
52
- subscription_id: string;
53
- plan_id: AllPlans;
54
- interval: number;
55
- frequency: Frequency;
56
- user_limit: number;
57
- phone_limit: number;
58
- current_period_end: number;
59
- current_period_start: number;
60
- additional_user_limit?: number;
61
- additional_phone_limit?: number;
62
- currency: string;
63
- cancelled_at?: number;
64
- cancel_schedule_created_at?: number;
65
- subscription_status?: string;
66
- };
67
-
68
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
69
- ? OrgPlanEnterprise
70
- : T extends AllPlans
71
- ? OrgPlanNonEnterprise
72
- : never;
73
-
74
- export type MicrosurveyData = {
75
- key: string;
76
- text: string;
77
- checked: boolean;
78
- }[];
79
-
80
- export type OrgPreferences = {
81
- disable_ai_flagging?: boolean;
82
- disable_ai_responder?: boolean;
83
- ai_responder_default_on?: boolean;
84
- disable_allow_exports?: boolean;
85
- disable_view_deleted_messages?: boolean;
86
- sync_phone_contacts?: boolean;
87
- mask_phone_numbers?: boolean;
88
- show_sender_names?: boolean;
89
- closed_chats?: Record<string, number>;
90
- auto_read_muted_chats?: boolean;
91
- member_permissions?: Record<string, boolean>;
92
- show_active_phone_only_messages_right?: boolean;
93
- };
94
-
95
- type OrgPreferenceKey = keyof OrgPreferences;
96
-
97
- export type OrgPreferencesValue = {
98
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
99
- }[OrgPreferenceKey];
100
-
101
- export type OrgAISettings = {
102
- ai_nickname?: string;
103
- confidence_score?: string;
104
- company_overview?: string;
105
- ai_responder_roles?: string;
106
- human_agent_roles?: string;
107
- ticket_creation_rules?: string;
108
- private_note_creation_rules?: string;
109
- response_delay_value?: string;
110
- snooze_delay_value?: string;
111
- temperature?: string;
112
- top_p?: string;
113
- top_k?: string;
114
- ai_maintain_flag_status?: boolean;
115
- enable_shift_timing?: boolean;
116
- shift_start_time?: string;
117
- shift_end_time?: string;
118
- };
119
-
120
- type OrgAISettingsKey = keyof OrgAISettings;
121
-
122
- export type OrgAISettingsValue = {
123
- [K in OrgAISettingsKey]: { key: K; value: OrgAISettings[K] };
124
- }[OrgAISettingsKey];
125
-
126
- export type CustomPropertySectionType = {
127
- id: string;
128
- name: string;
129
- order: number;
130
- type: 'chat' | 'ticket';
131
- properties_order?: {
132
- [id: string]: number;
133
- };
134
- };
135
-
136
- export enum CustomPropertyValueType {
137
- DROPDOWN = 'dropdown',
138
- TEXT = 'text',
139
- DATE = 'date',
140
- FILE = 'file',
141
- PICKLIST = 'picklist',
142
- DEPENDENT_DROPDOWN = 'dependent_dropdown',
143
- }
144
-
145
- export type CustomPropertyMetadataType = {
146
- section_id?: string;
147
- };
148
-
149
- export type CustomPropertyTextPropertiesType = {
150
- property_value_type: CustomPropertyValueType.TEXT;
151
- property_value: null;
152
- property_metadata: CustomPropertyMetadataType;
153
- };
154
-
155
- export type CustomPropertyDropdownPropertiesType = {
156
- property_value_type: CustomPropertyValueType.DROPDOWN;
157
- property_value: {
158
- [key: string]: string;
159
- };
160
- property_metadata: CustomPropertyMetadataType;
161
- };
162
-
163
- export type CustomPropertyPicklistPropertiesType = {
164
- property_value_type: CustomPropertyValueType.PICKLIST;
165
- property_value: {
166
- [key: string]: string;
167
- };
168
- property_metadata: CustomPropertyMetadataType;
169
- };
170
-
171
- export type CustomPropertyDependentDropdownPropertiesType = {
172
- property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
173
- property_value: {
174
- level_1: {
175
- value: string;
176
- label: string;
177
- level_2: {
178
- value: string;
179
- label: string;
180
- level_3: {
181
- value: string;
182
- label: string;
183
- }[];
184
- }[];
185
- }[];
186
- };
187
- property_metadata: Merge<
188
- CustomPropertyMetadataType,
189
- {
190
- level_names: {
191
- level_1: string;
192
- level_2: string;
193
- level_3: string;
194
- };
195
- }
196
- >;
197
- };
198
-
199
- export type CustomPropertyFilePropertiesType = {
200
- property_value_type: CustomPropertyValueType.FILE;
201
- property_value: null;
202
- property_metadata: CustomPropertyMetadataType;
203
- };
204
-
205
- export type CustomPropertyDatePropertiesType = {
206
- property_value_type: CustomPropertyValueType.DATE;
207
- property_value: null;
208
- property_metadata: CustomPropertyMetadataType;
209
- };
210
-
211
- export type CustomPropertyType = OverrideProperties<
212
- Tables<'tbl_custom_properties'>,
213
- | CustomPropertyDependentDropdownPropertiesType
214
- | CustomPropertyTextPropertiesType
215
- | CustomPropertyDropdownPropertiesType
216
- | CustomPropertyPicklistPropertiesType
217
- | CustomPropertyFilePropertiesType
218
- | CustomPropertyDatePropertiesType
219
- >;
220
-
221
- export type OrgMetadata = {
222
- phone_number: string;
223
- ticket_prefix: string;
224
- referralSource?: string;
225
- contact_name?: string;
226
- surveyData?: MicrosurveyData;
227
- preferences?: OrgPreferences;
228
- hubspot: {
229
- hubspot_pipelines?: {
230
- id: string;
231
- label: string;
232
- default_stage: { id: string; label: string };
233
- }[];
234
- hubspot_hidden_fields?: string[];
235
- };
236
- partition?: boolean;
237
- tickets: {
238
- prefix?: string;
239
- emoji_ticketing: {
240
- is_enabled?: boolean;
241
- is_message_enabled?: boolean;
242
- message_template?: string;
243
- };
244
- disable_auto_attach_message_to_ticket?: boolean;
245
- };
246
- attribution?: Object;
247
- affiliate_id?: string;
248
- custom_properties?: {
249
- sections?: CustomPropertySectionType[];
250
- };
251
- rules?: {
252
- limit?: number;
253
- };
254
- ai?: {
255
- flag_prompt?: string;
256
- };
257
- display_language?: string;
258
- custom_invite?: {
259
- is_enabled: boolean;
260
- template: string;
261
- };
262
- };
263
-
264
- export type GroupTemplateType = OverrideProperties<
265
- Tables<'tbl_group_templates'>,
266
- {
267
- group_metadata: {
268
- messagesAdminsOnly?: boolean;
269
- infoAdminsOnly?: boolean;
270
- addMembersAdminsOnly?: boolean;
271
- description?: string;
272
- admins?: string[];
273
- };
274
- }
275
- >;
276
-
277
- type AccessScopes = {
278
- feature_flags: Record<string, boolean>;
279
- integrations: boolean;
280
- rules: boolean;
281
- exports: boolean;
282
- };
283
-
284
- export type OrgMembersType = OverrideProperties<
285
- Tables<'tbl_org_members'>,
286
- {
287
- member_metadata: {
288
- shift_times: {
289
- [day in
290
- | 'monday'
291
- | 'tuesday'
292
- | 'wednesday'
293
- | 'thursday'
294
- | 'friday'
295
- | 'saturday'
296
- | 'sunday']?: [[string, string]];
297
- };
298
- override_status: boolean;
299
- [key: string]: any;
300
- };
301
- }
302
- >;
303
-
304
- export type OrgType = OverrideProperties<
305
- Merge<
306
- Tables<'tbl_org'>,
307
- {
308
- user: OrgMembersType;
309
- members: OrgMembersType[];
310
- phones: Tables<'tbl_org_phones'>[];
311
- labels: Tables<'tbl_org_labels'>[];
312
- quick_replies: Tables<'tbl_quick_replies'>[];
313
- custom_properties: CustomPropertyType[];
314
- subscription_status: 'active' | 'inactive' | 'unpaid';
315
- is_enterprise: boolean;
316
- is_free_trial: boolean;
317
- is_hubspot_connected: boolean;
318
- is_freshdesk_connected: boolean;
319
- is_zohodesk_connected: boolean;
320
- is_zohocrm_connected: boolean;
321
- access_scopes: AccessScopes;
322
- rules: Rule[];
323
- phone_limit: number;
324
- user_limit: number;
325
- }
326
- >,
327
- {
328
- org_plan: OrgPlan<AllPlans | Enterprise>;
329
- stripe_customer_details: Customer | null;
330
- stripe_subscription_details: Array<Subscription> | null;
331
- stripe_customer_id: Customer['id'] | null;
332
- org_metadata: OrgMetadata;
333
- ai_settings: OrgAISettings;
334
- }
335
- >;
336
-
337
- export type ChatMemberType = Merge<
338
- Tables<'tbl_chat_participants'>,
339
- Tables<'tbl_contacts'>
340
- >;
341
-
342
- export type ChatType = Merge<
343
- Tables<'view_chats'>,
344
- {
345
- chat_id: string;
346
- latest_message: MessageType | null;
347
- latest_message_timestamp: number | null;
348
- latest_message_timestamp_map?: Record<string, number | null>;
349
- members: { [key: string]: ChatMemberType } | null;
350
- chat_type: 'user' | 'group' | 'business' | 'unknown';
351
- chat_access: { [key: string]: boolean };
352
- label_ids: { [key: string]: boolean };
353
- chat_org_phones?: string[];
354
- message_unread_count: number | null;
355
- hubspot_metadata: {
356
- id: string;
357
- type: string;
358
- hubId: string;
359
- object_data: HubspotObjectDataType;
360
- } | null;
361
- info_admins_only: boolean;
362
- messages_admins_only: boolean;
363
- unread_count?: { [key: string]: number };
364
- active_phone: string | null;
365
- flag_count_map?: { [key: string]: number };
366
- is_archived?: boolean;
367
- is_pinned?: boolean;
368
- closed_at?: number | null;
369
- common_chats?: string[];
370
- freshdesk_metadata?: Record<string, any>;
371
- zohodesk_metadata?: Record<string, any>;
372
- zohocrm_metadata?: Record<string,any>;
373
- pinned_messages?: {
374
- message_id: string;
375
- pinned_at: number;
376
- expires_at: number;
377
- }[];
378
- group_metadata?: Record<string, any>;
379
- snooze_metadata?: {
380
- snooze_until: number;
381
- snooze_message?: string;
382
- snooze_by?: string;
383
- };
384
- member_unread_count?: {
385
- [key: string]: number;
386
- };
387
- }
388
- >;
389
-
390
- /* -------------------------------------------------------------------------- */
391
- /* MESSAGE */
392
- /* -------------------------------------------------------------------------- */
393
-
394
- export type MediaType = {
395
- path?: string;
396
- mimetype?: string;
397
- filename?: string;
398
- dimensions?: { width: number; height: number; ar: number };
399
- size?: number;
400
- thumbnail?: string;
401
- filedata?: string;
402
- compress?: boolean;
403
- };
404
-
405
- export type MessageType = Merge<
406
- OverrideProperties<
407
- TablesInsert<'tbl_chat_messages'>,
408
- {
409
- message_id: string;
410
- org_id: string;
411
- org_phone: string;
412
- chat_id: string;
413
- message_type: (typeof SUPPORTED_TYPES)[number];
414
- media: MediaType | null;
415
- flag_metadata?: MessageFlagType | null;
416
- poll_info?: PollSendType | null;
417
- poll_results?: PollResultType | null;
418
- delivery_info?: DeliveryInfoType | null;
419
- raw_data?: {
420
- translations?: Record<string, string>;
421
- [key: string]: unknown;
422
- } | null;
423
- }
424
- >,
425
- {
426
- reactions?: ReactionType[];
427
- message_payload?: SingleMessagePayload;
428
- highlight?: number;
429
- is_private_note?: boolean;
430
- }
431
- >;
432
-
433
- export type MessageFlagType = {
434
- status: boolean;
435
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
436
- response_id?: string;
437
- response_timestamp?: string;
438
- response_email?: string;
439
- flagged_by?: string;
440
- flagged_at?: string;
441
- response_phone?: string;
442
- };
443
-
444
- export type MessageSendType = {
445
- queue_id: string;
446
- queue_position: string;
447
- };
448
-
449
- export type MessageBroadcastType = {
450
- broadcast_id: string;
451
- };
452
-
453
- /* -------------------------------------------------------------------------- */
454
-
455
- export type TicketType = OverrideProperties<
456
- Tables<'tbl_chat_tickets'>,
457
- {
458
- label_ids: { [key: string]: boolean };
459
- hubspot_metadata: {
460
- id?: string;
461
- type?: string;
462
- hubId?: string;
463
- pipeline: {
464
- id: string;
465
- label: string;
466
- };
467
- object_data?: HubspotObjectDataType;
468
- } | null;
469
- freshdesk_metadata: Record<string, string>;
470
- close_ticket_metadata?:
471
- | {
472
- closed_by: string;
473
- closed_at: string;
474
- closed_message?: string | null;
475
- send_reply_message_id?: string | null;
476
- }
477
- | any;
478
- }
479
- > & {
480
- chat?: ChatType;
481
- quoted_message?: MessageType;
482
- };
483
-
484
- export type ContactType = Merge<
485
- Tables<'tbl_contacts'>,
486
- {
487
- chats: ChatType[] | null;
488
- chat_ids?: string[];
489
- }
490
- >;
491
- export type ReactionType = Tables<'tbl_chat_reactions'>;
492
-
493
- export type NotificationType = Tables<'tbl_chat_notifications'>;
494
-
495
- export type ChatAccessType = Merge<
496
- TablesUpdate<'tbl_org_members'>,
497
- {
498
- has_access?: boolean;
499
- email: string | null;
500
- }
501
- >;
502
-
503
- export type QueueJobTypes = {
504
- addedTimestamp: number;
505
- attemptsMade: number;
506
- attemptsStarted: number;
507
- data: {
508
- body: string;
509
- chat_id: string;
510
- };
511
- finishedTimestamp: number;
512
- id: string;
513
- message_id: string;
514
- processedTimestamp: number;
515
- stacktrace: string[];
516
- status: string;
517
- };
518
-
519
- export type PhoneQueueStatusType = {
520
- active: number;
521
- failed: number;
522
- completed: number;
523
- is_running: boolean;
524
- pending: number;
525
- };
526
-
527
- export type PhoneType = OverrideProperties<
528
- Tables<'tbl_org_phones'>,
529
- {
530
- queue_status: {
531
- [key: string]: PhoneQueueStatusType;
532
- };
533
- }
534
- >;
535
-
536
- export type PhoneInfoType = Merge<
537
- Pick<
538
- PhoneType,
539
- | 'created_at'
540
- | 'first_connected_at'
541
- | 'is_ready'
542
- | 'label_ids'
543
- | 'org_id'
544
- | 'org_phone'
545
- | 'phone_id'
546
- | 'phone_image'
547
- | 'phone_name'
548
- | 'qr_code'
549
- | 'updated_at'
550
- | 'wa_state'
551
- >,
552
- {
553
- labels: string[];
554
- }
555
- >;
556
-
557
- /* -------------------------------- CONSTANTS ------------------------------- */
558
-
559
- export const labelColors = [
560
- '#9333EA',
561
- '#0D9488',
562
- '#DB2777',
563
- '#2563EB',
564
- '#F97316',
565
- ];
566
-
567
- export const enumChatColors = [
568
- '#B4876E',
569
- '#A5B337',
570
- '#06CF9C',
571
- '#25D366',
572
- '#02A698',
573
- '#7D9EF1',
574
- '#007BFC',
575
- '#5E47DE',
576
- '#7F66FF',
577
- '#9333EA',
578
- '#FA6533',
579
- '#C4532D',
580
- '#DC2626',
581
- '#FF2E74',
582
- '#DB2777',
583
- ] as const;
584
-
585
- export type RepeatDaysType =
586
- | 'monday'
587
- | 'tuesday'
588
- | 'wednesday'
589
- | 'thursday'
590
- | 'friday'
591
- | 'saturday'
592
- | 'sunday';
593
- export type RepeatIntervalType = 'day' | 'week' | 'month';
594
-
595
- export enum WhatsappGroupActionEnum {
596
- ADD = 'add',
597
- REMOVE = 'remove',
598
- PROMOTE = 'promote',
599
- DEMOTE = 'demote',
600
- INVITE = 'invite',
601
- LEAVE = 'leave',
602
- ANNOUNCE_TRUE = 'announce_true',
603
- ANNOUNCE_FALSE = 'announce_false',
604
- RESTRICT_TRUE = 'restrict_true',
605
- RESTRICT_FALSE = 'restrict_false',
606
- MEMBERADDMODE_TRUE = 'memberaddmode_true',
607
- MEMBERADDMODE_FALSE = 'memberaddmode_false',
608
- SUBJECT = 'subject',
609
- DESC = 'desc',
610
- CALL = 'call',
611
- }
612
-
613
- /* -------------------------- LISTING ENDPOINT -------------------------- */
614
-
615
- type ListingType = {
616
- from?: number;
617
- to?: number;
618
- count?: number;
619
- };
620
-
621
- export type ListNotificationsType = Merge<
622
- ListingType,
623
- {
624
- notifictions?: NotificationType[];
625
- }
626
- >;
627
-
628
- export type ListChatMessagesType = Merge<
629
- ListingType,
630
- {
631
- messages?: MessageType[];
632
- }
633
- >;
634
-
635
- export type ListContactsType = Merge<
636
- ListingType,
637
- {
638
- contacts?: ContactType[];
639
- }
640
- >;
641
-
642
- export type ListTicketsType = Merge<
643
- ListingType,
644
- {
645
- tickets?: TicketType[];
646
- }
647
- >;
648
-
649
- export type ListChatsType = Merge<
650
- ListingType,
651
- {
652
- chats?: ChatType[];
653
- }
654
- >;
655
-
656
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
657
-
658
- export const SUPPORTED_TYPES = [
659
- 'chat',
660
- 'sticker',
661
- 'image',
662
- 'video',
663
- 'document',
664
- 'vcard',
665
- 'multi_vcard',
666
- 'audio',
667
- 'ptt',
668
- 'poll_creation',
669
- 'location',
670
- 'ciphertext',
671
- ] as const;
672
-
673
- export type SendMessageContent = {
674
- message_type?: (typeof SUPPORTED_TYPES)[number];
675
- body?: string;
676
- media?: MediaType;
677
- contact_ids?: string[];
678
- location?: {
679
- latitude: string;
680
- longitude: string;
681
- options?: { name?: string; address?: string; url?: string };
682
- };
683
- poll?: PollSendType;
684
- quoted_message_id?: string;
685
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
686
- broadcast_id?: string;
687
- performed_by?: string;
688
- options?: Record<string, any>;
689
- };
690
-
691
- export type QuickReplyContent = Omit<
692
- SendMessageContent,
693
- 'broadcast_id' | 'variables'
694
- >;
695
-
696
- export type ScheduleMessagePayload = {
697
- scheduled_id?: string;
698
- is_repeat?: boolean | null;
699
- scheduled_at: string;
700
- repeat_config?: {
701
- timezone?: string;
702
- repeat_ends?: string;
703
- repeat_interval?: RepeatIntervalType;
704
- repeat_value?: number;
705
- repeat_days?: RepeatDaysType[];
706
- };
707
- };
708
-
709
- export type BroadcastVariableType = {
710
- chat_id: string;
711
- values: { [key: string]: string };
712
- };
713
-
714
- export type BroadcastMessagePayload = SendMessageContent & {
715
- chat_ids: string[];
716
- broadcast_id?: string;
717
- variables?: BroadcastVariableType[];
718
- delay?: number;
719
- };
720
-
721
- export type SingleMessagePayload = SendMessageContent & {
722
- chat_id: string;
723
- job_id?: string;
724
- priority?: number;
725
- scheduled_id?: string;
726
- };
727
-
728
- export type MessageAttachmentFileTypes =
729
- | 'image'
730
- | 'audio'
731
- | 'document'
732
- | 'video';
733
-
734
- export type AttachmentFileType = {
735
- result: string;
736
- file: File | null;
737
- type: MessageAttachmentFileTypes;
738
- localFileURL?: string;
739
- };
740
-
741
- export type AttachmentLinkType = {
742
- link: {
743
- url: string;
744
- type: MessageAttachmentFileTypes;
745
- name: string;
746
- mimetype?: string;
747
- };
748
- };
749
-
750
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
751
-
752
- /* -------------------------------- BROADCAST ------------------------------- */
753
-
754
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
755
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
756
- } & {
757
- chats: ChatType[];
758
- };
759
-
760
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
761
-
762
- export type ChatLogType = {
763
- log: Tables<'view_chat_logs'>;
764
- operations: Tables<'tbl_chat_logs'>[];
765
- };
766
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
767
-
768
- export type ChatParticipantOperationPayload = {
769
- participant_ids: string[];
770
- chat_ids: string[];
771
- performed_by: string;
772
- force_add_participants?: boolean;
773
- };
774
-
775
- export type ChatOperationReturn = {
776
- [participant_id: string]: {
777
- is_success: boolean;
778
- message?: string;
779
- code?: number;
780
- isInviteV4Sent?: boolean;
781
- };
782
- };
783
-
784
- /* ----------------------- BILLING - STRIPE ----------------------- */
785
-
786
- export type ChargebeeSubscription = Subscription;
787
- export type ChargebeeCustomer = Customer;
788
- export type ChargebeePrice = ItemPrice;
789
- export type ChargebeeUpcomingInvoice =
790
- Estimate.RenewalEstimateResponse['estimate'];
791
- export type ChargebeeLineItem =
792
- HostedPage.CheckoutNewForItemsInputParam['subscription_items'];
793
-
794
- /* -------------------------------- REALTIME -------------------------------- */
795
-
796
- export type PhoneStateType = {
797
- loading: boolean;
798
- state: string;
799
- sync: number;
800
- percent: number | null;
801
- message?: string;
802
- error?: string;
803
- };
804
-
805
- /* ------------------------------- INTEGRATIONS ----------------------------- */
806
-
807
- export type ChatInfoType = Merge<
808
- ChatType,
809
- {
810
- members: {
811
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
812
- } | null;
813
- chat_labels: string | null;
814
- custom_properties: { [key: string]: string } | null;
815
- }
816
- >;
817
-
818
- export type TicketInfoType = {
819
- chat: ChatInfoType;
820
- message: {
821
- body: string;
822
- chat_id: string;
823
- org_phone: string;
824
- timestamp: string;
825
- media_path: string;
826
- message_id: string;
827
- sender_name: string;
828
- performed_by: string;
829
- sender_phone: string;
830
- };
831
- ticket: {
832
- org_id: string;
833
- status: string;
834
- subject: string;
835
- assignee: string;
836
- due_date: string;
837
- priority: 0 | 1 | 2 | 3 | 4;
838
- raised_by: string;
839
- ticket_id: string;
840
- created_at: string;
841
- assigned_by: string;
842
- ticket_labels: string;
843
- quoted_message_id: string;
844
- ticket_custom_properties: { [key: string]: string } | null;
845
- closed_at: string;
846
- closed_by: string;
847
- closed_message: string;
848
- first_assigned_at: string | null;
849
- is_deleted: boolean;
850
- };
851
- attached_messages: {
852
- body: string;
853
- chat_id: string;
854
- org_phone: string;
855
- timestamp: string;
856
- media_path: string;
857
- message_id: string;
858
- sender_name: string;
859
- performed_by: string;
860
- sender_phone: string;
861
- }[];
862
- };
863
-
864
- export type IntegrationLogObjectType =
865
- | 'chat'
866
- | 'message'
867
- | 'reaction'
868
- | 'ticket'
869
- | 'phone';
870
- export enum IntegrationLogType {
871
- NEW_CHAT = 'chat.created',
872
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
873
- NEW_MESSAGE = 'message.created',
874
- MESSAGE_UPDATED = 'message.updated',
875
- MESSAGE_DELETED = 'message.deleted',
876
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
877
- MESSAGE_FLAGGED = 'message.flagged',
878
- MESSAGE_UNFLAGGED = 'message.unflagged',
879
- MESSAGE_TICKET_ATTACHED = 'message.ticket.attached',
880
- REACTION_CREATED = 'reaction.created',
881
- REACTION_UPDATED = 'reaction.updated',
882
- NEW_TICKET = 'ticket.created',
883
- TICKET_UPDATED = 'ticket.updated',
884
- TICKET_DELETED = 'ticket.deleted',
885
- PHONE_DISCONNECTED = 'org.phone.disconnected',
886
- PHONE_CONNECTED = 'org.phone.connected',
887
- PHONE_UPDATED = 'org.phone.updated',
888
- PHONE_QR_UPDATED = 'org.phone.qr',
889
- NOTE_CREATED = 'note.created',
890
- CHAT_CUSTOM_PROPERTIES_UPDATED = 'chat.custom_properties.updated',
891
- }
892
-
893
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
894
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
895
- ? TicketInfoType
896
- : T extends IntegrationLogType.NEW_CHAT
897
- ? Tables<'tbl_chats'>
898
- : T extends
899
- | IntegrationLogType.NEW_MESSAGE
900
- | IntegrationLogType.MESSAGE_UPDATED
901
- | IntegrationLogType.MESSAGE_DELETED
902
- | IntegrationLogType.MESSAGE_ACK_UPDATED
903
- | IntegrationLogType.MESSAGE_FLAGGED
904
- | IntegrationLogType.MESSAGE_UNFLAGGED
905
- | IntegrationLogType.MESSAGE_TICKET_ATTACHED
906
- ? Tables<'tbl_chat_messages'>
907
- : T extends
908
- | IntegrationLogType.REACTION_CREATED
909
- | IntegrationLogType.REACTION_UPDATED
910
- ? Tables<'tbl_chat_reactions'>
911
- : T extends
912
- | IntegrationLogType.PHONE_DISCONNECTED
913
- | IntegrationLogType.PHONE_CONNECTED
914
- | IntegrationLogType.PHONE_UPDATED
915
- | IntegrationLogType.PHONE_QR_UPDATED
916
- ? Tables<'tbl_org_phones'>
917
- : T extends IntegrationLogType.NOTE_CREATED
918
- ? Tables<'tbl_chat_notes'>
919
- : {
920
- [key: string]: unknown;
921
- };
922
-
923
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
924
- OverrideProperties<
925
- Tables<'tbl_integration_logs'>,
926
- {
927
- integration_name: T;
928
- metadata: {
929
- event: IntegrationLogMetadataType<T> & {
930
- event_type: string;
931
- org_id: string;
932
- previous_attributes: {
933
- [key: string]: unknown;
934
- };
935
- };
936
- hook_id: string;
937
- name: string;
938
- };
939
- }
940
- >;
941
-
942
- export type APIAuthDetails = {
943
- org_details: Tables<'view_org'> | null;
944
- phone_details: Tables<'tbl_org_phones'> | null;
945
- token_details: Tables<'tbl_integration_tokens'> | null;
946
- };
947
-
948
- export type WebhookDataType = OverrideProperties<
949
- Tables<'tbl_integration_hooks'>,
950
- {
951
- integration_name: string[];
952
- }
953
- >;
954
-
955
- export type HubspotObjectDataType = {
956
- createdAt: string;
957
- archived: boolean;
958
- id: string;
959
- type: 'contacts' | 'tickets' | 'companies';
960
- properties: Record<
961
- string,
962
- {
963
- groupLabel: string;
964
- groupName: string;
965
- propertyKeyName: string;
966
- propertyKey: string;
967
- propertyInternalValue: string;
968
- propertyValue: string;
969
- propertyType: string;
970
- propertyFieldType: string;
971
- }[]
972
- >;
973
- };
974
-
975
- /* ---------------------------- USER PREFERENCES ---------------------------- */
976
-
977
- export type UserPreferences = {
978
- theme: 'light' | 'dark';
979
- language: 'en' | 'es';
980
- left_sidebar_open: boolean;
981
- right_sidepanel_open: boolean;
982
- sync_wa_unread_count: boolean;
983
- pinned_chats: string[];
984
- archived_chats: string[];
985
- closed_chats: Record<string, number>;
986
- periskope_chat_limit: number;
987
- notifications: Record<string, boolean>;
988
- };
989
-
990
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
991
-
992
- export interface MostActiveMember {
993
- sender_phone: string;
994
- total_messages: number;
995
- }
996
-
997
- export interface GroupAnalyticsResult {
998
- total_messages: number;
999
- total_joins: number;
1000
- total_leaves: number;
1001
- total_removes: number;
1002
- total_reactions: number;
1003
- most_active_members: MostActiveMember[];
1004
- }
1005
-
1006
- export interface TimeRange {
1007
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
1008
- endDateTime: string;
1009
- }
1010
-
1011
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
1012
-
1013
- export type PollSendType = {
1014
- pollName: string;
1015
- pollOptions: string[];
1016
- options?: {
1017
- allowMultipleAnswers?: boolean;
1018
- messageSecret?: number[] | null;
1019
- pollId?: string;
1020
- };
1021
- };
1022
-
1023
- export type PollResultType = {
1024
- [name: string]: Record<string, string>;
1025
- };
1026
-
1027
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
1028
-
1029
- export type CreateGroupOptions = {
1030
- messagesAdminsOnly?: boolean;
1031
- infoAdminsOnly?: boolean;
1032
- addMembersAdminsOnly?: boolean;
1033
- image?: string;
1034
- name?: string;
1035
- description?: string;
1036
- initiated_by?: string;
1037
- admins?: string[];
1038
- force_add_participants?: boolean;
1039
- };
1040
-
1041
- /* ------------------------------ DELIVERY INFO ----------------------------- */
1042
-
1043
- export type DeliveryInfoType = {
1044
- delivered: Record<string, number | undefined>;
1045
- read: Record<string, number | undefined>;
1046
- pending: string[];
1047
- read_count: number;
1048
- delivered_count: number;
1049
- };
1050
-
1051
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1052
-
1053
- export type OrgCreditsType = {
1054
- org_id: string;
1055
- recurring_allowance: number; // recurring credits replenished every cycle
1056
- recurring_balance: number; // recurring credits remaining in current cycle
1057
- topup_balance: number; // topup credits remaining
1058
- total_credits_used: number; // total credits used in current cycle
1059
- next_renewal_date: string;
1060
- topup_credits_used: number; // topup credits used in current cycle
1061
- recurring_credits_used: number; // recurring credits used in current cycle
1062
- };
1063
-
1064
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
1065
-
1066
- export type ChatRuleInfoType = {
1067
- chat: Merge<
1068
- Pick<
1069
- Tables<'view_chats'>,
1070
- | 'assigned_to'
1071
- | 'chat_id'
1072
- | 'chat_name'
1073
- | 'chat_type'
1074
- | 'created_at'
1075
- | 'group_description'
1076
- | 'info_admins_only'
1077
- | 'org_id'
1078
- | 'org_phone'
1079
- | 'chat_org_phones'
1080
- | 'messages_admins_only'
1081
- | 'custom_properties'
1082
- | 'initiated_by'
1083
- >,
1084
- {
1085
- has_flagged_messages: boolean;
1086
- labels: string[];
1087
- members: string[];
1088
- custom_properties: { [key: string]: string } | null;
1089
- }
1090
- >;
1091
- };
1092
-
1093
- export type SenderRuleInfoType = Merge<
1094
- Omit<
1095
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1096
- | 'verified_name'
1097
- | 'verified_level'
1098
- | 'updated_at'
1099
- | 'short_name'
1100
- | 'pushname'
1101
- | 'periskope_name'
1102
- | 'org_phone'
1103
- | 'number'
1104
- | 'name'
1105
- | 'label_ids'
1106
- | 'is_wa_contact'
1107
- | 'is_user'
1108
- | 'is_my_contact'
1109
- | 'is_me'
1110
- | 'is_imported'
1111
- | 'is_group'
1112
- | 'is_blocked'
1113
- | 'contact_color'
1114
- | 'business_profile'
1115
- | 'id'
1116
- | 'contact_image'
1117
- | 'contact_type'
1118
- | 'chat_id'
1119
- | 'is_business'
1120
- | 'is_enterprise'
1121
- | 'is_super_admin'
1122
- | 'contact_lid'
1123
- >,
1124
- {
1125
- is_internal: boolean;
1126
- labels: string[] | null;
1127
- }
1128
- >;
1129
-
1130
- export type MessageRuleInfoType = {
1131
- chat: ChatRuleInfoType['chat'];
1132
- sender: SenderRuleInfoType;
1133
- message: OverrideProperties<
1134
- Omit<
1135
- Tables<'tbl_chat_messages'>,
1136
- | 'vcards'
1137
- | 'updated_at'
1138
- | 'unique_id'
1139
- | 'token'
1140
- | 'to'
1141
- | 'sent_message_id'
1142
- | 'raw_data'
1143
- | 'delivery_info'
1144
- | 'poll_results'
1145
- | 'poll_info'
1146
- | 'order_id'
1147
- | 'mentioned_ids'
1148
- | 'media_key'
1149
- | 'location'
1150
- | 'links'
1151
- | 'is_status'
1152
- | 'is_starred'
1153
- | 'is_gif'
1154
- | 'is_forwarded'
1155
- | 'is_ephemeral'
1156
- | 'is_deleted'
1157
- | 'fts'
1158
- | 'quoted_message_id'
1159
- | 'invite_v4'
1160
- | 'id'
1161
- | 'has_reaction'
1162
- | 'has_media'
1163
- | 'duration'
1164
- | 'broadcast'
1165
- | 'broadcast_id'
1166
- | 'device_type'
1167
- | 'forwarding_score'
1168
- | 'from'
1169
- | 'from_me'
1170
- | 'prev_body'
1171
- | 'flag_response_time'
1172
- | 'flag_metadata'
1173
- | 'ack'
1174
- >,
1175
- {
1176
- media: MediaType | null;
1177
- }
1178
- >;
1179
- };
1180
-
1181
- export type ReactionRuleInfoType = {
1182
- chat: MessageRuleInfoType['chat'];
1183
- sender: MessageRuleInfoType['sender'];
1184
- message: MessageRuleInfoType['message'];
1185
- reaction: Pick<
1186
- Tables<'tbl_chat_reactions'>,
1187
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1188
- >;
1189
- };
1190
-
1191
- export type TicketRuleInfoType = {
1192
- chat: MessageRuleInfoType['chat'];
1193
- sender: MessageRuleInfoType['sender'];
1194
- ticket: Merge<
1195
- Pick<
1196
- Tables<'tbl_chat_tickets'>,
1197
- | 'org_id'
1198
- | 'status'
1199
- | 'chat_id'
1200
- | 'subject'
1201
- | 'assignee'
1202
- | 'due_date'
1203
- | 'priority'
1204
- | 'raised_by'
1205
- | 'ticket_id'
1206
- | 'created_at'
1207
- | 'is_deleted'
1208
- >,
1209
- {
1210
- labels: string[] | null;
1211
- custom_properties: { [key: string]: string } | null;
1212
- }
1213
- >;
1214
- message: MessageRuleInfoType['message'];
1215
- };
1216
-
1217
- export type TaskRuleInfoType<
1218
- T extends 'ticket' | 'chat' | 'message' | 'todo' = 'todo',
1219
- > = {
1220
- associated_object_data: T extends 'message'
1221
- ? MessageRuleInfoType
1222
- : T extends 'ticket'
1223
- ? TicketRuleInfoType
1224
- : T extends 'chat'
1225
- ? ChatRuleInfoType
1226
- : null;
1227
- task: Pick<
1228
- TaskType,
1229
- | 'org_id'
1230
- | 'title'
1231
- | 'notes'
1232
- | 'status'
1233
- | 'assignee'
1234
- | 'due_date'
1235
- | 'priority'
1236
- | 'task_id'
1237
- | 'created_at'
1238
- >;
1239
- };
1240
-
1241
- export type FeatureFlagReturnType = Record<string, boolean>;
1242
-
1243
- export type RuleLogsType = OverrideProperties<
1244
- Tables<'tbl_rules_logs'>,
1245
- {
1246
- actions_progress: {
1247
- action_id: string;
1248
- action_type: Rule['actions'][number]['type'];
1249
- action_delay: Rule['actions'][number]['delay'];
1250
- ran_at: string | null;
1251
- action_status: 'success' | 'failed' | 'pending';
1252
- action_response: {
1253
- success: boolean;
1254
- data: Record<string, unknown> | null;
1255
- error: {
1256
- message: string;
1257
- name: string;
1258
- stack?: string;
1259
- _error?: Error | Record<string, unknown>;
1260
- } | null;
1261
- };
1262
- }[];
1263
- metadata: {
1264
- conditions: Rule['conditions'];
1265
- actions: Rule['actions'];
1266
- rule_metadata: Pick<
1267
- Rule,
1268
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1269
- >;
1270
- data: Record<string, unknown>;
1271
- };
1272
- conditions_progress: {
1273
- is_valid: boolean;
1274
- validation_progress: Record<
1275
- string,
1276
- {
1277
- res: boolean;
1278
- filter: Filter;
1279
- value: unknown;
1280
- }
1281
- >;
1282
- checked_at: string | null;
1283
- };
1284
- }
1285
- >;
1286
-
1287
- /************************** TASKS ***************************/
1288
-
1289
- export type ChatMetadataType = {
1290
- type: 'chat';
1291
- index: 'chat_id';
1292
- id: string;
1293
- object: Pick<ChatType, 'chat_id' | 'org_phone' | 'org_id'>;
1294
- };
1295
-
1296
- export type MessageMetadataType = {
1297
- type: 'message';
1298
- index: 'message_id';
1299
- id: string;
1300
- object: Pick<
1301
- MessageType,
1302
- | 'message_id'
1303
- | 'org_phone'
1304
- | 'chat_id'
1305
- | 'sender_phone'
1306
- | 'org_id'
1307
- | 'is_private_note'
1308
- >;
1309
- };
1310
-
1311
- export type TicketMetadataType = {
1312
- type: 'ticket';
1313
- index: 'ticket_id';
1314
- id: string;
1315
- object: Pick<
1316
- TicketType,
1317
- 'ticket_id' | 'quoted_message_id' | 'chat_id' | 'org_id'
1318
- >;
1319
- };
1320
-
1321
- export type AssociatedObjectMetadataType<
1322
- T extends 'chat' | 'message' | 'ticket' | 'todo' =
1323
- | 'chat'
1324
- | 'message'
1325
- | 'ticket'
1326
- | 'todo',
1327
- > = T extends 'chat'
1328
- ? ChatMetadataType
1329
- : T extends 'message'
1330
- ? MessageMetadataType
1331
- : T extends 'ticket'
1332
- ? TicketMetadataType
1333
- : null;
1334
-
1335
- export const isChatTask = (task: TaskType): task is TaskType<'chat'> =>
1336
- task.associated_object_metadata?.type === 'chat';
1337
-
1338
- export const isMessageTask = (task: TaskType): task is TaskType<'message'> =>
1339
- task.associated_object_metadata?.type === 'message';
1340
-
1341
- export const isTicketTask = (task: TaskType): task is TaskType<'ticket'> =>
1342
- task.associated_object_metadata?.type === 'ticket';
1343
-
1344
- export const isTodoTask = (task: TaskType): task is TaskType<'todo'> =>
1345
- task.type === 'todo';
1346
-
1347
- export type TaskType<
1348
- T extends 'chat' | 'message' | 'ticket' | 'todo' =
1349
- | 'chat'
1350
- | 'message'
1351
- | 'ticket'
1352
- | 'todo',
1353
- > = OverrideProperties<
1354
- Tables<'tbl_org_tasks'>,
1355
- {
1356
- reminder_setting: {
1357
- remind_in:
1358
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1359
- | string
1360
- | null;
1361
- repeat?: {
1362
- frequency: number;
1363
- interval: 'days' | 'weeks' | 'months' | 'years';
1364
- end: 'never' | 'after' | 'on';
1365
- on?: string;
1366
- };
1367
- } | null;
1368
- associated_object_metadata: AssociatedObjectMetadataType<T>;
1369
- status: 'open' | 'inprogress' | 'closed';
1370
- priority: 1 | 2 | 3;
1371
- completed_metadata?: {
1372
- completed_at: string;
1373
- completed_by: string;
1374
- } | null;
1375
- type: T;
1376
- }
1377
- >;
1378
-
1379
- type Choice = {
1380
- id: number;
1381
- label: string;
1382
- value: string;
1383
- position: number;
1384
- };
1385
-
1386
- export type FreshdeskFieldType = {
1387
- id: number;
1388
- name: string;
1389
- type: string;
1390
- label: string;
1391
- default: boolean;
1392
- archived: boolean;
1393
- position: number;
1394
- created_at: string;
1395
- updated_at: string;
1396
- customers_can_edit: boolean;
1397
- label_for_customers: string;
1398
- required_for_agents: boolean;
1399
- customers_can_filter: boolean;
1400
- required_for_closure: boolean;
1401
- displayed_to_customers: boolean;
1402
- required_for_customers: boolean;
1403
- choices?: Choice[];
1404
- };
1405
-
1406
- export type OrgWarmup = OverrideProperties<
1407
- Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1408
- {
1409
- warmup_chats: { [key: string]: string };
1410
- }
1411
- >;
1412
-
1413
- /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1414
-
1415
- export type FreshdeskIntegrationTokenType = OverrideProperties<
1416
- Tables<'tbl_integration_tokens'>,
1417
- {
1418
- type: 'freshdesk';
1419
- token_metadata: {
1420
- url: string;
1421
- apiKey: string;
1422
- fields: {
1423
- ticket: FreshdeskFieldType[];
1424
- company: FreshdeskFieldType[];
1425
- contact: FreshdeskFieldType[];
1426
- };
1427
- automation: {
1428
- id: number | string;
1429
- meta: {
1430
- total_count: number;
1431
- total_active_count: 17;
1432
- };
1433
- name: string;
1434
- active: boolean;
1435
- events: Array<{
1436
- to?: string;
1437
- from?: string;
1438
- field_name: string;
1439
- value?: string;
1440
- }>;
1441
- actions: Array<{
1442
- url: string;
1443
- content: Record<string, string>;
1444
- field_name: string;
1445
- content_type: string;
1446
- request_type: string;
1447
- content_layout: string;
1448
- }>;
1449
- summary: {
1450
- events: Array<string>;
1451
- actions: Array<string>;
1452
- performer: string;
1453
- conditions: {
1454
- [key: string]: Array<string>;
1455
- };
1456
- };
1457
- outdated: boolean;
1458
- position: number;
1459
- performer: {
1460
- type: string;
1461
- };
1462
- conditions: Array<{
1463
- name: string;
1464
- match_type: string;
1465
- properties: Array<{
1466
- value: Array<string>;
1467
- operator: string;
1468
- field_name: string;
1469
- resource_type: string;
1470
- case_sensitive: boolean;
1471
- }>;
1472
- }>;
1473
- created_at: string;
1474
- updated_at: string;
1475
- description: string | null;
1476
- last_updated_by: string | number;
1477
- affected_tickets_count: number | null;
1478
- };
1479
- org_details: {
1480
- address: {
1481
- city: string;
1482
- state: string;
1483
- street: string;
1484
- country: string;
1485
- postalcode: string;
1486
- };
1487
- timezone: string;
1488
- bundle_id: string;
1489
- tier_type: string;
1490
- account_id: number;
1491
- cloud_type: string;
1492
- data_center: string;
1493
- account_name: string;
1494
- total_agents: {
1495
- full_time: number;
1496
- occasional: number;
1497
- collaborators: number;
1498
- field_service: number;
1499
- };
1500
- account_domain: string;
1501
- contact_person: {
1502
- email: string;
1503
- lastname: string;
1504
- firstname: string;
1505
- };
1506
- hipaa_compliant: boolean;
1507
- organisation_id: number;
1508
- organisation_name: string;
1509
- };
1510
- custom_fields: {
1511
- ticket: FreshdeskFieldType[];
1512
- company: FreshdeskFieldType[];
1513
- contact: FreshdeskFieldType[];
1514
- };
1515
- integration_org_id: string | number;
1516
- ticket_auto_creation?: boolean;
1517
- };
1518
- }
1519
- >;
1520
-
1521
- export type ZohodeskIntegrationTokenType = OverrideProperties<
1522
- Tables<'tbl_integration_tokens'>,
1523
- {
1524
- type: 'zohodesk';
1525
- token_metadata: {
1526
- scope: string;
1527
- domain: string;
1528
- fields: Array<{
1529
- id: string;
1530
- name: string;
1531
- type: string;
1532
- apiName: string;
1533
- toolTip: string;
1534
- i18NLabel: string;
1535
- maxLength: number;
1536
- isMandatory: boolean;
1537
- toolTipType: string;
1538
- displayLabel: string;
1539
- isCustomField: boolean;
1540
- isEncryptedField: boolean;
1541
- showToHelpCenter: boolean;
1542
- }>;
1543
- org_id: string;
1544
- webhooks: {
1545
- id: string;
1546
- url: string;
1547
- name: string;
1548
- type: string;
1549
- createdBy: string;
1550
- isEnabled: boolean;
1551
- createdTime: string;
1552
- description: string;
1553
- modifiedTime: string;
1554
- subscriptions: {
1555
- [key: string]: {
1556
- departmentIds: string[];
1557
- includePrevState: boolean;
1558
- };
1559
- };
1560
- ignoreSourceId: boolean | null;
1561
- includeEventsFrom: string[];
1562
- };
1563
- api_domain: string;
1564
- authDomain: string;
1565
- expires_in: number;
1566
- token_type: string;
1567
- departments: Array<{
1568
- id: string;
1569
- name: string;
1570
- hasLogo: boolean;
1571
- creatorId: string;
1572
- isDefault: boolean;
1573
- isEnabled: boolean;
1574
- chatStatus: string;
1575
- createdTime: string;
1576
- description: string | null;
1577
- sanitizedName: string;
1578
- nameInCustomerPortal: string;
1579
- isAssignToTeamEnabled: boolean;
1580
- isVisibleInCustomerPortal: boolean;
1581
- }>;
1582
- org_details: {
1583
- id: number;
1584
- fax: string;
1585
- zip: string;
1586
- city: string;
1587
- alias: string | null;
1588
- state: string;
1589
- mobile: string;
1590
- street: string;
1591
- country: string;
1592
- edition: string;
1593
- logoURL: string;
1594
- website: string;
1595
- isDefault: boolean;
1596
- portalURL: string;
1597
- faviconURL: string;
1598
- portalName: string;
1599
- companyName: string;
1600
- description: string | null;
1601
- phoneNumber: string | null;
1602
- currencyCode: string;
1603
- isAdminInOrg: boolean;
1604
- employeeCount: number;
1605
- currencyLocale: string;
1606
- currencySymbol: string;
1607
- primaryContact: string;
1608
- isSandboxPortal: boolean;
1609
- isPayloadEncryptionEnabled: boolean;
1610
- };
1611
- access_token: string;
1612
- refresh_token: string;
1613
- integration_org_id: string | number;
1614
- ticket_auto_creation?: boolean;
1615
- };
1616
- }
1617
- >;
1618
-
1619
- export type ZohoCrmIntegrationTokenType = OverrideProperties<
1620
- Tables<'tbl_integration_tokens'>,
1621
- {
1622
- type: 'zohocrm';
1623
- token_metadata: {
1624
- access_token: string;
1625
- refresh_token: string;
1626
- scope: string;
1627
- api_domain: string;
1628
- token_type: string;
1629
- expires_in: number;
1630
- domain_extension: string;
1631
- authDomain: string;
1632
- integration_org_id: string;
1633
- org_details: {
1634
- id: string;
1635
- name: string;
1636
- currency: string;
1637
- time_zone: string;
1638
- currency_symbol: string;
1639
- currency_locale: string;
1640
- website: string;
1641
- description: string | null;
1642
- phone: string | null;
1643
- mobile: string | null;
1644
- fax: string | null;
1645
- street: string;
1646
- city: string;
1647
- state: string;
1648
- zip: string;
1649
- country: string;
1650
- logo_url: string;
1651
- is_sandbox: boolean;
1652
- is_admin_in_org: boolean;
1653
- employee_count: number;
1654
- primary_contact: string;
1655
- };
1656
- modules: Array<{
1657
- id: string;
1658
- name: string;
1659
- api_name: string;
1660
- singular_label: string;
1661
- plural_label: string;
1662
- is_custom: boolean;
1663
- is_creatable: boolean;
1664
- is_editable: boolean;
1665
- is_deletable: boolean;
1666
- is_webform_supported: boolean;
1667
- sequence_number: number;
1668
- fields: Array<{
1669
- id: string;
1670
- name: string;
1671
- api_name: string;
1672
- data_type: string;
1673
- required: boolean;
1674
- is_custom: boolean;
1675
- is_editable: boolean;
1676
- is_creatable: boolean;
1677
- is_webform_supported: boolean;
1678
- length: number;
1679
- decimal_places: number | null;
1680
- default_value: string | null;
1681
- picklist_values: Array<{
1682
- display_value: string;
1683
- actual_value: string;
1684
- }> | null;
1685
- }>;
1686
- }>;
1687
- webhooks?: {
1688
- id: string;
1689
- url: string;
1690
- name: string;
1691
- events: string[];
1692
- is_active: boolean;
1693
- created_time: string;
1694
- modified_time: string;
1695
- };
1696
- };
1697
- }
1698
- >;
1
+ import {
2
+ Customer,
3
+ Estimate,
4
+ HostedPage,
5
+ ItemPrice,
6
+ Subscription,
7
+ } from 'chargebee';
8
+
9
+ import { Merge, OverrideProperties } from 'type-fest';
10
+ import { Filter, Rule } from './rules.types';
11
+ import { Tables, TablesInsert, TablesUpdate } from './supabase.types';
12
+
13
+ /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
14
+
15
+ /* ------------------------------ PERISKOPE TYPES ------------------------------ */
16
+
17
+ export enum AllPlans {
18
+ FREE_TRIAL = 'free-trial',
19
+ // MONTHLY_STARTER = 'monthly-starter',
20
+ // YEARLY_STARTER = 'yearly-starter',
21
+ // MONTHLY_PRO = 'monthly-pro',
22
+ // YEARLY_PRO = 'yearly-pro',
23
+ ENTERPRISE = 'enterprise',
24
+ MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
25
+ YEARLY_STARTER_SINGLE = 'yearly-starter-single',
26
+ MONTHLY_PRO_SINGLE = 'monthly-pro-single',
27
+ YEARLY_PRO_SINGLE = 'yearly-pro-single',
28
+ }
29
+
30
+ export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
31
+
32
+ export type Enterprise = `${string}-enterprise`;
33
+
34
+ export type OrgPlanEnterprise = {
35
+ subscription_id: string;
36
+ plan_id: Enterprise;
37
+ interval: number;
38
+ frequency: Frequency;
39
+ user_limit: number;
40
+ phone_limit: number;
41
+ current_period_start: number;
42
+ current_period_end: number | null;
43
+ additional_user_limit?: number;
44
+ additional_phone_limit?: number;
45
+ currency: string;
46
+ cancelled_at?: number;
47
+ cancel_schedule_created_at?: number;
48
+ subscription_status?: string;
49
+ };
50
+
51
+ export type OrgPlanNonEnterprise = {
52
+ subscription_id: string;
53
+ plan_id: AllPlans;
54
+ interval: number;
55
+ frequency: Frequency;
56
+ user_limit: number;
57
+ phone_limit: number;
58
+ current_period_end: number;
59
+ current_period_start: number;
60
+ additional_user_limit?: number;
61
+ additional_phone_limit?: number;
62
+ currency: string;
63
+ cancelled_at?: number;
64
+ cancel_schedule_created_at?: number;
65
+ subscription_status?: string;
66
+ };
67
+
68
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
69
+ ? OrgPlanEnterprise
70
+ : T extends AllPlans
71
+ ? OrgPlanNonEnterprise
72
+ : never;
73
+
74
+ export type MicrosurveyData = {
75
+ key: string;
76
+ text: string;
77
+ checked: boolean;
78
+ }[];
79
+
80
+ export type OrgPreferences = {
81
+ disable_ai_flagging?: boolean;
82
+ disable_ai_responder?: boolean;
83
+ ai_responder_default_on?: boolean;
84
+ disable_allow_exports?: boolean;
85
+ disable_view_deleted_messages?: boolean;
86
+ sync_phone_contacts?: boolean;
87
+ mask_phone_numbers?: boolean;
88
+ show_sender_names?: boolean;
89
+ closed_chats?: Record<string, number>;
90
+ auto_read_muted_chats?: boolean;
91
+ member_permissions?: Record<string, boolean>;
92
+ show_active_phone_only_messages_right?: boolean;
93
+ };
94
+
95
+ type OrgPreferenceKey = keyof OrgPreferences;
96
+
97
+ export type OrgPreferencesValue = {
98
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
99
+ }[OrgPreferenceKey];
100
+
101
+ export type OrgAISettings = {
102
+ ai_nickname?: string;
103
+ confidence_score?: string;
104
+ company_overview?: string;
105
+ ai_responder_roles?: string;
106
+ human_agent_roles?: string;
107
+ ticket_creation_rules?: string;
108
+ private_note_creation_rules?: string;
109
+ response_delay_value?: string;
110
+ snooze_delay_value?: string;
111
+ temperature?: string;
112
+ top_p?: string;
113
+ top_k?: string;
114
+ ai_maintain_flag_status?: boolean;
115
+ enable_shift_timing?: boolean;
116
+ shift_start_time?: string;
117
+ shift_end_time?: string;
118
+ };
119
+
120
+ type OrgAISettingsKey = keyof OrgAISettings;
121
+
122
+ export type OrgAISettingsValue = {
123
+ [K in OrgAISettingsKey]: { key: K; value: OrgAISettings[K] };
124
+ }[OrgAISettingsKey];
125
+
126
+ export type CustomPropertySectionType = {
127
+ id: string;
128
+ name: string;
129
+ order: number;
130
+ type: 'chat' | 'ticket';
131
+ properties_order?: {
132
+ [id: string]: number;
133
+ };
134
+ };
135
+
136
+ export enum CustomPropertyValueType {
137
+ DROPDOWN = 'dropdown',
138
+ TEXT = 'text',
139
+ DATE = 'date',
140
+ FILE = 'file',
141
+ PICKLIST = 'picklist',
142
+ DEPENDENT_DROPDOWN = 'dependent_dropdown',
143
+ }
144
+
145
+ export type CustomPropertyMetadataType = {
146
+ section_id?: string;
147
+ };
148
+
149
+ export type CustomPropertyTextPropertiesType = {
150
+ property_value_type: CustomPropertyValueType.TEXT;
151
+ property_value: null;
152
+ property_metadata: CustomPropertyMetadataType;
153
+ };
154
+
155
+ export type CustomPropertyDropdownPropertiesType = {
156
+ property_value_type: CustomPropertyValueType.DROPDOWN;
157
+ property_value: {
158
+ [key: string]: string;
159
+ };
160
+ property_metadata: CustomPropertyMetadataType;
161
+ };
162
+
163
+ export type CustomPropertyPicklistPropertiesType = {
164
+ property_value_type: CustomPropertyValueType.PICKLIST;
165
+ property_value: {
166
+ [key: string]: string;
167
+ };
168
+ property_metadata: CustomPropertyMetadataType;
169
+ };
170
+
171
+ export type CustomPropertyDependentDropdownPropertiesType = {
172
+ property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
173
+ property_value: {
174
+ level_1: {
175
+ value: string;
176
+ label: string;
177
+ level_2: {
178
+ value: string;
179
+ label: string;
180
+ level_3: {
181
+ value: string;
182
+ label: string;
183
+ }[];
184
+ }[];
185
+ }[];
186
+ };
187
+ property_metadata: Merge<
188
+ CustomPropertyMetadataType,
189
+ {
190
+ level_names: {
191
+ level_1: string;
192
+ level_2: string;
193
+ level_3: string;
194
+ };
195
+ }
196
+ >;
197
+ };
198
+
199
+ export type CustomPropertyFilePropertiesType = {
200
+ property_value_type: CustomPropertyValueType.FILE;
201
+ property_value: null;
202
+ property_metadata: CustomPropertyMetadataType;
203
+ };
204
+
205
+ export type CustomPropertyDatePropertiesType = {
206
+ property_value_type: CustomPropertyValueType.DATE;
207
+ property_value: null;
208
+ property_metadata: CustomPropertyMetadataType;
209
+ };
210
+
211
+ export type CustomPropertyType = OverrideProperties<
212
+ Tables<'tbl_custom_properties'>,
213
+ | CustomPropertyDependentDropdownPropertiesType
214
+ | CustomPropertyTextPropertiesType
215
+ | CustomPropertyDropdownPropertiesType
216
+ | CustomPropertyPicklistPropertiesType
217
+ | CustomPropertyFilePropertiesType
218
+ | CustomPropertyDatePropertiesType
219
+ >;
220
+
221
+ export type OrgMetadata = {
222
+ phone_number: string;
223
+ ticket_prefix: string;
224
+ referralSource?: string;
225
+ contact_name?: string;
226
+ surveyData?: MicrosurveyData;
227
+ preferences?: OrgPreferences;
228
+ hubspot: {
229
+ hubspot_pipelines?: {
230
+ id: string;
231
+ label: string;
232
+ default_stage: { id: string; label: string };
233
+ }[];
234
+ hubspot_hidden_fields?: string[];
235
+ };
236
+ partition?: boolean;
237
+ tickets: {
238
+ prefix?: string;
239
+ emoji_ticketing: {
240
+ is_enabled?: boolean;
241
+ is_message_enabled?: boolean;
242
+ message_template?: string;
243
+ };
244
+ disable_auto_attach_message_to_ticket?: boolean;
245
+ };
246
+ attribution?: Object;
247
+ affiliate_id?: string;
248
+ custom_properties?: {
249
+ sections?: CustomPropertySectionType[];
250
+ };
251
+ rules?: {
252
+ limit?: number;
253
+ };
254
+ ai?: {
255
+ flag_prompt?: string;
256
+ };
257
+ display_language?: string;
258
+ custom_invite?: {
259
+ is_enabled: boolean;
260
+ template: string;
261
+ };
262
+ };
263
+
264
+ export type GroupTemplateType = OverrideProperties<
265
+ Tables<'tbl_group_templates'>,
266
+ {
267
+ group_metadata: {
268
+ messagesAdminsOnly?: boolean;
269
+ infoAdminsOnly?: boolean;
270
+ addMembersAdminsOnly?: boolean;
271
+ description?: string;
272
+ admins?: string[];
273
+ };
274
+ }
275
+ >;
276
+
277
+ type AccessScopes = {
278
+ feature_flags: Record<string, boolean>;
279
+ integrations: boolean;
280
+ rules: boolean;
281
+ exports: boolean;
282
+ };
283
+
284
+ export type OrgMembersType = OverrideProperties<
285
+ Tables<'tbl_org_members'>,
286
+ {
287
+ member_metadata: {
288
+ shift_times: {
289
+ [day in
290
+ | 'monday'
291
+ | 'tuesday'
292
+ | 'wednesday'
293
+ | 'thursday'
294
+ | 'friday'
295
+ | 'saturday'
296
+ | 'sunday']?: [[string, string]];
297
+ };
298
+ override_status: boolean;
299
+ [key: string]: any;
300
+ };
301
+ }
302
+ >;
303
+
304
+ export type OrgType = OverrideProperties<
305
+ Merge<
306
+ Tables<'tbl_org'>,
307
+ {
308
+ user: OrgMembersType;
309
+ members: OrgMembersType[];
310
+ phones: Tables<'tbl_org_phones'>[];
311
+ labels: Tables<'tbl_org_labels'>[];
312
+ quick_replies: Tables<'tbl_quick_replies'>[];
313
+ custom_properties: CustomPropertyType[];
314
+ subscription_status: 'active' | 'inactive' | 'unpaid';
315
+ is_enterprise: boolean;
316
+ is_free_trial: boolean;
317
+ is_hubspot_connected: boolean;
318
+ is_freshdesk_connected: boolean;
319
+ is_zohodesk_connected: boolean;
320
+ access_scopes: AccessScopes;
321
+ rules: Rule[];
322
+ phone_limit: number;
323
+ user_limit: number;
324
+ }
325
+ >,
326
+ {
327
+ org_plan: OrgPlan<AllPlans | Enterprise>;
328
+ stripe_customer_details: Customer | null;
329
+ stripe_subscription_details: Array<Subscription> | null;
330
+ stripe_customer_id: Customer['id'] | null;
331
+ org_metadata: OrgMetadata;
332
+ ai_settings: OrgAISettings;
333
+ }
334
+ >;
335
+
336
+ export type ChatMemberType = Merge<
337
+ Tables<'tbl_chat_participants'>,
338
+ Tables<'tbl_contacts'>
339
+ >;
340
+
341
+ export type ChatType = Merge<
342
+ Tables<'view_chats'>,
343
+ {
344
+ chat_id: string;
345
+ latest_message: MessageType | null;
346
+ latest_message_timestamp: number | null;
347
+ latest_message_timestamp_map?: Record<string, number | null>;
348
+ members: { [key: string]: ChatMemberType } | null;
349
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
350
+ chat_access: { [key: string]: boolean };
351
+ label_ids: { [key: string]: boolean };
352
+ chat_org_phones?: string[];
353
+ message_unread_count: number | null;
354
+ hubspot_metadata: {
355
+ id: string;
356
+ type: string;
357
+ hubId: string;
358
+ object_data: HubspotObjectDataType;
359
+ } | null;
360
+ info_admins_only: boolean;
361
+ messages_admins_only: boolean;
362
+ unread_count?: { [key: string]: number };
363
+ active_phone: string | null;
364
+ flag_count_map?: { [key: string]: number };
365
+ is_archived?: boolean;
366
+ is_pinned?: boolean;
367
+ closed_at?: number | null;
368
+ common_chats?: string[];
369
+ freshdesk_metadata?: Record<string, any>;
370
+ zohodesk_metadata?: Record<string, any>;
371
+ pinned_messages?: {
372
+ message_id: string;
373
+ pinned_at: number;
374
+ expires_at: number;
375
+ }[];
376
+ group_metadata?: Record<string, any>;
377
+ snooze_metadata?: {
378
+ snooze_until: number;
379
+ snooze_message?: string;
380
+ snooze_by?: string;
381
+ };
382
+ member_unread_count?: {
383
+ [key: string]: number;
384
+ };
385
+ member_closed_at?: {
386
+ [key: string]: number;
387
+ };
388
+ }
389
+ >;
390
+
391
+ /* -------------------------------------------------------------------------- */
392
+ /* MESSAGE */
393
+ /* -------------------------------------------------------------------------- */
394
+
395
+ export type MediaType = {
396
+ path?: string;
397
+ mimetype?: string;
398
+ filename?: string;
399
+ dimensions?: { width: number; height: number; ar: number };
400
+ size?: number;
401
+ thumbnail?: string;
402
+ filedata?: string;
403
+ compress?: boolean;
404
+ };
405
+
406
+ export type MessageType = Merge<
407
+ OverrideProperties<
408
+ TablesInsert<'tbl_chat_messages'>,
409
+ {
410
+ message_id: string;
411
+ org_id: string;
412
+ org_phone: string;
413
+ chat_id: string;
414
+ message_type: (typeof SUPPORTED_TYPES)[number];
415
+ media: MediaType | null;
416
+ flag_metadata?: MessageFlagType | null;
417
+ poll_info?: PollSendType | null;
418
+ poll_results?: PollResultType | null;
419
+ delivery_info?: DeliveryInfoType | null;
420
+ raw_data?: {
421
+ translations?: Record<string, string>;
422
+ [key: string]: unknown;
423
+ } | null;
424
+ }
425
+ >,
426
+ {
427
+ reactions?: ReactionType[];
428
+ message_payload?: SingleMessagePayload;
429
+ highlight?: number;
430
+ is_private_note?: boolean;
431
+ }
432
+ >;
433
+
434
+ export type MessageFlagType = {
435
+ status: boolean;
436
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
437
+ response_id?: string;
438
+ response_timestamp?: string;
439
+ response_email?: string;
440
+ flagged_by?: string;
441
+ flagged_at?: string;
442
+ response_phone?: string;
443
+ };
444
+
445
+ export type MessageSendType = {
446
+ queue_id: string;
447
+ queue_position: string;
448
+ };
449
+
450
+ export type MessageBroadcastType = {
451
+ broadcast_id: string;
452
+ };
453
+
454
+ /* -------------------------------------------------------------------------- */
455
+
456
+ export type TicketType = OverrideProperties<
457
+ Tables<'tbl_chat_tickets'>,
458
+ {
459
+ label_ids: { [key: string]: boolean };
460
+ hubspot_metadata: {
461
+ id?: string;
462
+ type?: string;
463
+ hubId?: string;
464
+ pipeline: {
465
+ id: string;
466
+ label: string;
467
+ };
468
+ object_data?: HubspotObjectDataType;
469
+ } | null;
470
+ freshdesk_metadata: Record<string, string>;
471
+ close_ticket_metadata?:
472
+ | {
473
+ closed_by: string;
474
+ closed_at: string;
475
+ closed_message?: string | null;
476
+ send_reply_message_id?: string | null;
477
+ }
478
+ | any;
479
+ }
480
+ > & {
481
+ chat?: ChatType;
482
+ quoted_message?: MessageType;
483
+ };
484
+
485
+ export type ContactType = Merge<
486
+ Tables<'tbl_contacts'>,
487
+ {
488
+ chats: ChatType[] | null;
489
+ chat_ids?: string[];
490
+ }
491
+ >;
492
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
493
+
494
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
495
+
496
+ export type ChatAccessType = Merge<
497
+ TablesUpdate<'tbl_org_members'>,
498
+ {
499
+ has_access?: boolean;
500
+ email: string | null;
501
+ }
502
+ >;
503
+
504
+ export type QueueJobTypes = {
505
+ addedTimestamp: number;
506
+ attemptsMade: number;
507
+ attemptsStarted: number;
508
+ data: {
509
+ body: string;
510
+ chat_id: string;
511
+ };
512
+ finishedTimestamp: number;
513
+ id: string;
514
+ message_id: string;
515
+ processedTimestamp: number;
516
+ stacktrace: string[];
517
+ status: string;
518
+ };
519
+
520
+ export type PhoneQueueStatusType = {
521
+ active: number;
522
+ failed: number;
523
+ completed: number;
524
+ is_running: boolean;
525
+ pending: number;
526
+ };
527
+
528
+ export type PhoneType = OverrideProperties<
529
+ Tables<'tbl_org_phones'>,
530
+ {
531
+ queue_status: {
532
+ [key: string]: PhoneQueueStatusType;
533
+ };
534
+ }
535
+ >;
536
+
537
+ export type PhoneInfoType = Merge<
538
+ Pick<
539
+ PhoneType,
540
+ | 'created_at'
541
+ | 'first_connected_at'
542
+ | 'is_ready'
543
+ | 'label_ids'
544
+ | 'org_id'
545
+ | 'org_phone'
546
+ | 'phone_id'
547
+ | 'phone_image'
548
+ | 'phone_name'
549
+ | 'qr_code'
550
+ | 'updated_at'
551
+ | 'wa_state'
552
+ >,
553
+ {
554
+ labels: string[];
555
+ }
556
+ >;
557
+
558
+ /* -------------------------------- CONSTANTS ------------------------------- */
559
+
560
+ export const labelColors = [
561
+ '#9333EA',
562
+ '#0D9488',
563
+ '#DB2777',
564
+ '#2563EB',
565
+ '#F97316',
566
+ ];
567
+
568
+ export const enumChatColors = [
569
+ '#B4876E',
570
+ '#A5B337',
571
+ '#06CF9C',
572
+ '#25D366',
573
+ '#02A698',
574
+ '#7D9EF1',
575
+ '#007BFC',
576
+ '#5E47DE',
577
+ '#7F66FF',
578
+ '#9333EA',
579
+ '#FA6533',
580
+ '#C4532D',
581
+ '#DC2626',
582
+ '#FF2E74',
583
+ '#DB2777',
584
+ ] as const;
585
+
586
+ export type RepeatDaysType =
587
+ | 'monday'
588
+ | 'tuesday'
589
+ | 'wednesday'
590
+ | 'thursday'
591
+ | 'friday'
592
+ | 'saturday'
593
+ | 'sunday';
594
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
595
+
596
+ export enum WhatsappGroupActionEnum {
597
+ ADD = 'add',
598
+ REMOVE = 'remove',
599
+ PROMOTE = 'promote',
600
+ DEMOTE = 'demote',
601
+ INVITE = 'invite',
602
+ LEAVE = 'leave',
603
+ ANNOUNCE_TRUE = 'announce_true',
604
+ ANNOUNCE_FALSE = 'announce_false',
605
+ RESTRICT_TRUE = 'restrict_true',
606
+ RESTRICT_FALSE = 'restrict_false',
607
+ MEMBERADDMODE_TRUE = 'memberaddmode_true',
608
+ MEMBERADDMODE_FALSE = 'memberaddmode_false',
609
+ SUBJECT = 'subject',
610
+ DESC = 'desc',
611
+ CALL = 'call',
612
+ }
613
+
614
+ /* -------------------------- LISTING ENDPOINT -------------------------- */
615
+
616
+ type ListingType = {
617
+ from?: number;
618
+ to?: number;
619
+ count?: number;
620
+ };
621
+
622
+ export type ListNotificationsType = Merge<
623
+ ListingType,
624
+ {
625
+ notifictions?: NotificationType[];
626
+ }
627
+ >;
628
+
629
+ export type ListChatMessagesType = Merge<
630
+ ListingType,
631
+ {
632
+ messages?: MessageType[];
633
+ }
634
+ >;
635
+
636
+ export type ListContactsType = Merge<
637
+ ListingType,
638
+ {
639
+ contacts?: ContactType[];
640
+ }
641
+ >;
642
+
643
+ export type ListTicketsType = Merge<
644
+ ListingType,
645
+ {
646
+ tickets?: TicketType[];
647
+ }
648
+ >;
649
+
650
+ export type ListChatsType = Merge<
651
+ ListingType,
652
+ {
653
+ chats?: ChatType[];
654
+ }
655
+ >;
656
+
657
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
658
+
659
+ export const SUPPORTED_TYPES = [
660
+ 'chat',
661
+ 'sticker',
662
+ 'image',
663
+ 'video',
664
+ 'document',
665
+ 'vcard',
666
+ 'multi_vcard',
667
+ 'audio',
668
+ 'ptt',
669
+ 'poll_creation',
670
+ 'location',
671
+ 'ciphertext',
672
+ ] as const;
673
+
674
+ export type SendMessageContent = {
675
+ message_type?: (typeof SUPPORTED_TYPES)[number];
676
+ body?: string;
677
+ media?: MediaType;
678
+ contact_ids?: string[];
679
+ location?: {
680
+ latitude: string;
681
+ longitude: string;
682
+ options?: { name?: string; address?: string; url?: string };
683
+ };
684
+ poll?: PollSendType;
685
+ quoted_message_id?: string;
686
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
687
+ broadcast_id?: string;
688
+ performed_by?: string;
689
+ options?: Record<string, any>;
690
+ };
691
+
692
+ export type QuickReplyContent = Omit<
693
+ SendMessageContent,
694
+ 'broadcast_id' | 'variables'
695
+ >;
696
+
697
+ export type ScheduleMessagePayload = {
698
+ scheduled_id?: string;
699
+ is_repeat?: boolean | null;
700
+ scheduled_at: string;
701
+ repeat_config?: {
702
+ timezone?: string;
703
+ repeat_ends?: string;
704
+ repeat_interval?: RepeatIntervalType;
705
+ repeat_value?: number;
706
+ repeat_days?: RepeatDaysType[];
707
+ };
708
+ };
709
+
710
+ export type BroadcastVariableType = {
711
+ chat_id: string;
712
+ values: { [key: string]: string };
713
+ };
714
+
715
+ export type BroadcastMessagePayload = SendMessageContent & {
716
+ chat_ids: string[];
717
+ broadcast_id?: string;
718
+ variables?: BroadcastVariableType[];
719
+ delay?: number;
720
+ };
721
+
722
+ export type SingleMessagePayload = SendMessageContent & {
723
+ chat_id: string;
724
+ job_id?: string;
725
+ priority?: number;
726
+ scheduled_id?: string;
727
+ };
728
+
729
+ export type MessageAttachmentFileTypes =
730
+ | 'image'
731
+ | 'audio'
732
+ | 'document'
733
+ | 'video';
734
+
735
+ export type AttachmentFileType = {
736
+ result: string;
737
+ file: File | null;
738
+ type: MessageAttachmentFileTypes;
739
+ localFileURL?: string;
740
+ };
741
+
742
+ export type AttachmentLinkType = {
743
+ link: {
744
+ url: string;
745
+ type: MessageAttachmentFileTypes;
746
+ name: string;
747
+ mimetype?: string;
748
+ };
749
+ };
750
+
751
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
752
+
753
+ /* -------------------------------- BROADCAST ------------------------------- */
754
+
755
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
756
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
757
+ } & {
758
+ chats: ChatType[];
759
+ };
760
+
761
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
762
+
763
+ export type ChatLogType = {
764
+ log: Tables<'view_chat_logs'>;
765
+ operations: Tables<'tbl_chat_logs'>[];
766
+ };
767
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
768
+
769
+ export type ChatParticipantOperationPayload = {
770
+ participant_ids: string[];
771
+ chat_ids: string[];
772
+ performed_by: string;
773
+ force_add_participants?: boolean;
774
+ };
775
+
776
+ export type ChatOperationReturn = {
777
+ [participant_id: string]: {
778
+ is_success: boolean;
779
+ message?: string;
780
+ code?: number;
781
+ isInviteV4Sent?: boolean;
782
+ };
783
+ };
784
+
785
+ /* ----------------------- BILLING - STRIPE ----------------------- */
786
+
787
+ export type ChargebeeSubscription = Subscription;
788
+ export type ChargebeeCustomer = Customer;
789
+ export type ChargebeePrice = ItemPrice;
790
+ export type ChargebeeUpcomingInvoice =
791
+ Estimate.RenewalEstimateResponse['estimate'];
792
+ export type ChargebeeLineItem =
793
+ HostedPage.CheckoutNewForItemsInputParam['subscription_items'];
794
+
795
+ /* -------------------------------- REALTIME -------------------------------- */
796
+
797
+ export type PhoneStateType = {
798
+ loading: boolean;
799
+ state: string;
800
+ sync: number;
801
+ percent: number | null;
802
+ message?: string;
803
+ error?: string;
804
+ };
805
+
806
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
807
+
808
+ export type ChatInfoType = Merge<
809
+ ChatType,
810
+ {
811
+ members: {
812
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
813
+ } | null;
814
+ chat_labels: string | null;
815
+ custom_properties: { [key: string]: string } | null;
816
+ }
817
+ >;
818
+
819
+ export type TicketInfoType = {
820
+ chat: ChatInfoType;
821
+ message: {
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
+ ticket: {
833
+ org_id: string;
834
+ status: string;
835
+ subject: string;
836
+ assignee: string;
837
+ due_date: string;
838
+ priority: 0 | 1 | 2 | 3 | 4;
839
+ raised_by: string;
840
+ ticket_id: string;
841
+ created_at: string;
842
+ assigned_by: string;
843
+ ticket_labels: string;
844
+ quoted_message_id: string;
845
+ ticket_custom_properties: { [key: string]: string } | null;
846
+ closed_at: string;
847
+ closed_by: string;
848
+ closed_message: string;
849
+ first_assigned_at: string | null;
850
+ is_deleted: boolean;
851
+ };
852
+ attached_messages: {
853
+ body: string;
854
+ chat_id: string;
855
+ org_phone: string;
856
+ timestamp: string;
857
+ media_path: string;
858
+ message_id: string;
859
+ sender_name: string;
860
+ performed_by: string;
861
+ sender_phone: string;
862
+ }[];
863
+ };
864
+
865
+ export type IntegrationLogObjectType =
866
+ | 'chat'
867
+ | 'message'
868
+ | 'reaction'
869
+ | 'ticket'
870
+ | 'phone';
871
+ export enum IntegrationLogType {
872
+ NEW_CHAT = 'chat.created',
873
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
874
+ NEW_MESSAGE = 'message.created',
875
+ MESSAGE_UPDATED = 'message.updated',
876
+ MESSAGE_DELETED = 'message.deleted',
877
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
878
+ MESSAGE_FLAGGED = 'message.flagged',
879
+ MESSAGE_UNFLAGGED = 'message.unflagged',
880
+ MESSAGE_TICKET_ATTACHED = 'message.ticket.attached',
881
+ REACTION_CREATED = 'reaction.created',
882
+ REACTION_UPDATED = 'reaction.updated',
883
+ NEW_TICKET = 'ticket.created',
884
+ TICKET_UPDATED = 'ticket.updated',
885
+ TICKET_DELETED = 'ticket.deleted',
886
+ PHONE_DISCONNECTED = 'org.phone.disconnected',
887
+ PHONE_CONNECTED = 'org.phone.connected',
888
+ PHONE_UPDATED = 'org.phone.updated',
889
+ PHONE_QR_UPDATED = 'org.phone.qr',
890
+ NOTE_CREATED = 'note.created',
891
+ CHAT_CUSTOM_PROPERTIES_UPDATED = 'chat.custom_properties.updated',
892
+ }
893
+
894
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
895
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
896
+ ? TicketInfoType
897
+ : T extends IntegrationLogType.NEW_CHAT
898
+ ? Tables<'tbl_chats'>
899
+ : T extends
900
+ | IntegrationLogType.NEW_MESSAGE
901
+ | IntegrationLogType.MESSAGE_UPDATED
902
+ | IntegrationLogType.MESSAGE_DELETED
903
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
904
+ | IntegrationLogType.MESSAGE_FLAGGED
905
+ | IntegrationLogType.MESSAGE_UNFLAGGED
906
+ | IntegrationLogType.MESSAGE_TICKET_ATTACHED
907
+ ? Tables<'tbl_chat_messages'>
908
+ : T extends
909
+ | IntegrationLogType.REACTION_CREATED
910
+ | IntegrationLogType.REACTION_UPDATED
911
+ ? Tables<'tbl_chat_reactions'>
912
+ : T extends
913
+ | IntegrationLogType.PHONE_DISCONNECTED
914
+ | IntegrationLogType.PHONE_CONNECTED
915
+ | IntegrationLogType.PHONE_UPDATED
916
+ | IntegrationLogType.PHONE_QR_UPDATED
917
+ ? Tables<'tbl_org_phones'>
918
+ : T extends IntegrationLogType.NOTE_CREATED
919
+ ? Tables<'tbl_chat_notes'>
920
+ : {
921
+ [key: string]: unknown;
922
+ };
923
+
924
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
925
+ OverrideProperties<
926
+ Tables<'tbl_integration_logs'>,
927
+ {
928
+ integration_name: T;
929
+ metadata: {
930
+ event: IntegrationLogMetadataType<T> & {
931
+ event_type: string;
932
+ org_id: string;
933
+ previous_attributes: {
934
+ [key: string]: unknown;
935
+ };
936
+ };
937
+ hook_id: string;
938
+ name: string;
939
+ };
940
+ }
941
+ >;
942
+
943
+ export type APIAuthDetails = {
944
+ org_details: Tables<'view_org'> | null;
945
+ phone_details: Tables<'tbl_org_phones'> | null;
946
+ token_details: Tables<'tbl_integration_tokens'> | null;
947
+ };
948
+
949
+ export type WebhookDataType = OverrideProperties<
950
+ Tables<'tbl_integration_hooks'>,
951
+ {
952
+ integration_name: string[];
953
+ }
954
+ >;
955
+
956
+ export type HubspotObjectDataType = {
957
+ createdAt: string;
958
+ archived: boolean;
959
+ id: string;
960
+ type: 'contacts' | 'tickets' | 'companies';
961
+ properties: Record<
962
+ string,
963
+ {
964
+ groupLabel: string;
965
+ groupName: string;
966
+ propertyKeyName: string;
967
+ propertyKey: string;
968
+ propertyInternalValue: string;
969
+ propertyValue: string;
970
+ propertyType: string;
971
+ propertyFieldType: string;
972
+ }[]
973
+ >;
974
+ };
975
+
976
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
977
+
978
+ export type UserPreferences = {
979
+ theme: 'light' | 'dark';
980
+ language: 'en' | 'es';
981
+ left_sidebar_open: boolean;
982
+ right_sidepanel_open: boolean;
983
+ sync_wa_unread_count: boolean;
984
+ pinned_chats: string[];
985
+ periskope_chat_limit: number;
986
+ notifications: Record<string, boolean>;
987
+ };
988
+
989
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
990
+
991
+ export interface MostActiveMember {
992
+ sender_phone: string;
993
+ total_messages: number;
994
+ }
995
+
996
+ export interface GroupAnalyticsResult {
997
+ total_messages: number;
998
+ total_joins: number;
999
+ total_leaves: number;
1000
+ total_removes: number;
1001
+ total_reactions: number;
1002
+ most_active_members: MostActiveMember[];
1003
+ }
1004
+
1005
+ export interface TimeRange {
1006
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
1007
+ endDateTime: string;
1008
+ }
1009
+
1010
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
1011
+
1012
+ export type PollSendType = {
1013
+ pollName: string;
1014
+ pollOptions: string[];
1015
+ options?: {
1016
+ allowMultipleAnswers?: boolean;
1017
+ messageSecret?: number[] | null;
1018
+ pollId?: string;
1019
+ };
1020
+ };
1021
+
1022
+ export type PollResultType = {
1023
+ [name: string]: Record<string, string>;
1024
+ };
1025
+
1026
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
1027
+
1028
+ export type CreateGroupOptions = {
1029
+ messagesAdminsOnly?: boolean;
1030
+ infoAdminsOnly?: boolean;
1031
+ addMembersAdminsOnly?: boolean;
1032
+ image?: string;
1033
+ name?: string;
1034
+ description?: string;
1035
+ initiated_by?: string;
1036
+ admins?: string[];
1037
+ force_add_participants?: boolean;
1038
+ };
1039
+
1040
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
1041
+
1042
+ export type DeliveryInfoType = {
1043
+ delivered: Record<string, number | undefined>;
1044
+ read: Record<string, number | undefined>;
1045
+ pending: string[];
1046
+ read_count: number;
1047
+ delivered_count: number;
1048
+ };
1049
+
1050
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1051
+
1052
+ export type OrgCreditsType = {
1053
+ org_id: string;
1054
+ recurring_allowance: number; // recurring credits replenished every cycle
1055
+ recurring_balance: number; // recurring credits remaining in current cycle
1056
+ topup_balance: number; // topup credits remaining
1057
+ total_credits_used: number; // total credits used in current cycle
1058
+ next_renewal_date: string;
1059
+ topup_credits_used: number; // topup credits used in current cycle
1060
+ recurring_credits_used: number; // recurring credits used in current cycle
1061
+ };
1062
+
1063
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
1064
+
1065
+ export type ChatRuleInfoType = {
1066
+ chat: Merge<
1067
+ Pick<
1068
+ Tables<'view_chats'>,
1069
+ | 'assigned_to'
1070
+ | 'chat_id'
1071
+ | 'chat_name'
1072
+ | 'chat_type'
1073
+ | 'created_at'
1074
+ | 'group_description'
1075
+ | 'info_admins_only'
1076
+ | 'org_id'
1077
+ | 'org_phone'
1078
+ | 'chat_org_phones'
1079
+ | 'messages_admins_only'
1080
+ | 'custom_properties'
1081
+ | 'initiated_by'
1082
+ >,
1083
+ {
1084
+ has_flagged_messages: boolean;
1085
+ labels: string[];
1086
+ members: string[];
1087
+ custom_properties: { [key: string]: string } | null;
1088
+ }
1089
+ >;
1090
+ };
1091
+
1092
+ export type SenderRuleInfoType = Merge<
1093
+ Omit<
1094
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1095
+ | 'verified_name'
1096
+ | 'verified_level'
1097
+ | 'updated_at'
1098
+ | 'short_name'
1099
+ | 'pushname'
1100
+ | 'periskope_name'
1101
+ | 'org_phone'
1102
+ | 'number'
1103
+ | 'name'
1104
+ | 'label_ids'
1105
+ | 'is_wa_contact'
1106
+ | 'is_user'
1107
+ | 'is_my_contact'
1108
+ | 'is_me'
1109
+ | 'is_imported'
1110
+ | 'is_group'
1111
+ | 'is_blocked'
1112
+ | 'contact_color'
1113
+ | 'business_profile'
1114
+ | 'id'
1115
+ | 'contact_image'
1116
+ | 'contact_type'
1117
+ | 'chat_id'
1118
+ | 'is_business'
1119
+ | 'is_enterprise'
1120
+ | 'is_super_admin'
1121
+ | 'contact_lid'
1122
+ >,
1123
+ {
1124
+ is_internal: boolean;
1125
+ labels: string[] | null;
1126
+ }
1127
+ >;
1128
+
1129
+ export type MessageRuleInfoType = {
1130
+ chat: ChatRuleInfoType['chat'];
1131
+ sender: SenderRuleInfoType;
1132
+ message: OverrideProperties<
1133
+ Omit<
1134
+ Tables<'tbl_chat_messages'>,
1135
+ | 'vcards'
1136
+ | 'updated_at'
1137
+ | 'unique_id'
1138
+ | 'token'
1139
+ | 'to'
1140
+ | 'sent_message_id'
1141
+ | 'raw_data'
1142
+ | 'delivery_info'
1143
+ | 'poll_results'
1144
+ | 'poll_info'
1145
+ | 'order_id'
1146
+ | 'mentioned_ids'
1147
+ | 'media_key'
1148
+ | 'location'
1149
+ | 'links'
1150
+ | 'is_status'
1151
+ | 'is_starred'
1152
+ | 'is_gif'
1153
+ | 'is_forwarded'
1154
+ | 'is_ephemeral'
1155
+ | 'is_deleted'
1156
+ | 'fts'
1157
+ | 'quoted_message_id'
1158
+ | 'invite_v4'
1159
+ | 'id'
1160
+ | 'has_reaction'
1161
+ | 'has_media'
1162
+ | 'duration'
1163
+ | 'broadcast'
1164
+ | 'broadcast_id'
1165
+ | 'device_type'
1166
+ | 'forwarding_score'
1167
+ | 'from'
1168
+ | 'from_me'
1169
+ | 'prev_body'
1170
+ | 'flag_response_time'
1171
+ | 'flag_metadata'
1172
+ | 'ack'
1173
+ >,
1174
+ {
1175
+ media: MediaType | null;
1176
+ }
1177
+ >;
1178
+ };
1179
+
1180
+ export type ReactionRuleInfoType = {
1181
+ chat: MessageRuleInfoType['chat'];
1182
+ sender: MessageRuleInfoType['sender'];
1183
+ message: MessageRuleInfoType['message'];
1184
+ reaction: Pick<
1185
+ Tables<'tbl_chat_reactions'>,
1186
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1187
+ >;
1188
+ };
1189
+
1190
+ export type TicketRuleInfoType = {
1191
+ chat: MessageRuleInfoType['chat'];
1192
+ sender: MessageRuleInfoType['sender'];
1193
+ ticket: Merge<
1194
+ Pick<
1195
+ Tables<'tbl_chat_tickets'>,
1196
+ | 'org_id'
1197
+ | 'status'
1198
+ | 'chat_id'
1199
+ | 'subject'
1200
+ | 'assignee'
1201
+ | 'due_date'
1202
+ | 'priority'
1203
+ | 'raised_by'
1204
+ | 'ticket_id'
1205
+ | 'created_at'
1206
+ | 'is_deleted'
1207
+ >,
1208
+ {
1209
+ labels: string[] | null;
1210
+ custom_properties: { [key: string]: string } | null;
1211
+ }
1212
+ >;
1213
+ message: MessageRuleInfoType['message'];
1214
+ };
1215
+
1216
+ export type TaskRuleInfoType<
1217
+ T extends 'ticket' | 'chat' | 'message' | 'todo' = 'todo',
1218
+ > = {
1219
+ associated_object_data: T extends 'message'
1220
+ ? MessageRuleInfoType
1221
+ : T extends 'ticket'
1222
+ ? TicketRuleInfoType
1223
+ : T extends 'chat'
1224
+ ? ChatRuleInfoType
1225
+ : null;
1226
+ task: Pick<
1227
+ TaskType,
1228
+ | 'org_id'
1229
+ | 'title'
1230
+ | 'notes'
1231
+ | 'status'
1232
+ | 'assignee'
1233
+ | 'due_date'
1234
+ | 'priority'
1235
+ | 'task_id'
1236
+ | 'created_at'
1237
+ >;
1238
+ };
1239
+
1240
+ export type FeatureFlagReturnType = Record<string, boolean>;
1241
+
1242
+ export type RuleLogsType = OverrideProperties<
1243
+ Tables<'tbl_rules_logs'>,
1244
+ {
1245
+ actions_progress: {
1246
+ action_id: string;
1247
+ action_type: Rule['actions'][number]['type'];
1248
+ action_delay: Rule['actions'][number]['delay'];
1249
+ ran_at: string | null;
1250
+ action_status: 'success' | 'failed' | 'pending';
1251
+ action_response: {
1252
+ success: boolean;
1253
+ data: Record<string, unknown> | null;
1254
+ error: {
1255
+ message: string;
1256
+ name: string;
1257
+ stack?: string;
1258
+ _error?: Error | Record<string, unknown>;
1259
+ } | null;
1260
+ };
1261
+ }[];
1262
+ metadata: {
1263
+ conditions: Rule['conditions'];
1264
+ actions: Rule['actions'];
1265
+ rule_metadata: Pick<
1266
+ Rule,
1267
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1268
+ >;
1269
+ data: Record<string, unknown>;
1270
+ };
1271
+ conditions_progress: {
1272
+ is_valid: boolean;
1273
+ validation_progress: Record<
1274
+ string,
1275
+ {
1276
+ res: boolean;
1277
+ filter: Filter;
1278
+ value: unknown;
1279
+ }
1280
+ >;
1281
+ checked_at: string | null;
1282
+ };
1283
+ }
1284
+ >;
1285
+
1286
+ /************************** TASKS ***************************/
1287
+
1288
+ export type ChatMetadataType = {
1289
+ type: 'chat';
1290
+ index: 'chat_id';
1291
+ id: string;
1292
+ object: Pick<ChatType, 'chat_id' | 'org_phone' | 'org_id'>;
1293
+ };
1294
+
1295
+ export type MessageMetadataType = {
1296
+ type: 'message';
1297
+ index: 'message_id';
1298
+ id: string;
1299
+ object: Pick<
1300
+ MessageType,
1301
+ | 'message_id'
1302
+ | 'org_phone'
1303
+ | 'chat_id'
1304
+ | 'sender_phone'
1305
+ | 'org_id'
1306
+ | 'is_private_note'
1307
+ >;
1308
+ };
1309
+
1310
+ export type TicketMetadataType = {
1311
+ type: 'ticket';
1312
+ index: 'ticket_id';
1313
+ id: string;
1314
+ object: Pick<
1315
+ TicketType,
1316
+ 'ticket_id' | 'quoted_message_id' | 'chat_id' | 'org_id'
1317
+ >;
1318
+ };
1319
+
1320
+ export type AssociatedObjectMetadataType<
1321
+ T extends 'chat' | 'message' | 'ticket' | 'todo' =
1322
+ | 'chat'
1323
+ | 'message'
1324
+ | 'ticket'
1325
+ | 'todo',
1326
+ > = T extends 'chat'
1327
+ ? ChatMetadataType
1328
+ : T extends 'message'
1329
+ ? MessageMetadataType
1330
+ : T extends 'ticket'
1331
+ ? TicketMetadataType
1332
+ : null;
1333
+
1334
+ export const isChatTask = (task: TaskType): task is TaskType<'chat'> =>
1335
+ task.associated_object_metadata?.type === 'chat';
1336
+
1337
+ export const isMessageTask = (task: TaskType): task is TaskType<'message'> =>
1338
+ task.associated_object_metadata?.type === 'message';
1339
+
1340
+ export const isTicketTask = (task: TaskType): task is TaskType<'ticket'> =>
1341
+ task.associated_object_metadata?.type === 'ticket';
1342
+
1343
+ export const isTodoTask = (task: TaskType): task is TaskType<'todo'> =>
1344
+ task.type === 'todo';
1345
+
1346
+ export type TaskType<
1347
+ T extends 'chat' | 'message' | 'ticket' | 'todo' =
1348
+ | 'chat'
1349
+ | 'message'
1350
+ | 'ticket'
1351
+ | 'todo',
1352
+ > = OverrideProperties<
1353
+ Tables<'tbl_org_tasks'>,
1354
+ {
1355
+ reminder_setting: {
1356
+ remind_in:
1357
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1358
+ | string
1359
+ | null;
1360
+ repeat?: {
1361
+ frequency: number;
1362
+ interval: 'days' | 'weeks' | 'months' | 'years';
1363
+ end: 'never' | 'after' | 'on';
1364
+ on?: string;
1365
+ };
1366
+ } | null;
1367
+ associated_object_metadata: AssociatedObjectMetadataType<T>;
1368
+ status: 'open' | 'inprogress' | 'closed';
1369
+ priority: 1 | 2 | 3;
1370
+ completed_metadata?: {
1371
+ completed_at: string;
1372
+ completed_by: string;
1373
+ } | null;
1374
+ type: T;
1375
+ }
1376
+ >;
1377
+
1378
+ type Choice = {
1379
+ id: number;
1380
+ label: string;
1381
+ value: string;
1382
+ position: number;
1383
+ };
1384
+
1385
+ export type FreshdeskFieldType = {
1386
+ id: number;
1387
+ name: string;
1388
+ type: string;
1389
+ label: string;
1390
+ default: boolean;
1391
+ archived: boolean;
1392
+ position: number;
1393
+ created_at: string;
1394
+ updated_at: string;
1395
+ customers_can_edit: boolean;
1396
+ label_for_customers: string;
1397
+ required_for_agents: boolean;
1398
+ customers_can_filter: boolean;
1399
+ required_for_closure: boolean;
1400
+ displayed_to_customers: boolean;
1401
+ required_for_customers: boolean;
1402
+ choices?: Choice[];
1403
+ };
1404
+
1405
+ export type OrgWarmup = OverrideProperties<
1406
+ Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1407
+ {
1408
+ warmup_chats: { [key: string]: string };
1409
+ }
1410
+ >;
1411
+
1412
+ /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1413
+
1414
+ export type FreshdeskIntegrationTokenType = OverrideProperties<
1415
+ Tables<'tbl_integration_tokens'>,
1416
+ {
1417
+ type: 'freshdesk';
1418
+ token_metadata: {
1419
+ url: string;
1420
+ apiKey: string;
1421
+ fields: {
1422
+ ticket: FreshdeskFieldType[];
1423
+ company: FreshdeskFieldType[];
1424
+ contact: FreshdeskFieldType[];
1425
+ };
1426
+ automation: {
1427
+ id: number | string;
1428
+ meta: {
1429
+ total_count: number;
1430
+ total_active_count: 17;
1431
+ };
1432
+ name: string;
1433
+ active: boolean;
1434
+ events: Array<{
1435
+ to?: string;
1436
+ from?: string;
1437
+ field_name: string;
1438
+ value?: string;
1439
+ }>;
1440
+ actions: Array<{
1441
+ url: string;
1442
+ content: Record<string, string>;
1443
+ field_name: string;
1444
+ content_type: string;
1445
+ request_type: string;
1446
+ content_layout: string;
1447
+ }>;
1448
+ summary: {
1449
+ events: Array<string>;
1450
+ actions: Array<string>;
1451
+ performer: string;
1452
+ conditions: {
1453
+ [key: string]: Array<string>;
1454
+ };
1455
+ };
1456
+ outdated: boolean;
1457
+ position: number;
1458
+ performer: {
1459
+ type: string;
1460
+ };
1461
+ conditions: Array<{
1462
+ name: string;
1463
+ match_type: string;
1464
+ properties: Array<{
1465
+ value: Array<string>;
1466
+ operator: string;
1467
+ field_name: string;
1468
+ resource_type: string;
1469
+ case_sensitive: boolean;
1470
+ }>;
1471
+ }>;
1472
+ created_at: string;
1473
+ updated_at: string;
1474
+ description: string | null;
1475
+ last_updated_by: string | number;
1476
+ affected_tickets_count: number | null;
1477
+ };
1478
+ org_details: {
1479
+ address: {
1480
+ city: string;
1481
+ state: string;
1482
+ street: string;
1483
+ country: string;
1484
+ postalcode: string;
1485
+ };
1486
+ timezone: string;
1487
+ bundle_id: string;
1488
+ tier_type: string;
1489
+ account_id: number;
1490
+ cloud_type: string;
1491
+ data_center: string;
1492
+ account_name: string;
1493
+ total_agents: {
1494
+ full_time: number;
1495
+ occasional: number;
1496
+ collaborators: number;
1497
+ field_service: number;
1498
+ };
1499
+ account_domain: string;
1500
+ contact_person: {
1501
+ email: string;
1502
+ lastname: string;
1503
+ firstname: string;
1504
+ };
1505
+ hipaa_compliant: boolean;
1506
+ organisation_id: number;
1507
+ organisation_name: string;
1508
+ };
1509
+ custom_fields: {
1510
+ ticket: FreshdeskFieldType[];
1511
+ company: FreshdeskFieldType[];
1512
+ contact: FreshdeskFieldType[];
1513
+ };
1514
+ integration_org_id: string | number;
1515
+ ticket_auto_creation?: boolean;
1516
+ };
1517
+ }
1518
+ >;
1519
+
1520
+ export type ZohodeskIntegrationTokenType = OverrideProperties<
1521
+ Tables<'tbl_integration_tokens'>,
1522
+ {
1523
+ type: 'zohodesk';
1524
+ token_metadata: {
1525
+ scope: string;
1526
+ domain: string;
1527
+ fields: Array<{
1528
+ id: string;
1529
+ name: string;
1530
+ type: string;
1531
+ apiName: string;
1532
+ toolTip: string;
1533
+ i18NLabel: string;
1534
+ maxLength: number;
1535
+ isMandatory: boolean;
1536
+ toolTipType: string;
1537
+ displayLabel: string;
1538
+ isCustomField: boolean;
1539
+ isEncryptedField: boolean;
1540
+ showToHelpCenter: boolean;
1541
+ }>;
1542
+ org_id: string;
1543
+ webhooks: {
1544
+ id: string;
1545
+ url: string;
1546
+ name: string;
1547
+ type: string;
1548
+ createdBy: string;
1549
+ isEnabled: boolean;
1550
+ createdTime: string;
1551
+ description: string;
1552
+ modifiedTime: string;
1553
+ subscriptions: {
1554
+ [key: string]: {
1555
+ departmentIds: string[];
1556
+ includePrevState: boolean;
1557
+ };
1558
+ };
1559
+ ignoreSourceId: boolean | null;
1560
+ includeEventsFrom: string[];
1561
+ };
1562
+ api_domain: string;
1563
+ authDomain: string;
1564
+ expires_in: number;
1565
+ token_type: string;
1566
+ departments: Array<{
1567
+ id: string;
1568
+ name: string;
1569
+ hasLogo: boolean;
1570
+ creatorId: string;
1571
+ isDefault: boolean;
1572
+ isEnabled: boolean;
1573
+ chatStatus: string;
1574
+ createdTime: string;
1575
+ description: string | null;
1576
+ sanitizedName: string;
1577
+ nameInCustomerPortal: string;
1578
+ isAssignToTeamEnabled: boolean;
1579
+ isVisibleInCustomerPortal: boolean;
1580
+ }>;
1581
+ org_details: {
1582
+ id: number;
1583
+ fax: string;
1584
+ zip: string;
1585
+ city: string;
1586
+ alias: string | null;
1587
+ state: string;
1588
+ mobile: string;
1589
+ street: string;
1590
+ country: string;
1591
+ edition: string;
1592
+ logoURL: string;
1593
+ website: string;
1594
+ isDefault: boolean;
1595
+ portalURL: string;
1596
+ faviconURL: string;
1597
+ portalName: string;
1598
+ companyName: string;
1599
+ description: string | null;
1600
+ phoneNumber: string | null;
1601
+ currencyCode: string;
1602
+ isAdminInOrg: boolean;
1603
+ employeeCount: number;
1604
+ currencyLocale: string;
1605
+ currencySymbol: string;
1606
+ primaryContact: string;
1607
+ isSandboxPortal: boolean;
1608
+ isPayloadEncryptionEnabled: boolean;
1609
+ };
1610
+ access_token: string;
1611
+ refresh_token: string;
1612
+ integration_org_id: string | number;
1613
+ ticket_auto_creation?: boolean;
1614
+ };
1615
+ }
1616
+ >;