@periskope/types 0.6.373 → 0.6.375

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