@periskope/types 0.6.319 → 0.6.321

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,1585 +1,1585 @@
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
- }
862
-
863
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
864
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
865
- ? TicketInfoType
866
- : T extends IntegrationLogType.NEW_CHAT
867
- ? Tables<'tbl_chats'>
868
- : T extends
869
- | IntegrationLogType.NEW_MESSAGE
870
- | IntegrationLogType.MESSAGE_UPDATED
871
- | IntegrationLogType.MESSAGE_DELETED
872
- | IntegrationLogType.MESSAGE_ACK_UPDATED
873
- | IntegrationLogType.MESSAGE_FLAGGED
874
- | IntegrationLogType.MESSAGE_UNFLAGGED
875
- | IntegrationLogType.MESSAGE_TICKET_ATTACHED
876
- ? Tables<'tbl_chat_messages'>
877
- : T extends
878
- | IntegrationLogType.REACTION_CREATED
879
- | IntegrationLogType.REACTION_UPDATED
880
- ? Tables<'tbl_chat_reactions'>
881
- : T extends
882
- | IntegrationLogType.PHONE_DISCONNECTED
883
- | IntegrationLogType.PHONE_CONNECTED
884
- | IntegrationLogType.PHONE_UPDATED
885
- | IntegrationLogType.PHONE_QR_UPDATED
886
- ? Tables<'tbl_org_phones'>
887
- : {
888
- [key: string]: unknown;
889
- };
890
-
891
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
892
- OverrideProperties<
893
- Tables<'tbl_integration_logs'>,
894
- {
895
- integration_name: T;
896
- metadata: {
897
- event: IntegrationLogMetadataType<T> & {
898
- event_type: string;
899
- org_id: string;
900
- previous_attributes: {
901
- [key: string]: unknown;
902
- };
903
- };
904
- hook_id: string;
905
- name: string;
906
- };
907
- }
908
- >;
909
-
910
- export type APIAuthDetails = {
911
- org_details: Tables<'view_org'> | null;
912
- phone_details: Tables<'tbl_org_phones'> | null;
913
- token_details: Tables<'tbl_integration_tokens'> | null;
914
- };
915
-
916
- export type WebhookDataType = OverrideProperties<
917
- Tables<'tbl_integration_hooks'>,
918
- {
919
- integration_name: string[];
920
- }
921
- >;
922
-
923
- export type HubspotObjectDataType = {
924
- createdAt: string;
925
- archived: boolean;
926
- id: string;
927
- type: 'contacts' | 'tickets' | 'companies';
928
- properties: Record<
929
- string,
930
- {
931
- groupLabel: string;
932
- groupName: string;
933
- propertyKeyName: string;
934
- propertyKey: string;
935
- propertyInternalValue: string;
936
- propertyValue: string;
937
- propertyType: string;
938
- propertyFieldType: string;
939
- }[]
940
- >;
941
- };
942
-
943
- /* ---------------------------- USER PREFERENCES ---------------------------- */
944
-
945
- export type UserPreferences = {
946
- theme: 'light' | 'dark';
947
- language: 'en' | 'es';
948
- left_sidebar_open: boolean;
949
- right_sidepanel_open: boolean;
950
- sync_wa_unread_count: boolean;
951
- pinned_chats: string[];
952
- archived_chats: string[];
953
- closed_chats: Record<string, number>;
954
- periskope_chat_limit: number;
955
- notifications: Record<string, boolean>;
956
- };
957
-
958
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
959
-
960
- export interface MostActiveMember {
961
- sender_phone: string;
962
- total_messages: number;
963
- }
964
-
965
- export interface GroupAnalyticsResult {
966
- total_messages: number;
967
- total_joins: number;
968
- total_leaves: number;
969
- total_removes: number;
970
- total_reactions: number;
971
- most_active_members: MostActiveMember[];
972
- }
973
-
974
- export interface TimeRange {
975
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
976
- endDateTime: string;
977
- }
978
-
979
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
980
-
981
- export type PollSendType = {
982
- pollName: string;
983
- pollOptions: string[];
984
- options?: {
985
- allowMultipleAnswers?: boolean;
986
- messageSecret?: number[] | null;
987
- pollId?: string;
988
- };
989
- };
990
-
991
- export type PollResultType = {
992
- [name: string]: Record<string, string>;
993
- };
994
-
995
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
996
-
997
- export type CreateGroupOptions = {
998
- messagesAdminsOnly?: boolean;
999
- infoAdminsOnly?: boolean;
1000
- addMembersAdminsOnly?: boolean;
1001
- image?: string;
1002
- name?: string;
1003
- description?: string;
1004
- initiated_by?: string;
1005
- admins?: string[];
1006
- force_add_participants?: boolean;
1007
- };
1008
-
1009
- /* ------------------------------ DELIVERY INFO ----------------------------- */
1010
-
1011
- export type DeliveryInfoType = {
1012
- delivered: Record<string, number | undefined>;
1013
- read: Record<string, number | undefined>;
1014
- pending: string[];
1015
- read_count: number;
1016
- delivered_count: number;
1017
- };
1018
-
1019
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1020
-
1021
- export type OrgCreditsType = {
1022
- org_id: string;
1023
- recurring_allowance: number; // recurring credits replenished every cycle
1024
- recurring_balance: number; // recurring credits remaining in current cycle
1025
- topup_balance: number; // topup credits remaining
1026
- total_credits_used: number; // total credits used in current cycle
1027
- next_renewal_date: string;
1028
- topup_credits_used: number; // topup credits used in current cycle
1029
- recurring_credits_used: number; // recurring credits used in current cycle
1030
- };
1031
-
1032
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
1033
-
1034
- export type ChatRuleInfoType = {
1035
- chat: Merge<
1036
- Pick<
1037
- Tables<'view_chats'>,
1038
- | 'assigned_to'
1039
- | 'chat_id'
1040
- | 'chat_name'
1041
- | 'chat_type'
1042
- | 'created_at'
1043
- | 'group_description'
1044
- | 'info_admins_only'
1045
- | 'org_id'
1046
- | 'org_phone'
1047
- | 'chat_org_phones'
1048
- | 'messages_admins_only'
1049
- | 'custom_properties'
1050
- | 'initiated_by'
1051
- >,
1052
- {
1053
- has_flagged_messages: boolean;
1054
- labels: string[];
1055
- members: string[];
1056
- custom_properties: { [key: string]: string } | null;
1057
- }
1058
- >;
1059
- };
1060
-
1061
- export type SenderRuleInfoType = Merge<
1062
- Omit<
1063
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1064
- | 'verified_name'
1065
- | 'verified_level'
1066
- | 'updated_at'
1067
- | 'short_name'
1068
- | 'pushname'
1069
- | 'periskope_name'
1070
- | 'org_phone'
1071
- | 'number'
1072
- | 'name'
1073
- | 'label_ids'
1074
- | 'is_wa_contact'
1075
- | 'is_user'
1076
- | 'is_my_contact'
1077
- | 'is_me'
1078
- | 'is_imported'
1079
- | 'is_group'
1080
- | 'is_blocked'
1081
- | 'contact_color'
1082
- | 'business_profile'
1083
- | 'id'
1084
- | 'contact_image'
1085
- | 'contact_type'
1086
- | 'chat_id'
1087
- | 'is_business'
1088
- | 'is_enterprise'
1089
- | 'is_super_admin'
1090
- | 'contact_lid'
1091
- >,
1092
- {
1093
- is_internal: boolean;
1094
- labels: string[] | null;
1095
- }
1096
- >;
1097
-
1098
- export type MessageRuleInfoType = {
1099
- chat: ChatRuleInfoType['chat'];
1100
- sender: SenderRuleInfoType;
1101
- message: OverrideProperties<
1102
- Omit<
1103
- Tables<'tbl_chat_messages'>,
1104
- | 'vcards'
1105
- | 'updated_at'
1106
- | 'unique_id'
1107
- | 'token'
1108
- | 'to'
1109
- | 'sent_message_id'
1110
- | 'raw_data'
1111
- | 'delivery_info'
1112
- | 'poll_results'
1113
- | 'poll_info'
1114
- | 'order_id'
1115
- | 'mentioned_ids'
1116
- | 'media_key'
1117
- | 'location'
1118
- | 'links'
1119
- | 'is_status'
1120
- | 'is_starred'
1121
- | 'is_gif'
1122
- | 'is_forwarded'
1123
- | 'is_ephemeral'
1124
- | 'is_deleted'
1125
- | 'fts'
1126
- | 'quoted_message_id'
1127
- | 'invite_v4'
1128
- | 'id'
1129
- | 'has_reaction'
1130
- | 'has_media'
1131
- | 'duration'
1132
- | 'broadcast'
1133
- | 'broadcast_id'
1134
- | 'device_type'
1135
- | 'forwarding_score'
1136
- | 'from'
1137
- | 'from_me'
1138
- | 'prev_body'
1139
- | 'flag_response_time'
1140
- | 'flag_metadata'
1141
- | 'ack'
1142
- >,
1143
- {
1144
- media: MediaType | null;
1145
- }
1146
- >;
1147
- };
1148
-
1149
- export type ReactionRuleInfoType = {
1150
- chat: MessageRuleInfoType['chat'];
1151
- sender: MessageRuleInfoType['sender'];
1152
- message: MessageRuleInfoType['message'];
1153
- reaction: Pick<
1154
- Tables<'tbl_chat_reactions'>,
1155
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1156
- >;
1157
- };
1158
-
1159
- export type TicketRuleInfoType = {
1160
- chat: MessageRuleInfoType['chat'];
1161
- sender: MessageRuleInfoType['sender'];
1162
- ticket: Merge<
1163
- Pick<
1164
- Tables<'tbl_chat_tickets'>,
1165
- | 'org_id'
1166
- | 'status'
1167
- | 'chat_id'
1168
- | 'subject'
1169
- | 'assignee'
1170
- | 'due_date'
1171
- | 'priority'
1172
- | 'raised_by'
1173
- | 'ticket_id'
1174
- | 'created_at'
1175
- | 'is_deleted'
1176
- >,
1177
- {
1178
- labels: string[] | null;
1179
- custom_properties: { [key: string]: string } | null;
1180
- }
1181
- >;
1182
- message: MessageRuleInfoType['message'];
1183
- };
1184
-
1185
- export type TaskRuleInfoType<
1186
- T extends 'ticket' | 'chat' | 'message' | 'todo' = 'todo',
1187
- > = {
1188
- associated_object_data: T extends 'message'
1189
- ? MessageRuleInfoType
1190
- : T extends 'ticket'
1191
- ? TicketRuleInfoType
1192
- : T extends 'chat'
1193
- ? ChatRuleInfoType
1194
- : null;
1195
- task: Pick<
1196
- TaskType,
1197
- | 'org_id'
1198
- | 'title'
1199
- | 'notes'
1200
- | 'status'
1201
- | 'assignee'
1202
- | 'due_date'
1203
- | 'priority'
1204
- | 'task_id'
1205
- | 'created_at'
1206
- >;
1207
- };
1208
-
1209
- export type FeatureFlagReturnType = Record<string, boolean>;
1210
-
1211
- export type RuleLogsType = OverrideProperties<
1212
- Tables<'tbl_rules_logs'>,
1213
- {
1214
- actions_progress: {
1215
- action_id: string;
1216
- action_type: Rule['actions'][number]['type'];
1217
- action_delay: Rule['actions'][number]['delay'];
1218
- ran_at: string | null;
1219
- action_status: 'success' | 'failed' | 'pending';
1220
- action_response: {
1221
- success: boolean;
1222
- data: Record<string, unknown> | null;
1223
- error: {
1224
- message: string;
1225
- name: string;
1226
- stack?: string;
1227
- _error?: Error | Record<string, unknown>;
1228
- } | null;
1229
- };
1230
- }[];
1231
- metadata: {
1232
- conditions: Rule['conditions'];
1233
- actions: Rule['actions'];
1234
- rule_metadata: Pick<
1235
- Rule,
1236
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1237
- >;
1238
- data: Record<string, unknown>;
1239
- };
1240
- conditions_progress: {
1241
- is_valid: boolean;
1242
- validation_progress: Record<
1243
- string,
1244
- {
1245
- res: boolean;
1246
- filter: Filter;
1247
- value: unknown;
1248
- }
1249
- >;
1250
- checked_at: string | null;
1251
- };
1252
- }
1253
- >;
1254
-
1255
- /************************** TASKS ***************************/
1256
-
1257
- export type ChatMetadataType = {
1258
- type: 'chat';
1259
- index: 'chat_id';
1260
- id: string;
1261
- object: Pick<ChatType, 'chat_id' | 'org_phone' | 'org_id'>;
1262
- };
1263
-
1264
- export type MessageMetadataType = {
1265
- type: 'message';
1266
- index: 'message_id';
1267
- id: string;
1268
- object: Pick<
1269
- MessageType,
1270
- | 'message_id'
1271
- | 'org_phone'
1272
- | 'chat_id'
1273
- | 'sender_phone'
1274
- | 'org_id'
1275
- | 'is_private_note'
1276
- >;
1277
- };
1278
-
1279
- export type TicketMetadataType = {
1280
- type: 'ticket';
1281
- index: 'ticket_id';
1282
- id: string;
1283
- object: Pick<
1284
- TicketType,
1285
- 'ticket_id' | 'quoted_message_id' | 'chat_id' | 'org_id'
1286
- >;
1287
- };
1288
-
1289
- export type AssociatedObjectMetadataType<
1290
- T extends 'chat' | 'message' | 'ticket' | 'todo' =
1291
- | 'chat'
1292
- | 'message'
1293
- | 'ticket'
1294
- | 'todo',
1295
- > = T extends 'chat'
1296
- ? ChatMetadataType
1297
- : T extends 'message'
1298
- ? MessageMetadataType
1299
- : T extends 'ticket'
1300
- ? TicketMetadataType
1301
- : null;
1302
-
1303
- export const isChatTask = (task: TaskType): task is TaskType<'chat'> =>
1304
- task.associated_object_metadata?.type === 'chat';
1305
-
1306
- export const isMessageTask = (task: TaskType): task is TaskType<'message'> =>
1307
- task.associated_object_metadata?.type === 'message';
1308
-
1309
- export const isTicketTask = (task: TaskType): task is TaskType<'ticket'> =>
1310
- task.associated_object_metadata?.type === 'ticket';
1311
-
1312
- export const isTodoTask = (task: TaskType): task is TaskType<'todo'> =>
1313
- task.type === 'todo';
1314
-
1315
- export type TaskType<
1316
- T extends 'chat' | 'message' | 'ticket' | 'todo' =
1317
- | 'chat'
1318
- | 'message'
1319
- | 'ticket'
1320
- | 'todo',
1321
- > = OverrideProperties<
1322
- Tables<'tbl_org_tasks'>,
1323
- {
1324
- reminder_setting: {
1325
- remind_in:
1326
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1327
- | string
1328
- | null;
1329
- repeat?: {
1330
- frequency: number;
1331
- interval: 'days' | 'weeks' | 'months' | 'years';
1332
- end: 'never' | 'after' | 'on';
1333
- on?: string;
1334
- };
1335
- } | null;
1336
- associated_object_metadata: AssociatedObjectMetadataType<T>;
1337
- status: 'open' | 'inprogress' | 'closed';
1338
- priority: 1 | 2 | 3;
1339
- completed_metadata?: {
1340
- completed_at: string;
1341
- completed_by: string;
1342
- } | null;
1343
- type: T;
1344
- }
1345
- >;
1346
-
1347
- type Choice = {
1348
- id: number;
1349
- label: string;
1350
- value: string;
1351
- position: number;
1352
- };
1353
-
1354
- export type FreshdeskFieldType = {
1355
- id: number;
1356
- name: string;
1357
- type: string;
1358
- label: string;
1359
- default: boolean;
1360
- archived: boolean;
1361
- position: number;
1362
- created_at: string;
1363
- updated_at: string;
1364
- customers_can_edit: boolean;
1365
- label_for_customers: string;
1366
- required_for_agents: boolean;
1367
- customers_can_filter: boolean;
1368
- required_for_closure: boolean;
1369
- displayed_to_customers: boolean;
1370
- required_for_customers: boolean;
1371
- choices?: Choice[];
1372
- };
1373
-
1374
- export type OrgWarmup = OverrideProperties<
1375
- Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1376
- {
1377
- warmup_chats: { [key: string]: string };
1378
- }
1379
- >;
1380
-
1381
- /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1382
-
1383
- export type FreshdeskIntegrationTokenType = OverrideProperties<
1384
- Tables<'tbl_integration_tokens'>,
1385
- {
1386
- type: 'freshdesk';
1387
- token_metadata: {
1388
- url: string;
1389
- apiKey: string;
1390
- fields: {
1391
- ticket: FreshdeskFieldType[];
1392
- company: FreshdeskFieldType[];
1393
- contact: FreshdeskFieldType[];
1394
- };
1395
- automation: {
1396
- id: number | string;
1397
- meta: {
1398
- total_count: number;
1399
- total_active_count: 17;
1400
- };
1401
- name: string;
1402
- active: boolean;
1403
- events: Array<{
1404
- to?: string;
1405
- from?: string;
1406
- field_name: string;
1407
- value?: string;
1408
- }>;
1409
- actions: Array<{
1410
- url: string;
1411
- content: Record<string, string>;
1412
- field_name: string;
1413
- content_type: string;
1414
- request_type: string;
1415
- content_layout: string;
1416
- }>;
1417
- summary: {
1418
- events: Array<string>;
1419
- actions: Array<string>;
1420
- performer: string;
1421
- conditions: {
1422
- [key: string]: Array<string>;
1423
- };
1424
- };
1425
- outdated: boolean;
1426
- position: number;
1427
- performer: {
1428
- type: string;
1429
- };
1430
- conditions: Array<{
1431
- name: string;
1432
- match_type: string;
1433
- properties: Array<{
1434
- value: Array<string>;
1435
- operator: string;
1436
- field_name: string;
1437
- resource_type: string;
1438
- case_sensitive: boolean;
1439
- }>;
1440
- }>;
1441
- created_at: string;
1442
- updated_at: string;
1443
- description: string | null;
1444
- last_updated_by: string | number;
1445
- affected_tickets_count: number | null;
1446
- };
1447
- org_details: {
1448
- address: {
1449
- city: string;
1450
- state: string;
1451
- street: string;
1452
- country: string;
1453
- postalcode: string;
1454
- };
1455
- timezone: string;
1456
- bundle_id: string;
1457
- tier_type: string;
1458
- account_id: number;
1459
- cloud_type: string;
1460
- data_center: string;
1461
- account_name: string;
1462
- total_agents: {
1463
- full_time: number;
1464
- occasional: number;
1465
- collaborators: number;
1466
- field_service: number;
1467
- };
1468
- account_domain: string;
1469
- contact_person: {
1470
- email: string;
1471
- lastname: string;
1472
- firstname: string;
1473
- };
1474
- hipaa_compliant: boolean;
1475
- organisation_id: number;
1476
- organisation_name: string;
1477
- };
1478
- custom_fields: {
1479
- ticket: FreshdeskFieldType[];
1480
- company: FreshdeskFieldType[];
1481
- contact: FreshdeskFieldType[];
1482
- };
1483
- integration_org_id: string | number;
1484
- ticket_auto_creation?: boolean;
1485
- };
1486
- }
1487
- >;
1488
-
1489
- export type ZohodeskIntegrationTokenType = OverrideProperties<
1490
- Tables<'tbl_integration_tokens'>,
1491
- {
1492
- type: 'zohodesk';
1493
- token_metadata: {
1494
- scope: string;
1495
- domain: string;
1496
- fields: Array<{
1497
- id: string;
1498
- name: string;
1499
- type: string;
1500
- apiName: string;
1501
- toolTip: string;
1502
- i18NLabel: string;
1503
- maxLength: number;
1504
- isMandatory: boolean;
1505
- toolTipType: string;
1506
- displayLabel: string;
1507
- isCustomField: boolean;
1508
- isEncryptedField: boolean;
1509
- showToHelpCenter: boolean;
1510
- }>;
1511
- org_id: string;
1512
- webhooks: {
1513
- id: string;
1514
- url: string;
1515
- name: string;
1516
- type: string;
1517
- createdBy: string;
1518
- isEnabled: boolean;
1519
- createdTime: string;
1520
- description: string;
1521
- modifiedTime: string;
1522
- subscriptions: {
1523
- [key: string]: {
1524
- departmentIds: string[];
1525
- includePrevState: boolean;
1526
- };
1527
- };
1528
- ignoreSourceId: boolean | null;
1529
- includeEventsFrom: string[];
1530
- };
1531
- api_domain: string;
1532
- authDomain: string;
1533
- expires_in: number;
1534
- token_type: string;
1535
- departments: Array<{
1536
- id: string;
1537
- name: string;
1538
- hasLogo: boolean;
1539
- creatorId: string;
1540
- isDefault: boolean;
1541
- isEnabled: boolean;
1542
- chatStatus: string;
1543
- createdTime: string;
1544
- description: string | null;
1545
- sanitizedName: string;
1546
- nameInCustomerPortal: string;
1547
- isAssignToTeamEnabled: boolean;
1548
- isVisibleInCustomerPortal: boolean;
1549
- }>;
1550
- org_details: {
1551
- id: number;
1552
- fax: string;
1553
- zip: string;
1554
- city: string;
1555
- alias: string | null;
1556
- state: string;
1557
- mobile: string;
1558
- street: string;
1559
- country: string;
1560
- edition: string;
1561
- logoURL: string;
1562
- website: string;
1563
- isDefault: boolean;
1564
- portalURL: string;
1565
- faviconURL: string;
1566
- portalName: string;
1567
- companyName: string;
1568
- description: string | null;
1569
- phoneNumber: string | null;
1570
- currencyCode: string;
1571
- isAdminInOrg: boolean;
1572
- employeeCount: number;
1573
- currencyLocale: string;
1574
- currencySymbol: string;
1575
- primaryContact: string;
1576
- isSandboxPortal: boolean;
1577
- isPayloadEncryptionEnabled: boolean;
1578
- };
1579
- access_token: string;
1580
- refresh_token: string;
1581
- integration_org_id: string | number;
1582
- ticket_auto_creation?: boolean;
1583
- };
1584
- }
1585
- >;
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
+ }
862
+
863
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
864
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
865
+ ? TicketInfoType
866
+ : T extends IntegrationLogType.NEW_CHAT
867
+ ? Tables<'tbl_chats'>
868
+ : T extends
869
+ | IntegrationLogType.NEW_MESSAGE
870
+ | IntegrationLogType.MESSAGE_UPDATED
871
+ | IntegrationLogType.MESSAGE_DELETED
872
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
873
+ | IntegrationLogType.MESSAGE_FLAGGED
874
+ | IntegrationLogType.MESSAGE_UNFLAGGED
875
+ | IntegrationLogType.MESSAGE_TICKET_ATTACHED
876
+ ? Tables<'tbl_chat_messages'>
877
+ : T extends
878
+ | IntegrationLogType.REACTION_CREATED
879
+ | IntegrationLogType.REACTION_UPDATED
880
+ ? Tables<'tbl_chat_reactions'>
881
+ : T extends
882
+ | IntegrationLogType.PHONE_DISCONNECTED
883
+ | IntegrationLogType.PHONE_CONNECTED
884
+ | IntegrationLogType.PHONE_UPDATED
885
+ | IntegrationLogType.PHONE_QR_UPDATED
886
+ ? Tables<'tbl_org_phones'>
887
+ : {
888
+ [key: string]: unknown;
889
+ };
890
+
891
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
892
+ OverrideProperties<
893
+ Tables<'tbl_integration_logs'>,
894
+ {
895
+ integration_name: T;
896
+ metadata: {
897
+ event: IntegrationLogMetadataType<T> & {
898
+ event_type: string;
899
+ org_id: string;
900
+ previous_attributes: {
901
+ [key: string]: unknown;
902
+ };
903
+ };
904
+ hook_id: string;
905
+ name: string;
906
+ };
907
+ }
908
+ >;
909
+
910
+ export type APIAuthDetails = {
911
+ org_details: Tables<'view_org'> | null;
912
+ phone_details: Tables<'tbl_org_phones'> | null;
913
+ token_details: Tables<'tbl_integration_tokens'> | null;
914
+ };
915
+
916
+ export type WebhookDataType = OverrideProperties<
917
+ Tables<'tbl_integration_hooks'>,
918
+ {
919
+ integration_name: string[];
920
+ }
921
+ >;
922
+
923
+ export type HubspotObjectDataType = {
924
+ createdAt: string;
925
+ archived: boolean;
926
+ id: string;
927
+ type: 'contacts' | 'tickets' | 'companies';
928
+ properties: Record<
929
+ string,
930
+ {
931
+ groupLabel: string;
932
+ groupName: string;
933
+ propertyKeyName: string;
934
+ propertyKey: string;
935
+ propertyInternalValue: string;
936
+ propertyValue: string;
937
+ propertyType: string;
938
+ propertyFieldType: string;
939
+ }[]
940
+ >;
941
+ };
942
+
943
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
944
+
945
+ export type UserPreferences = {
946
+ theme: 'light' | 'dark';
947
+ language: 'en' | 'es';
948
+ left_sidebar_open: boolean;
949
+ right_sidepanel_open: boolean;
950
+ sync_wa_unread_count: boolean;
951
+ pinned_chats: string[];
952
+ archived_chats: string[];
953
+ closed_chats: Record<string, number>;
954
+ periskope_chat_limit: number;
955
+ notifications: Record<string, boolean>;
956
+ };
957
+
958
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
959
+
960
+ export interface MostActiveMember {
961
+ sender_phone: string;
962
+ total_messages: number;
963
+ }
964
+
965
+ export interface GroupAnalyticsResult {
966
+ total_messages: number;
967
+ total_joins: number;
968
+ total_leaves: number;
969
+ total_removes: number;
970
+ total_reactions: number;
971
+ most_active_members: MostActiveMember[];
972
+ }
973
+
974
+ export interface TimeRange {
975
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
976
+ endDateTime: string;
977
+ }
978
+
979
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
980
+
981
+ export type PollSendType = {
982
+ pollName: string;
983
+ pollOptions: string[];
984
+ options?: {
985
+ allowMultipleAnswers?: boolean;
986
+ messageSecret?: number[] | null;
987
+ pollId?: string;
988
+ };
989
+ };
990
+
991
+ export type PollResultType = {
992
+ [name: string]: Record<string, string>;
993
+ };
994
+
995
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
996
+
997
+ export type CreateGroupOptions = {
998
+ messagesAdminsOnly?: boolean;
999
+ infoAdminsOnly?: boolean;
1000
+ addMembersAdminsOnly?: boolean;
1001
+ image?: string;
1002
+ name?: string;
1003
+ description?: string;
1004
+ initiated_by?: string;
1005
+ admins?: string[];
1006
+ force_add_participants?: boolean;
1007
+ };
1008
+
1009
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
1010
+
1011
+ export type DeliveryInfoType = {
1012
+ delivered: Record<string, number | undefined>;
1013
+ read: Record<string, number | undefined>;
1014
+ pending: string[];
1015
+ read_count: number;
1016
+ delivered_count: number;
1017
+ };
1018
+
1019
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1020
+
1021
+ export type OrgCreditsType = {
1022
+ org_id: string;
1023
+ recurring_allowance: number; // recurring credits replenished every cycle
1024
+ recurring_balance: number; // recurring credits remaining in current cycle
1025
+ topup_balance: number; // topup credits remaining
1026
+ total_credits_used: number; // total credits used in current cycle
1027
+ next_renewal_date: string;
1028
+ topup_credits_used: number; // topup credits used in current cycle
1029
+ recurring_credits_used: number; // recurring credits used in current cycle
1030
+ };
1031
+
1032
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
1033
+
1034
+ export type ChatRuleInfoType = {
1035
+ chat: Merge<
1036
+ Pick<
1037
+ Tables<'view_chats'>,
1038
+ | 'assigned_to'
1039
+ | 'chat_id'
1040
+ | 'chat_name'
1041
+ | 'chat_type'
1042
+ | 'created_at'
1043
+ | 'group_description'
1044
+ | 'info_admins_only'
1045
+ | 'org_id'
1046
+ | 'org_phone'
1047
+ | 'chat_org_phones'
1048
+ | 'messages_admins_only'
1049
+ | 'custom_properties'
1050
+ | 'initiated_by'
1051
+ >,
1052
+ {
1053
+ has_flagged_messages: boolean;
1054
+ labels: string[];
1055
+ members: string[];
1056
+ custom_properties: { [key: string]: string } | null;
1057
+ }
1058
+ >;
1059
+ };
1060
+
1061
+ export type SenderRuleInfoType = Merge<
1062
+ Omit<
1063
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1064
+ | 'verified_name'
1065
+ | 'verified_level'
1066
+ | 'updated_at'
1067
+ | 'short_name'
1068
+ | 'pushname'
1069
+ | 'periskope_name'
1070
+ | 'org_phone'
1071
+ | 'number'
1072
+ | 'name'
1073
+ | 'label_ids'
1074
+ | 'is_wa_contact'
1075
+ | 'is_user'
1076
+ | 'is_my_contact'
1077
+ | 'is_me'
1078
+ | 'is_imported'
1079
+ | 'is_group'
1080
+ | 'is_blocked'
1081
+ | 'contact_color'
1082
+ | 'business_profile'
1083
+ | 'id'
1084
+ | 'contact_image'
1085
+ | 'contact_type'
1086
+ | 'chat_id'
1087
+ | 'is_business'
1088
+ | 'is_enterprise'
1089
+ | 'is_super_admin'
1090
+ | 'contact_lid'
1091
+ >,
1092
+ {
1093
+ is_internal: boolean;
1094
+ labels: string[] | null;
1095
+ }
1096
+ >;
1097
+
1098
+ export type MessageRuleInfoType = {
1099
+ chat: ChatRuleInfoType['chat'];
1100
+ sender: SenderRuleInfoType;
1101
+ message: OverrideProperties<
1102
+ Omit<
1103
+ Tables<'tbl_chat_messages'>,
1104
+ | 'vcards'
1105
+ | 'updated_at'
1106
+ | 'unique_id'
1107
+ | 'token'
1108
+ | 'to'
1109
+ | 'sent_message_id'
1110
+ | 'raw_data'
1111
+ | 'delivery_info'
1112
+ | 'poll_results'
1113
+ | 'poll_info'
1114
+ | 'order_id'
1115
+ | 'mentioned_ids'
1116
+ | 'media_key'
1117
+ | 'location'
1118
+ | 'links'
1119
+ | 'is_status'
1120
+ | 'is_starred'
1121
+ | 'is_gif'
1122
+ | 'is_forwarded'
1123
+ | 'is_ephemeral'
1124
+ | 'is_deleted'
1125
+ | 'fts'
1126
+ | 'quoted_message_id'
1127
+ | 'invite_v4'
1128
+ | 'id'
1129
+ | 'has_reaction'
1130
+ | 'has_media'
1131
+ | 'duration'
1132
+ | 'broadcast'
1133
+ | 'broadcast_id'
1134
+ | 'device_type'
1135
+ | 'forwarding_score'
1136
+ | 'from'
1137
+ | 'from_me'
1138
+ | 'prev_body'
1139
+ | 'flag_response_time'
1140
+ | 'flag_metadata'
1141
+ | 'ack'
1142
+ >,
1143
+ {
1144
+ media: MediaType | null;
1145
+ }
1146
+ >;
1147
+ };
1148
+
1149
+ export type ReactionRuleInfoType = {
1150
+ chat: MessageRuleInfoType['chat'];
1151
+ sender: MessageRuleInfoType['sender'];
1152
+ message: MessageRuleInfoType['message'];
1153
+ reaction: Pick<
1154
+ Tables<'tbl_chat_reactions'>,
1155
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1156
+ >;
1157
+ };
1158
+
1159
+ export type TicketRuleInfoType = {
1160
+ chat: MessageRuleInfoType['chat'];
1161
+ sender: MessageRuleInfoType['sender'];
1162
+ ticket: Merge<
1163
+ Pick<
1164
+ Tables<'tbl_chat_tickets'>,
1165
+ | 'org_id'
1166
+ | 'status'
1167
+ | 'chat_id'
1168
+ | 'subject'
1169
+ | 'assignee'
1170
+ | 'due_date'
1171
+ | 'priority'
1172
+ | 'raised_by'
1173
+ | 'ticket_id'
1174
+ | 'created_at'
1175
+ | 'is_deleted'
1176
+ >,
1177
+ {
1178
+ labels: string[] | null;
1179
+ custom_properties: { [key: string]: string } | null;
1180
+ }
1181
+ >;
1182
+ message: MessageRuleInfoType['message'];
1183
+ };
1184
+
1185
+ export type TaskRuleInfoType<
1186
+ T extends 'ticket' | 'chat' | 'message' | 'todo' = 'todo',
1187
+ > = {
1188
+ associated_object_data: T extends 'message'
1189
+ ? MessageRuleInfoType
1190
+ : T extends 'ticket'
1191
+ ? TicketRuleInfoType
1192
+ : T extends 'chat'
1193
+ ? ChatRuleInfoType
1194
+ : null;
1195
+ task: Pick<
1196
+ TaskType,
1197
+ | 'org_id'
1198
+ | 'title'
1199
+ | 'notes'
1200
+ | 'status'
1201
+ | 'assignee'
1202
+ | 'due_date'
1203
+ | 'priority'
1204
+ | 'task_id'
1205
+ | 'created_at'
1206
+ >;
1207
+ };
1208
+
1209
+ export type FeatureFlagReturnType = Record<string, boolean>;
1210
+
1211
+ export type RuleLogsType = OverrideProperties<
1212
+ Tables<'tbl_rules_logs'>,
1213
+ {
1214
+ actions_progress: {
1215
+ action_id: string;
1216
+ action_type: Rule['actions'][number]['type'];
1217
+ action_delay: Rule['actions'][number]['delay'];
1218
+ ran_at: string | null;
1219
+ action_status: 'success' | 'failed' | 'pending';
1220
+ action_response: {
1221
+ success: boolean;
1222
+ data: Record<string, unknown> | null;
1223
+ error: {
1224
+ message: string;
1225
+ name: string;
1226
+ stack?: string;
1227
+ _error?: Error | Record<string, unknown>;
1228
+ } | null;
1229
+ };
1230
+ }[];
1231
+ metadata: {
1232
+ conditions: Rule['conditions'];
1233
+ actions: Rule['actions'];
1234
+ rule_metadata: Pick<
1235
+ Rule,
1236
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1237
+ >;
1238
+ data: Record<string, unknown>;
1239
+ };
1240
+ conditions_progress: {
1241
+ is_valid: boolean;
1242
+ validation_progress: Record<
1243
+ string,
1244
+ {
1245
+ res: boolean;
1246
+ filter: Filter;
1247
+ value: unknown;
1248
+ }
1249
+ >;
1250
+ checked_at: string | null;
1251
+ };
1252
+ }
1253
+ >;
1254
+
1255
+ /************************** TASKS ***************************/
1256
+
1257
+ export type ChatMetadataType = {
1258
+ type: 'chat';
1259
+ index: 'chat_id';
1260
+ id: string;
1261
+ object: Pick<ChatType, 'chat_id' | 'org_phone' | 'org_id'>;
1262
+ };
1263
+
1264
+ export type MessageMetadataType = {
1265
+ type: 'message';
1266
+ index: 'message_id';
1267
+ id: string;
1268
+ object: Pick<
1269
+ MessageType,
1270
+ | 'message_id'
1271
+ | 'org_phone'
1272
+ | 'chat_id'
1273
+ | 'sender_phone'
1274
+ | 'org_id'
1275
+ | 'is_private_note'
1276
+ >;
1277
+ };
1278
+
1279
+ export type TicketMetadataType = {
1280
+ type: 'ticket';
1281
+ index: 'ticket_id';
1282
+ id: string;
1283
+ object: Pick<
1284
+ TicketType,
1285
+ 'ticket_id' | 'quoted_message_id' | 'chat_id' | 'org_id'
1286
+ >;
1287
+ };
1288
+
1289
+ export type AssociatedObjectMetadataType<
1290
+ T extends 'chat' | 'message' | 'ticket' | 'todo' =
1291
+ | 'chat'
1292
+ | 'message'
1293
+ | 'ticket'
1294
+ | 'todo',
1295
+ > = T extends 'chat'
1296
+ ? ChatMetadataType
1297
+ : T extends 'message'
1298
+ ? MessageMetadataType
1299
+ : T extends 'ticket'
1300
+ ? TicketMetadataType
1301
+ : null;
1302
+
1303
+ export const isChatTask = (task: TaskType): task is TaskType<'chat'> =>
1304
+ task.associated_object_metadata?.type === 'chat';
1305
+
1306
+ export const isMessageTask = (task: TaskType): task is TaskType<'message'> =>
1307
+ task.associated_object_metadata?.type === 'message';
1308
+
1309
+ export const isTicketTask = (task: TaskType): task is TaskType<'ticket'> =>
1310
+ task.associated_object_metadata?.type === 'ticket';
1311
+
1312
+ export const isTodoTask = (task: TaskType): task is TaskType<'todo'> =>
1313
+ task.type === 'todo';
1314
+
1315
+ export type TaskType<
1316
+ T extends 'chat' | 'message' | 'ticket' | 'todo' =
1317
+ | 'chat'
1318
+ | 'message'
1319
+ | 'ticket'
1320
+ | 'todo',
1321
+ > = OverrideProperties<
1322
+ Tables<'tbl_org_tasks'>,
1323
+ {
1324
+ reminder_setting: {
1325
+ remind_in:
1326
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1327
+ | string
1328
+ | null;
1329
+ repeat?: {
1330
+ frequency: number;
1331
+ interval: 'days' | 'weeks' | 'months' | 'years';
1332
+ end: 'never' | 'after' | 'on';
1333
+ on?: string;
1334
+ };
1335
+ } | null;
1336
+ associated_object_metadata: AssociatedObjectMetadataType<T>;
1337
+ status: 'open' | 'inprogress' | 'closed';
1338
+ priority: 1 | 2 | 3;
1339
+ completed_metadata?: {
1340
+ completed_at: string;
1341
+ completed_by: string;
1342
+ } | null;
1343
+ type: T;
1344
+ }
1345
+ >;
1346
+
1347
+ type Choice = {
1348
+ id: number;
1349
+ label: string;
1350
+ value: string;
1351
+ position: number;
1352
+ };
1353
+
1354
+ export type FreshdeskFieldType = {
1355
+ id: number;
1356
+ name: string;
1357
+ type: string;
1358
+ label: string;
1359
+ default: boolean;
1360
+ archived: boolean;
1361
+ position: number;
1362
+ created_at: string;
1363
+ updated_at: string;
1364
+ customers_can_edit: boolean;
1365
+ label_for_customers: string;
1366
+ required_for_agents: boolean;
1367
+ customers_can_filter: boolean;
1368
+ required_for_closure: boolean;
1369
+ displayed_to_customers: boolean;
1370
+ required_for_customers: boolean;
1371
+ choices?: Choice[];
1372
+ };
1373
+
1374
+ export type OrgWarmup = OverrideProperties<
1375
+ Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1376
+ {
1377
+ warmup_chats: { [key: string]: string };
1378
+ }
1379
+ >;
1380
+
1381
+ /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1382
+
1383
+ export type FreshdeskIntegrationTokenType = OverrideProperties<
1384
+ Tables<'tbl_integration_tokens'>,
1385
+ {
1386
+ type: 'freshdesk';
1387
+ token_metadata: {
1388
+ url: string;
1389
+ apiKey: string;
1390
+ fields: {
1391
+ ticket: FreshdeskFieldType[];
1392
+ company: FreshdeskFieldType[];
1393
+ contact: FreshdeskFieldType[];
1394
+ };
1395
+ automation: {
1396
+ id: number | string;
1397
+ meta: {
1398
+ total_count: number;
1399
+ total_active_count: 17;
1400
+ };
1401
+ name: string;
1402
+ active: boolean;
1403
+ events: Array<{
1404
+ to?: string;
1405
+ from?: string;
1406
+ field_name: string;
1407
+ value?: string;
1408
+ }>;
1409
+ actions: Array<{
1410
+ url: string;
1411
+ content: Record<string, string>;
1412
+ field_name: string;
1413
+ content_type: string;
1414
+ request_type: string;
1415
+ content_layout: string;
1416
+ }>;
1417
+ summary: {
1418
+ events: Array<string>;
1419
+ actions: Array<string>;
1420
+ performer: string;
1421
+ conditions: {
1422
+ [key: string]: Array<string>;
1423
+ };
1424
+ };
1425
+ outdated: boolean;
1426
+ position: number;
1427
+ performer: {
1428
+ type: string;
1429
+ };
1430
+ conditions: Array<{
1431
+ name: string;
1432
+ match_type: string;
1433
+ properties: Array<{
1434
+ value: Array<string>;
1435
+ operator: string;
1436
+ field_name: string;
1437
+ resource_type: string;
1438
+ case_sensitive: boolean;
1439
+ }>;
1440
+ }>;
1441
+ created_at: string;
1442
+ updated_at: string;
1443
+ description: string | null;
1444
+ last_updated_by: string | number;
1445
+ affected_tickets_count: number | null;
1446
+ };
1447
+ org_details: {
1448
+ address: {
1449
+ city: string;
1450
+ state: string;
1451
+ street: string;
1452
+ country: string;
1453
+ postalcode: string;
1454
+ };
1455
+ timezone: string;
1456
+ bundle_id: string;
1457
+ tier_type: string;
1458
+ account_id: number;
1459
+ cloud_type: string;
1460
+ data_center: string;
1461
+ account_name: string;
1462
+ total_agents: {
1463
+ full_time: number;
1464
+ occasional: number;
1465
+ collaborators: number;
1466
+ field_service: number;
1467
+ };
1468
+ account_domain: string;
1469
+ contact_person: {
1470
+ email: string;
1471
+ lastname: string;
1472
+ firstname: string;
1473
+ };
1474
+ hipaa_compliant: boolean;
1475
+ organisation_id: number;
1476
+ organisation_name: string;
1477
+ };
1478
+ custom_fields: {
1479
+ ticket: FreshdeskFieldType[];
1480
+ company: FreshdeskFieldType[];
1481
+ contact: FreshdeskFieldType[];
1482
+ };
1483
+ integration_org_id: string | number;
1484
+ ticket_auto_creation?: boolean;
1485
+ };
1486
+ }
1487
+ >;
1488
+
1489
+ export type ZohodeskIntegrationTokenType = OverrideProperties<
1490
+ Tables<'tbl_integration_tokens'>,
1491
+ {
1492
+ type: 'zohodesk';
1493
+ token_metadata: {
1494
+ scope: string;
1495
+ domain: string;
1496
+ fields: Array<{
1497
+ id: string;
1498
+ name: string;
1499
+ type: string;
1500
+ apiName: string;
1501
+ toolTip: string;
1502
+ i18NLabel: string;
1503
+ maxLength: number;
1504
+ isMandatory: boolean;
1505
+ toolTipType: string;
1506
+ displayLabel: string;
1507
+ isCustomField: boolean;
1508
+ isEncryptedField: boolean;
1509
+ showToHelpCenter: boolean;
1510
+ }>;
1511
+ org_id: string;
1512
+ webhooks: {
1513
+ id: string;
1514
+ url: string;
1515
+ name: string;
1516
+ type: string;
1517
+ createdBy: string;
1518
+ isEnabled: boolean;
1519
+ createdTime: string;
1520
+ description: string;
1521
+ modifiedTime: string;
1522
+ subscriptions: {
1523
+ [key: string]: {
1524
+ departmentIds: string[];
1525
+ includePrevState: boolean;
1526
+ };
1527
+ };
1528
+ ignoreSourceId: boolean | null;
1529
+ includeEventsFrom: string[];
1530
+ };
1531
+ api_domain: string;
1532
+ authDomain: string;
1533
+ expires_in: number;
1534
+ token_type: string;
1535
+ departments: Array<{
1536
+ id: string;
1537
+ name: string;
1538
+ hasLogo: boolean;
1539
+ creatorId: string;
1540
+ isDefault: boolean;
1541
+ isEnabled: boolean;
1542
+ chatStatus: string;
1543
+ createdTime: string;
1544
+ description: string | null;
1545
+ sanitizedName: string;
1546
+ nameInCustomerPortal: string;
1547
+ isAssignToTeamEnabled: boolean;
1548
+ isVisibleInCustomerPortal: boolean;
1549
+ }>;
1550
+ org_details: {
1551
+ id: number;
1552
+ fax: string;
1553
+ zip: string;
1554
+ city: string;
1555
+ alias: string | null;
1556
+ state: string;
1557
+ mobile: string;
1558
+ street: string;
1559
+ country: string;
1560
+ edition: string;
1561
+ logoURL: string;
1562
+ website: string;
1563
+ isDefault: boolean;
1564
+ portalURL: string;
1565
+ faviconURL: string;
1566
+ portalName: string;
1567
+ companyName: string;
1568
+ description: string | null;
1569
+ phoneNumber: string | null;
1570
+ currencyCode: string;
1571
+ isAdminInOrg: boolean;
1572
+ employeeCount: number;
1573
+ currencyLocale: string;
1574
+ currencySymbol: string;
1575
+ primaryContact: string;
1576
+ isSandboxPortal: boolean;
1577
+ isPayloadEncryptionEnabled: boolean;
1578
+ };
1579
+ access_token: string;
1580
+ refresh_token: string;
1581
+ integration_org_id: string | number;
1582
+ ticket_auto_creation?: boolean;
1583
+ };
1584
+ }
1585
+ >;