@periskope/types 0.6.330 → 0.6.331

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