@periskope/types 0.6.355 → 0.6.356

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