@periskope/types 0.6.342 → 0.6.343

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