@periskope/types 0.6.342 → 0.6.344

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