@periskope/types 0.6.366 → 0.6.368

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