@periskope/types 0.6.349 → 0.6.351

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