@periskope/types 0.6.293 → 0.6.294

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,1297 +1,1297 @@
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
- sync_phone_contacts?: boolean;
71
- mask_phone_numbers?: boolean;
72
- show_sender_names?: boolean;
73
- closed_chats?: Record<string, number>;
74
- auto_read_muted_chats?: boolean;
75
- member_permissions?: Record<string, boolean>;
76
- };
77
-
78
- type OrgPreferenceKey = keyof OrgPreferences;
79
-
80
- export type OrgPreferencesValue = {
81
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
82
- }[OrgPreferenceKey];
83
-
84
- export type OrgAISettings = {
85
- ai_nickname?: string;
86
- confidence_score?: string;
87
- company_overview?: string;
88
- ai_responder_roles?: string;
89
- human_agent_roles?: string;
90
- ticket_creation_rules?: string;
91
- private_note_creation_rules?: string;
92
- response_delay_value?: string;
93
- snooze_delay_value?: string;
94
- temperature?: string;
95
- top_p?: string;
96
- top_k?: string;
97
- ai_maintain_flag_status?: boolean;
98
- };
99
-
100
- type OrgAISettingsKey = keyof OrgAISettings;
101
-
102
- export type OrgAISettingsValue = {
103
- [K in OrgAISettingsKey]: { key: K; value: OrgAISettings[K] };
104
- }[OrgAISettingsKey];
105
-
106
- export type CustomPropertySectionType = {
107
- id: string;
108
- name: string;
109
- order: number;
110
- type: 'chat' | 'ticket';
111
- properties_order?: {
112
- [id: string]: number;
113
- };
114
- };
115
-
116
- export enum CustomPropertyValueType {
117
- DROPDOWN = 'dropdown',
118
- TEXT = 'text',
119
- DATE = 'date',
120
- FILE = 'file',
121
- PICKLIST = 'picklist',
122
- DEPENDENT_DROPDOWN = 'dependent_dropdown',
123
- }
124
-
125
- export type CustomPropertyMetadataType = {
126
- section_id?: string;
127
- };
128
-
129
- export type CustomPropertyTextPropertiesType = {
130
- property_value_type: CustomPropertyValueType.TEXT;
131
- property_value: null;
132
- property_metadata: CustomPropertyMetadataType;
133
- };
134
-
135
- export type CustomPropertyDropdownPropertiesType = {
136
- property_value_type: CustomPropertyValueType.DROPDOWN;
137
- property_value: {
138
- [key: string]: string;
139
- };
140
- property_metadata: CustomPropertyMetadataType;
141
- };
142
-
143
- export type CustomPropertyPicklistPropertiesType = {
144
- property_value_type: CustomPropertyValueType.PICKLIST;
145
- property_value: {
146
- [key: string]: string;
147
- };
148
- property_metadata: CustomPropertyMetadataType;
149
- };
150
-
151
- export type CustomPropertyDependentDropdownPropertiesType = {
152
- property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
153
- property_value: {
154
- level_1: {
155
- value: string;
156
- label: string;
157
- level_2: {
158
- value: string;
159
- label: string;
160
- level_3: {
161
- value: string;
162
- label: string;
163
- }[];
164
- }[];
165
- }[];
166
- };
167
- property_metadata: Merge<
168
- CustomPropertyMetadataType,
169
- {
170
- level_names: {
171
- level_1: string;
172
- level_2: string;
173
- level_3: string;
174
- };
175
- }
176
- >;
177
- };
178
-
179
- export type CustomPropertyFilePropertiesType = {
180
- property_value_type: CustomPropertyValueType.FILE;
181
- property_value: null;
182
- property_metadata: CustomPropertyMetadataType;
183
- };
184
-
185
- export type CustomPropertyDatePropertiesType = {
186
- property_value_type: CustomPropertyValueType.DATE;
187
- property_value: null;
188
- property_metadata: CustomPropertyMetadataType;
189
- };
190
-
191
- export type CustomPropertyType = OverrideProperties<
192
- Tables<'tbl_custom_properties'>,
193
- | CustomPropertyDependentDropdownPropertiesType
194
- | CustomPropertyTextPropertiesType
195
- | CustomPropertyDropdownPropertiesType
196
- | CustomPropertyPicklistPropertiesType
197
- | CustomPropertyFilePropertiesType
198
- | CustomPropertyDatePropertiesType
199
- >;
200
-
201
- export type OrgMetadata = {
202
- phone_number: string;
203
- ticket_prefix: string;
204
- referralSource?: string;
205
- surveyData?: MicrosurveyData;
206
- preferences?: OrgPreferences;
207
- hubspot: {
208
- hubspot_pipelines?: {
209
- id: string;
210
- label: string;
211
- default_stage: { id: string; label: string };
212
- }[];
213
- hubspot_hidden_fields?: string[];
214
- };
215
- partition?: boolean;
216
- tickets: {
217
- prefix?: string;
218
- emoji_ticketing: {
219
- is_enabled?: boolean;
220
- is_message_enabled?: boolean;
221
- message_template?: string;
222
- };
223
- };
224
- attribution?: Object;
225
- affiliate_id?: string;
226
- custom_properties?: {
227
- sections?: CustomPropertySectionType[];
228
- };
229
- rules?: {
230
- limit?: number;
231
- };
232
- ai?: {
233
- flag_prompt?: string;
234
- };
235
- display_language?: string;
236
- };
237
-
238
- export type GroupTemplateType = OverrideProperties<
239
- Tables<'tbl_group_templates'>,
240
- {
241
- group_metadata: {
242
- messagesAdminsOnly?: boolean;
243
- infoAdminsOnly?: boolean;
244
- addMembersAdminsOnly?: boolean;
245
- description?: string;
246
- admins?: string[];
247
- };
248
- }
249
- >;
250
-
251
- type AccessScopes = {
252
- feature_flags: Record<string, boolean>;
253
- integrations: boolean;
254
- rules: boolean;
255
- exports: boolean;
256
- };
257
-
258
- export type OrgMembersType = OverrideProperties<
259
- Tables<'tbl_org_members'>,
260
- {
261
- member_metadata: {
262
- shift_times: {
263
- [day in
264
- | 'monday'
265
- | 'tuesday'
266
- | 'wednesday'
267
- | 'thursday'
268
- | 'friday'
269
- | 'saturday'
270
- | 'sunday']?: [[string, string]];
271
- };
272
- override_status: boolean;
273
- [key: string]: any;
274
- };
275
- }
276
- >;
277
-
278
- export type OrgType = OverrideProperties<
279
- Merge<
280
- Tables<'tbl_org'>,
281
- {
282
- user: OrgMembersType;
283
- members: OrgMembersType[];
284
- phones: Tables<'tbl_org_phones'>[];
285
- labels: Tables<'tbl_org_labels'>[];
286
- quick_replies: Tables<'tbl_quick_replies'>[];
287
- custom_properties: CustomPropertyType[];
288
- subscription_status: 'active' | 'inactive' | 'unpaid';
289
- is_enterprise: boolean;
290
- is_free_trial: boolean;
291
- is_hubspot_connected: boolean;
292
- is_freshdesk_connected: boolean;
293
- is_zohodesk_connected: boolean;
294
- access_scopes: AccessScopes;
295
- rules: Rule[];
296
- phone_limit: number;
297
- user_limit: number;
298
- }
299
- >,
300
- {
301
- org_plan: OrgPlan<AllPlans | Enterprise>;
302
- stripe_customer_details: _Stripe.Customer | null;
303
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
304
- stripe_customer_id: _Stripe.Customer['id'] | null;
305
- org_metadata: OrgMetadata;
306
- ai_settings: OrgAISettings;
307
- }
308
- >;
309
-
310
- export type ChatMemberType = Merge<
311
- Tables<'tbl_chat_participants'>,
312
- Tables<'tbl_contacts'>
313
- >;
314
-
315
- export type ChatType = Merge<
316
- Tables<'view_chats'>,
317
- {
318
- chat_id: string;
319
- latest_message: MessageType | null;
320
- latest_message_timestamp: number | null;
321
- members: { [key: string]: ChatMemberType } | null;
322
- chat_type: 'user' | 'group' | 'business' | 'unknown';
323
- chat_access: { [key: string]: boolean };
324
- label_ids: { [key: string]: boolean };
325
- chat_org_phones?: string[];
326
- message_unread_count: number | null;
327
- hubspot_metadata: {
328
- id: string;
329
- type: string;
330
- hubId: string;
331
- object_data: HubspotObjectDataType;
332
- } | null;
333
- info_admins_only: boolean;
334
- messages_admins_only: boolean;
335
- unread_count?: { [key: string]: number };
336
- active_phone: string | null;
337
- flag_count_map?: { [key: string]: number };
338
- is_archived?: boolean;
339
- is_pinned?: boolean;
340
- closed_at?: number | null;
341
- common_chats?: string[];
342
- freshdesk_metadata?: Record<string, any>;
343
- zohodesk_metadata?: Record<string, any>;
344
- pinned_messages?: {
345
- message_id: string;
346
- pinned_at: number;
347
- expires_at: number;
348
- }[];
349
- group_metadata?: Record<string, any>;
350
- snooze_metadata?: {
351
- snooze_until: number;
352
- snooze_message?: string;
353
- snooze_by?: string;
354
- };
355
- member_unread_count?: {
356
- [key: string]: number;
357
- };
358
- }
359
- >;
360
-
361
- /* -------------------------------------------------------------------------- */
362
- /* MESSAGE */
363
- /* -------------------------------------------------------------------------- */
364
-
365
- export type MediaType = {
366
- path?: string;
367
- mimetype?: string;
368
- filename?: string;
369
- dimensions?: { width: number; height: number; ar: number };
370
- size?: number;
371
- thumbnail?: string;
372
- filedata?: string;
373
- compress?: boolean;
374
- };
375
-
376
- export type MessageType = Merge<
377
- OverrideProperties<
378
- TablesInsert<'tbl_chat_messages'>,
379
- {
380
- message_id: string;
381
- org_id: string;
382
- org_phone: string;
383
- chat_id: string;
384
- message_type: (typeof SUPPORTED_TYPES)[number];
385
- media: MediaType | null;
386
- flag_metadata?: MessageFlagType | null;
387
- poll_info?: PollSendType | null;
388
- poll_results?: PollResultType | null;
389
- delivery_info?: DeliveryInfoType | null;
390
- raw_data?: {
391
- translations?: Record<string, string>;
392
- [key: string]: unknown;
393
- } | null;
394
- }
395
- >,
396
- {
397
- reactions?: ReactionType[];
398
- message_payload?: SingleMessagePayload;
399
- highlight?: number;
400
- is_private_note?: boolean;
401
- }
402
- >;
403
-
404
- export type MessageFlagType = {
405
- status: boolean;
406
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
407
- response_id?: string;
408
- response_timestamp?: string;
409
- response_email?: string;
410
- flagged_by?: string;
411
- flagged_at?: string;
412
- };
413
-
414
- export type MessageSendType = {
415
- queue_id: string;
416
- queue_position: string;
417
- };
418
-
419
- export type MessageBroadcastType = {
420
- broadcast_id: string;
421
- };
422
-
423
- /* -------------------------------------------------------------------------- */
424
-
425
- export type TicketType = OverrideProperties<
426
- Tables<'tbl_chat_tickets'>,
427
- {
428
- label_ids: { [key: string]: boolean };
429
- hubspot_metadata: {
430
- id?: string;
431
- type?: string;
432
- hubId?: string;
433
- pipeline: {
434
- id: string;
435
- label: string;
436
- };
437
- object_data?: HubspotObjectDataType;
438
- } | null;
439
- freshdesk_metadata: Record<string, string>;
440
- close_ticket_metadata?:
441
- | {
442
- closed_by: string;
443
- closed_at: string;
444
- closed_message?: string | null;
445
- send_reply_message_id?: string | null;
446
- }
447
- | any;
448
- }
449
- >;
450
-
451
- export type ContactType = Merge<
452
- Tables<'tbl_contacts'>,
453
- {
454
- chats: ChatType[] | null;
455
- chat_ids?: string[];
456
- }
457
- >;
458
- export type ReactionType = Tables<'tbl_chat_reactions'>;
459
-
460
- export type NotificationType = Tables<'tbl_chat_notifications'>;
461
-
462
- export type ChatAccessType = Merge<
463
- TablesUpdate<'tbl_org_members'>,
464
- {
465
- has_access?: boolean;
466
- email: string | null;
467
- }
468
- >;
469
-
470
- export type QueueJobTypes = {
471
- addedTimestamp: number;
472
- attemptsMade: number;
473
- attemptsStarted: number;
474
- data: {
475
- body: string;
476
- chat_id: string;
477
- };
478
- finishedTimestamp: number;
479
- id: string;
480
- message_id: string;
481
- processedTimestamp: number;
482
- stacktrace: string[];
483
- status: string;
484
- };
485
-
486
- export type PhoneQueueStatusType = {
487
- active: number;
488
- failed: number;
489
- completed: number;
490
- is_running: boolean;
491
- pending: number;
492
- };
493
-
494
- export type PhoneType = OverrideProperties<
495
- Tables<'tbl_org_phones'>,
496
- {
497
- queue_status: {
498
- [key: string]: PhoneQueueStatusType;
499
- };
500
- }
501
- >;
502
-
503
- export type PhoneInfoType = Merge<
504
- Pick<
505
- PhoneType,
506
- | 'created_at'
507
- | 'first_connected_at'
508
- | 'is_ready'
509
- | 'label_ids'
510
- | 'org_id'
511
- | 'org_phone'
512
- | 'phone_id'
513
- | 'phone_image'
514
- | 'phone_name'
515
- | 'qr_code'
516
- | 'updated_at'
517
- | 'wa_state'
518
- >,
519
- {
520
- labels: string[];
521
- }
522
- >;
523
-
524
- /* -------------------------------- CONSTANTS ------------------------------- */
525
-
526
- export const labelColors = [
527
- '#9333EA',
528
- '#0D9488',
529
- '#DB2777',
530
- '#2563EB',
531
- '#F97316',
532
- ];
533
-
534
- export const enumChatColors = [
535
- '#B4876E',
536
- '#A5B337',
537
- '#06CF9C',
538
- '#25D366',
539
- '#02A698',
540
- '#7D9EF1',
541
- '#007BFC',
542
- '#5E47DE',
543
- '#7F66FF',
544
- '#9333EA',
545
- '#FA6533',
546
- '#C4532D',
547
- '#DC2626',
548
- '#FF2E74',
549
- '#DB2777',
550
- ] as const;
551
-
552
- export type RepeatDaysType =
553
- | 'monday'
554
- | 'tuesday'
555
- | 'wednesday'
556
- | 'thursday'
557
- | 'friday'
558
- | 'saturday'
559
- | 'sunday';
560
- export type RepeatIntervalType = 'day' | 'week' | 'month';
561
-
562
- export enum WhatsappGroupActionEnum {
563
- ADD = 'add',
564
- REMOVE = 'remove',
565
- PROMOTE = 'promote',
566
- DEMOTE = 'demote',
567
- INVITE = 'invite',
568
- LEAVE = 'leave',
569
- ANNOUNCE_TRUE = 'announce_true',
570
- ANNOUNCE_FALSE = 'announce_false',
571
- RESTRICT_TRUE = 'restrict_true',
572
- RESTRICT_FALSE = 'restrict_false',
573
- MEMBERADDMODE_TRUE = 'memberaddmode_true',
574
- MEMBERADDMODE_FALSE = 'memberaddmode_false',
575
- SUBJECT = 'subject',
576
- DESC = 'desc',
577
- CALL = 'call',
578
- }
579
-
580
- /* -------------------------- LISTING ENDPOINT -------------------------- */
581
-
582
- type ListingType = {
583
- from?: number;
584
- to?: number;
585
- count?: number;
586
- };
587
-
588
- export type ListNotificationsType = Merge<
589
- ListingType,
590
- {
591
- notifictions?: NotificationType[];
592
- }
593
- >;
594
-
595
- export type ListChatMessagesType = Merge<
596
- ListingType,
597
- {
598
- messages?: MessageType[];
599
- }
600
- >;
601
-
602
- export type ListContactsType = Merge<
603
- ListingType,
604
- {
605
- contacts?: ContactType[];
606
- }
607
- >;
608
-
609
- export type ListTicketsType = Merge<
610
- ListingType,
611
- {
612
- tickets?: TicketType[];
613
- }
614
- >;
615
-
616
- export type ListChatsType = Merge<
617
- ListingType,
618
- {
619
- chats?: ChatType[];
620
- }
621
- >;
622
-
623
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
624
-
625
- export const SUPPORTED_TYPES = [
626
- 'chat',
627
- 'sticker',
628
- 'image',
629
- 'video',
630
- 'document',
631
- 'vcard',
632
- 'multi_vcard',
633
- 'audio',
634
- 'ptt',
635
- 'poll_creation',
636
- 'location',
637
- 'ciphertext',
638
- ] as const;
639
-
640
- export type SendMessageContent = {
641
- message_type?: (typeof SUPPORTED_TYPES)[number];
642
- body?: string;
643
- media?: MediaType;
644
- contact_ids?: string[];
645
- location?: {
646
- latitude: string;
647
- longitude: string;
648
- options?: { name?: string; address?: string; url?: string };
649
- };
650
- poll?: PollSendType;
651
- quoted_message_id?: string;
652
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
653
- broadcast_id?: string;
654
- performed_by?: string;
655
- options?: Record<string, any>;
656
- };
657
-
658
- export type QuickReplyContent = Omit<
659
- SendMessageContent,
660
- 'broadcast_id' | 'variables'
661
- >;
662
-
663
- export type ScheduleMessagePayload = {
664
- scheduled_id?: string;
665
- is_repeat?: boolean | null;
666
- scheduled_at: string;
667
- repeat_config?: {
668
- timezone?: string;
669
- repeat_ends?: string;
670
- repeat_interval?: RepeatIntervalType;
671
- repeat_value?: number;
672
- repeat_days?: RepeatDaysType[];
673
- };
674
- };
675
-
676
- export type BroadcastVariableType = {
677
- chat_id: string;
678
- values: { [key: string]: string };
679
- };
680
-
681
- export type BroadcastMessagePayload = SendMessageContent & {
682
- chat_ids: string[];
683
- broadcast_id?: string;
684
- variables?: BroadcastVariableType[];
685
- delay?: number;
686
- };
687
-
688
- export type SingleMessagePayload = SendMessageContent & {
689
- chat_id: string;
690
- job_id?: string;
691
- priority?: number;
692
- };
693
-
694
- export type MessageAttachmentFileTypes =
695
- | 'image'
696
- | 'audio'
697
- | 'document'
698
- | 'video';
699
-
700
- export type AttachmentFileType = {
701
- result: string;
702
- file: File | null;
703
- type: MessageAttachmentFileTypes;
704
- localFileURL?: string;
705
- };
706
-
707
- export type AttachmentLinkType = {
708
- link: {
709
- url: string;
710
- type: MessageAttachmentFileTypes;
711
- name: string;
712
- mimetype?: string;
713
- };
714
- };
715
-
716
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
717
-
718
- /* -------------------------------- BROADCAST ------------------------------- */
719
-
720
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
721
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
722
- } & {
723
- chats: ChatType[];
724
- };
725
-
726
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
727
-
728
- export type ChatLogType = {
729
- log: Tables<'view_chat_logs'>;
730
- operations: Tables<'tbl_chat_logs'>[];
731
- };
732
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
733
-
734
- export type ChatParticipantOperationPayload = {
735
- participant_ids: string[];
736
- chat_ids: string[];
737
- performed_by: string;
738
- force_add_participants?: boolean;
739
- };
740
-
741
- export type ChatOperationReturn = {
742
- [participant_id: string]: {
743
- is_success: boolean;
744
- message?: string;
745
- code?: number;
746
- isInviteV4Sent?: boolean;
747
- };
748
- };
749
-
750
- /* ----------------------- BILLING - STRIPE ----------------------- */
751
-
752
- export type StripeSubscription = _Stripe.Subscription;
753
- export type StripeCustomer = _Stripe.Customer;
754
- export type StripeCoupon = _Stripe.Coupon;
755
- export type StripePrice = _Stripe.Price;
756
- export type Stripe = _Stripe;
757
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
758
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
759
-
760
- /* -------------------------------- REALTIME -------------------------------- */
761
-
762
- export type PhoneStateType = {
763
- loading: boolean;
764
- state: string;
765
- sync: number;
766
- percent: number | null;
767
- message?: string;
768
- error?: string;
769
- };
770
-
771
- /* ------------------------------- INTEGRATIONS ----------------------------- */
772
-
773
- export type ChatInfoType = Merge<
774
- ChatType,
775
- {
776
- members: {
777
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
778
- } | null;
779
- chat_labels: string | null;
780
- custom_properties: { [key: string]: string } | null;
781
- }
782
- >;
783
-
784
- export type TicketInfoType = {
785
- chat: ChatInfoType;
786
- message: {
787
- body: string;
788
- chat_id: string;
789
- org_phone: string;
790
- timestamp: string;
791
- media_path: string;
792
- message_id: string;
793
- sender_name: string;
794
- performed_by: string;
795
- sender_phone: string;
796
- };
797
- ticket: {
798
- org_id: string;
799
- status: string;
800
- subject: string;
801
- assignee: string;
802
- due_date: string;
803
- priority: 0 | 1 | 2 | 3 | 4;
804
- raised_by: string;
805
- ticket_id: string;
806
- created_at: string;
807
- assigned_by: string;
808
- ticket_labels: string;
809
- quoted_message_id: string;
810
- ticket_custom_properties: { [key: string]: string } | null;
811
- closed_at: string;
812
- closed_by: string;
813
- closed_message: string;
814
- first_assigned_at: string | null;
815
- };
816
- attached_messages: {
817
- body: string;
818
- chat_id: string;
819
- org_phone: string;
820
- timestamp: string;
821
- media_path: string;
822
- message_id: string;
823
- sender_name: string;
824
- performed_by: string;
825
- sender_phone: string;
826
- }[];
827
- };
828
-
829
- export type IntegrationLogObjectType =
830
- | 'chat'
831
- | 'message'
832
- | 'reaction'
833
- | 'ticket'
834
- | 'phone';
835
- export enum IntegrationLogType {
836
- NEW_CHAT = 'chat.created',
837
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
838
- NEW_MESSAGE = 'message.created',
839
- MESSAGE_UPDATED = 'message.updated',
840
- MESSAGE_DELETED = 'message.deleted',
841
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
842
- MESSAGE_FLAGGED = 'message.flagged',
843
- MESSAGE_UNFLAGGED = 'message.unflagged',
844
- MESSAGE_TICKET_ATTACHED = 'message.ticket.attached',
845
- REACTION_CREATED = 'reaction.created',
846
- REACTION_UPDATED = 'reaction.updated',
847
- NEW_TICKET = 'ticket.created',
848
- TICKET_UPDATED = 'ticket.updated',
849
- TICKET_DELETED = 'ticket.deleted',
850
- PHONE_DISCONNECTED = 'org.phone.disconnected',
851
- PHONE_CONNECTED = 'org.phone.connected',
852
- PHONE_UPDATED = 'org.phone.updated',
853
- PHONE_QR_UPDATED = 'org.phone.qr',
854
- }
855
-
856
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
857
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
858
- ? TicketInfoType
859
- : T extends IntegrationLogType.NEW_CHAT
860
- ? Tables<'tbl_chats'>
861
- : T extends
862
- | IntegrationLogType.NEW_MESSAGE
863
- | IntegrationLogType.MESSAGE_UPDATED
864
- | IntegrationLogType.MESSAGE_DELETED
865
- | IntegrationLogType.MESSAGE_ACK_UPDATED
866
- | IntegrationLogType.MESSAGE_FLAGGED
867
- | IntegrationLogType.MESSAGE_UNFLAGGED
868
- | IntegrationLogType.MESSAGE_TICKET_ATTACHED
869
- ? Tables<'tbl_chat_messages'>
870
- : T extends
871
- | IntegrationLogType.REACTION_CREATED
872
- | IntegrationLogType.REACTION_UPDATED
873
- ? Tables<'tbl_chat_reactions'>
874
- : T extends
875
- | IntegrationLogType.PHONE_DISCONNECTED
876
- | IntegrationLogType.PHONE_CONNECTED
877
- | IntegrationLogType.PHONE_UPDATED
878
- | IntegrationLogType.PHONE_QR_UPDATED
879
- ? Tables<'tbl_org_phones'>
880
- : {
881
- [key: string]: unknown;
882
- };
883
-
884
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
885
- OverrideProperties<
886
- Tables<'tbl_integration_logs'>,
887
- {
888
- integration_name: T;
889
- metadata: {
890
- event: IntegrationLogMetadataType<T> & {
891
- event_type: string;
892
- org_id: string;
893
- previous_attributes: {
894
- [key: string]: unknown;
895
- };
896
- };
897
- hook_id: string;
898
- name: string;
899
- };
900
- }
901
- >;
902
-
903
- export type APIAuthDetails = {
904
- org_details: Tables<'view_org'> | null;
905
- phone_details: Tables<'tbl_org_phones'> | null;
906
- token_details: Tables<'tbl_integration_tokens'> | null;
907
- };
908
-
909
- export type WebhookDataType = OverrideProperties<
910
- Tables<'tbl_integration_hooks'>,
911
- {
912
- integration_name: string[];
913
- }
914
- >;
915
-
916
- export type HubspotObjectDataType = {
917
- createdAt: string;
918
- archived: boolean;
919
- id: string;
920
- type: 'contacts' | 'tickets' | 'companies';
921
- properties: Record<
922
- string,
923
- {
924
- groupLabel: string;
925
- groupName: string;
926
- propertyKeyName: string;
927
- propertyKey: string;
928
- propertyInternalValue: string;
929
- propertyValue: string;
930
- propertyType: string;
931
- propertyFieldType: string;
932
- }[]
933
- >;
934
- };
935
-
936
- /* ---------------------------- USER PREFERENCES ---------------------------- */
937
-
938
- export type UserPreferences = {
939
- theme: 'light' | 'dark';
940
- language: 'en' | 'es';
941
- left_sidebar_open: boolean;
942
- right_sidepanel_open: boolean;
943
- sync_wa_unread_count: boolean;
944
- pinned_chats: string[];
945
- archived_chats: string[];
946
- closed_chats: Record<string, number>;
947
- periskope_chat_limit: number;
948
- notifications: Record<string, boolean>;
949
- };
950
-
951
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
952
-
953
- export interface MostActiveMember {
954
- sender_phone: string;
955
- total_messages: number;
956
- }
957
-
958
- export interface GroupAnalyticsResult {
959
- total_messages: number;
960
- total_joins: number;
961
- total_leaves: number;
962
- total_removes: number;
963
- total_reactions: number;
964
- most_active_members: MostActiveMember[];
965
- }
966
-
967
- export interface TimeRange {
968
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
969
- endDateTime: string;
970
- }
971
-
972
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
973
-
974
- export type PollSendType = {
975
- pollName: string;
976
- pollOptions: string[];
977
- options?: {
978
- allowMultipleAnswers?: boolean;
979
- messageSecret?: number[] | null;
980
- pollId?: string;
981
- };
982
- };
983
-
984
- export type PollResultType = {
985
- [name: string]: Record<string, string>;
986
- };
987
-
988
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
989
-
990
- export type CreateGroupOptions = {
991
- messagesAdminsOnly?: boolean;
992
- infoAdminsOnly?: boolean;
993
- addMembersAdminsOnly?: boolean;
994
- image?: string;
995
- name?: string;
996
- description?: string;
997
- initiated_by?: string;
998
- admins?: string[];
999
- force_add_participants?: boolean;
1000
- };
1001
-
1002
- /* ------------------------------ DELIVERY INFO ----------------------------- */
1003
-
1004
- export type DeliveryInfoType = {
1005
- delivered: Record<string, number | undefined>;
1006
- read: Record<string, number | undefined>;
1007
- pending: string[];
1008
- read_count: number;
1009
- delivered_count: number;
1010
- };
1011
-
1012
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1013
-
1014
- export type OrgCreditsType = {
1015
- org_id: string;
1016
- recurring_allowance: number; // recurring credits replenished every cycle
1017
- recurring_balance: number; // recurring credits remaining in current cycle
1018
- topup_balance: number; // topup credits remaining
1019
- total_credits_used: number; // total credits used in current cycle
1020
- next_renewal_date: string;
1021
- topup_credits_used: number; // topup credits used in current cycle
1022
- recurring_credits_used: number; // recurring credits used in current cycle
1023
- };
1024
-
1025
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
1026
-
1027
- export type ChatRuleInfoType = Merge<
1028
- Pick<
1029
- Tables<'view_chats'>,
1030
- | 'assigned_to'
1031
- | 'chat_id'
1032
- | 'chat_name'
1033
- | 'chat_type'
1034
- | 'created_at'
1035
- | 'group_description'
1036
- | 'info_admins_only'
1037
- | 'org_id'
1038
- | 'org_phone'
1039
- | 'chat_org_phones'
1040
- | 'messages_admins_only'
1041
- | 'custom_properties'
1042
- | 'initiated_by'
1043
- >,
1044
- {
1045
- has_flagged_messages: boolean;
1046
- labels: string[];
1047
- members: string[];
1048
- custom_properties: { [key: string]: string } | null;
1049
- }
1050
- >;
1051
-
1052
- export type SenderRuleInfoType = Merge<
1053
- Omit<
1054
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1055
- | 'verified_name'
1056
- | 'verified_level'
1057
- | 'updated_at'
1058
- | 'short_name'
1059
- | 'pushname'
1060
- | 'periskope_name'
1061
- | 'org_phone'
1062
- | 'number'
1063
- | 'name'
1064
- | 'label_ids'
1065
- | 'is_wa_contact'
1066
- | 'is_user'
1067
- | 'is_my_contact'
1068
- | 'is_me'
1069
- | 'is_imported'
1070
- | 'is_group'
1071
- | 'is_blocked'
1072
- | 'contact_color'
1073
- | 'business_profile'
1074
- | 'id'
1075
- | 'contact_image'
1076
- | 'contact_type'
1077
- | 'chat_id'
1078
- | 'is_business'
1079
- | 'is_enterprise'
1080
- | 'is_super_admin'
1081
- | 'contact_lid'
1082
- >,
1083
- {
1084
- is_internal: boolean;
1085
- labels: string[] | null;
1086
- }
1087
- >;
1088
-
1089
- export type MessageRuleInfoType = {
1090
- chat: ChatRuleInfoType;
1091
- sender: SenderRuleInfoType;
1092
- message: OverrideProperties<
1093
- Omit<
1094
- Tables<'tbl_chat_messages'>,
1095
- | 'vcards'
1096
- | 'updated_at'
1097
- | 'unique_id'
1098
- | 'token'
1099
- | 'to'
1100
- | 'sent_message_id'
1101
- | 'raw_data'
1102
- | 'delivery_info'
1103
- | 'poll_results'
1104
- | 'poll_info'
1105
- | 'order_id'
1106
- | 'mentioned_ids'
1107
- | 'media_key'
1108
- | 'location'
1109
- | 'links'
1110
- | 'is_status'
1111
- | 'is_starred'
1112
- | 'is_gif'
1113
- | 'is_forwarded'
1114
- | 'is_ephemeral'
1115
- | 'is_deleted'
1116
- | 'fts'
1117
- | 'quoted_message_id'
1118
- | 'invite_v4'
1119
- | 'id'
1120
- | 'has_reaction'
1121
- | 'has_media'
1122
- | 'duration'
1123
- | 'broadcast'
1124
- | 'broadcast_id'
1125
- | 'device_type'
1126
- | 'forwarding_score'
1127
- | 'from'
1128
- | 'from_me'
1129
- | 'prev_body'
1130
- | 'flag_response_time'
1131
- | 'flag_metadata'
1132
- | 'ack'
1133
- >,
1134
- {
1135
- media: MediaType | null;
1136
- }
1137
- >;
1138
- };
1139
-
1140
- export type ReactionRuleInfoType = {
1141
- chat: ChatRuleInfoType;
1142
- sender: SenderRuleInfoType;
1143
- message: MessageRuleInfoType['message'];
1144
- reaction: Pick<
1145
- Tables<'tbl_chat_reactions'>,
1146
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1147
- >;
1148
- };
1149
-
1150
- export type TicketRuleInfoType = {
1151
- chat: ChatRuleInfoType;
1152
- sender: SenderRuleInfoType;
1153
- ticket: Merge<
1154
- Pick<
1155
- Tables<'tbl_chat_tickets'>,
1156
- | 'org_id'
1157
- | 'status'
1158
- | 'chat_id'
1159
- | 'subject'
1160
- | 'assignee'
1161
- | 'due_date'
1162
- | 'priority'
1163
- | 'raised_by'
1164
- | 'ticket_id'
1165
- | 'created_at'
1166
- | 'is_deleted'
1167
- >,
1168
- {
1169
- labels: string[] | null;
1170
- custom_properties: { [key: string]: string } | null;
1171
- }
1172
- >;
1173
- message: MessageRuleInfoType['message'];
1174
- };
1175
- export type FeatureFlagReturnType = Record<string, boolean>;
1176
-
1177
- export type RuleLogsType = OverrideProperties<
1178
- Tables<'tbl_rules_logs'>,
1179
- {
1180
- actions_progress: {
1181
- action_id: string;
1182
- action_type: Rule['actions'][number]['type'];
1183
- action_delay: Rule['actions'][number]['delay'];
1184
- ran_at: string | null;
1185
- action_status: 'success' | 'failed' | 'pending';
1186
- action_response: {
1187
- success: boolean;
1188
- data: Record<string, unknown> | null;
1189
- error: {
1190
- message: string;
1191
- name: string;
1192
- stack?: string;
1193
- _error?: Error | Record<string, unknown>;
1194
- } | null;
1195
- };
1196
- }[];
1197
- metadata: {
1198
- conditions: Rule['conditions'];
1199
- actions: Rule['actions'];
1200
- rule_metadata: Pick<
1201
- Rule,
1202
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1203
- >;
1204
- data: Record<string, unknown>;
1205
- };
1206
- conditions_progress: {
1207
- is_valid: boolean;
1208
- validation_progress: Record<
1209
- string,
1210
- {
1211
- res: boolean;
1212
- filter: Filter;
1213
- value: unknown;
1214
- }
1215
- >;
1216
- checked_at: string | null;
1217
- };
1218
- }
1219
- >;
1220
-
1221
- /************************** TASKS ***************************/
1222
-
1223
- export type TaskType = OverrideProperties<
1224
- Tables<'tbl_org_tasks'>,
1225
- {
1226
- reminder_setting: {
1227
- remind_in:
1228
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1229
- | string
1230
- | null;
1231
- repeat?: {
1232
- frequency: number;
1233
- interval: 'days' | 'weeks' | 'months' | 'years';
1234
- end: 'never' | 'after' | 'on';
1235
- on?: string;
1236
- };
1237
- } | null;
1238
- associated_object_metadata:
1239
- | {
1240
- type: 'chat';
1241
- index: 'chat_id';
1242
- id: string;
1243
- object: ChatType;
1244
- }
1245
- | {
1246
- type: 'message';
1247
- index: 'message_id';
1248
- id: string;
1249
- object: MessageType;
1250
- }
1251
- | {
1252
- type: 'ticket';
1253
- index: 'ticket_id';
1254
- id: string;
1255
- object: TicketType;
1256
- }
1257
- | null;
1258
- status: 'open' | 'inprogress' | 'closed';
1259
- priority: 1 | 2 | 3;
1260
- completed_metadata?: {
1261
- completed_at: string;
1262
- completed_by: string;
1263
- } | null;
1264
- type: 'todo' | 'chat' | 'message' | 'ticket';
1265
- }
1266
- >;
1267
-
1268
- type Choice = {
1269
- id: number;
1270
- label: string;
1271
- value: string;
1272
- position: number;
1273
- };
1274
-
1275
- export type FreshdeskCustomFieldType = {
1276
- id: number;
1277
- name: string;
1278
- label: string;
1279
- position: number;
1280
- required_for_agents: boolean;
1281
- archived: boolean;
1282
- customers_can_edit: boolean;
1283
- label_for_customers: string;
1284
- required_for_customers: boolean;
1285
- customers_can_filter: boolean;
1286
- required_for_closure: boolean;
1287
- displayed_to_customers: boolean;
1288
- type: string;
1289
- default: boolean;
1290
- created_at: string;
1291
- updated_at: string;
1292
- choices?: Choice[];
1293
- };
1294
-
1295
- export type OrgWarmup = OverrideProperties<Tables<{ schema: 'internal' }, 'tbl_org_warmup'>, {
1296
- warmup_chats: {[key: string]: string};
1297
- }>
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
+ sync_phone_contacts?: boolean;
71
+ mask_phone_numbers?: boolean;
72
+ show_sender_names?: boolean;
73
+ closed_chats?: Record<string, number>;
74
+ auto_read_muted_chats?: boolean;
75
+ member_permissions?: Record<string, boolean>;
76
+ };
77
+
78
+ type OrgPreferenceKey = keyof OrgPreferences;
79
+
80
+ export type OrgPreferencesValue = {
81
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
82
+ }[OrgPreferenceKey];
83
+
84
+ export type OrgAISettings = {
85
+ ai_nickname?: string;
86
+ confidence_score?: string;
87
+ company_overview?: string;
88
+ ai_responder_roles?: string;
89
+ human_agent_roles?: string;
90
+ ticket_creation_rules?: string;
91
+ private_note_creation_rules?: string;
92
+ response_delay_value?: string;
93
+ snooze_delay_value?: string;
94
+ temperature?: string;
95
+ top_p?: string;
96
+ top_k?: string;
97
+ ai_maintain_flag_status?: boolean;
98
+ };
99
+
100
+ type OrgAISettingsKey = keyof OrgAISettings;
101
+
102
+ export type OrgAISettingsValue = {
103
+ [K in OrgAISettingsKey]: { key: K; value: OrgAISettings[K] };
104
+ }[OrgAISettingsKey];
105
+
106
+ export type CustomPropertySectionType = {
107
+ id: string;
108
+ name: string;
109
+ order: number;
110
+ type: 'chat' | 'ticket';
111
+ properties_order?: {
112
+ [id: string]: number;
113
+ };
114
+ };
115
+
116
+ export enum CustomPropertyValueType {
117
+ DROPDOWN = 'dropdown',
118
+ TEXT = 'text',
119
+ DATE = 'date',
120
+ FILE = 'file',
121
+ PICKLIST = 'picklist',
122
+ DEPENDENT_DROPDOWN = 'dependent_dropdown',
123
+ }
124
+
125
+ export type CustomPropertyMetadataType = {
126
+ section_id?: string;
127
+ };
128
+
129
+ export type CustomPropertyTextPropertiesType = {
130
+ property_value_type: CustomPropertyValueType.TEXT;
131
+ property_value: null;
132
+ property_metadata: CustomPropertyMetadataType;
133
+ };
134
+
135
+ export type CustomPropertyDropdownPropertiesType = {
136
+ property_value_type: CustomPropertyValueType.DROPDOWN;
137
+ property_value: {
138
+ [key: string]: string;
139
+ };
140
+ property_metadata: CustomPropertyMetadataType;
141
+ };
142
+
143
+ export type CustomPropertyPicklistPropertiesType = {
144
+ property_value_type: CustomPropertyValueType.PICKLIST;
145
+ property_value: {
146
+ [key: string]: string;
147
+ };
148
+ property_metadata: CustomPropertyMetadataType;
149
+ };
150
+
151
+ export type CustomPropertyDependentDropdownPropertiesType = {
152
+ property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
153
+ property_value: {
154
+ level_1: {
155
+ value: string;
156
+ label: string;
157
+ level_2: {
158
+ value: string;
159
+ label: string;
160
+ level_3: {
161
+ value: string;
162
+ label: string;
163
+ }[];
164
+ }[];
165
+ }[];
166
+ };
167
+ property_metadata: Merge<
168
+ CustomPropertyMetadataType,
169
+ {
170
+ level_names: {
171
+ level_1: string;
172
+ level_2: string;
173
+ level_3: string;
174
+ };
175
+ }
176
+ >;
177
+ };
178
+
179
+ export type CustomPropertyFilePropertiesType = {
180
+ property_value_type: CustomPropertyValueType.FILE;
181
+ property_value: null;
182
+ property_metadata: CustomPropertyMetadataType;
183
+ };
184
+
185
+ export type CustomPropertyDatePropertiesType = {
186
+ property_value_type: CustomPropertyValueType.DATE;
187
+ property_value: null;
188
+ property_metadata: CustomPropertyMetadataType;
189
+ };
190
+
191
+ export type CustomPropertyType = OverrideProperties<
192
+ Tables<'tbl_custom_properties'>,
193
+ | CustomPropertyDependentDropdownPropertiesType
194
+ | CustomPropertyTextPropertiesType
195
+ | CustomPropertyDropdownPropertiesType
196
+ | CustomPropertyPicklistPropertiesType
197
+ | CustomPropertyFilePropertiesType
198
+ | CustomPropertyDatePropertiesType
199
+ >;
200
+
201
+ export type OrgMetadata = {
202
+ phone_number: string;
203
+ ticket_prefix: string;
204
+ referralSource?: string;
205
+ surveyData?: MicrosurveyData;
206
+ preferences?: OrgPreferences;
207
+ hubspot: {
208
+ hubspot_pipelines?: {
209
+ id: string;
210
+ label: string;
211
+ default_stage: { id: string; label: string };
212
+ }[];
213
+ hubspot_hidden_fields?: string[];
214
+ };
215
+ partition?: boolean;
216
+ tickets: {
217
+ prefix?: string;
218
+ emoji_ticketing: {
219
+ is_enabled?: boolean;
220
+ is_message_enabled?: boolean;
221
+ message_template?: string;
222
+ };
223
+ };
224
+ attribution?: Object;
225
+ affiliate_id?: string;
226
+ custom_properties?: {
227
+ sections?: CustomPropertySectionType[];
228
+ };
229
+ rules?: {
230
+ limit?: number;
231
+ };
232
+ ai?: {
233
+ flag_prompt?: string;
234
+ };
235
+ display_language?: string;
236
+ };
237
+
238
+ export type GroupTemplateType = OverrideProperties<
239
+ Tables<'tbl_group_templates'>,
240
+ {
241
+ group_metadata: {
242
+ messagesAdminsOnly?: boolean;
243
+ infoAdminsOnly?: boolean;
244
+ addMembersAdminsOnly?: boolean;
245
+ description?: string;
246
+ admins?: string[];
247
+ };
248
+ }
249
+ >;
250
+
251
+ type AccessScopes = {
252
+ feature_flags: Record<string, boolean>;
253
+ integrations: boolean;
254
+ rules: boolean;
255
+ exports: boolean;
256
+ };
257
+
258
+ export type OrgMembersType = OverrideProperties<
259
+ Tables<'tbl_org_members'>,
260
+ {
261
+ member_metadata: {
262
+ shift_times: {
263
+ [day in
264
+ | 'monday'
265
+ | 'tuesday'
266
+ | 'wednesday'
267
+ | 'thursday'
268
+ | 'friday'
269
+ | 'saturday'
270
+ | 'sunday']?: [[string, string]];
271
+ };
272
+ override_status: boolean;
273
+ [key: string]: any;
274
+ };
275
+ }
276
+ >;
277
+
278
+ export type OrgType = OverrideProperties<
279
+ Merge<
280
+ Tables<'tbl_org'>,
281
+ {
282
+ user: OrgMembersType;
283
+ members: OrgMembersType[];
284
+ phones: Tables<'tbl_org_phones'>[];
285
+ labels: Tables<'tbl_org_labels'>[];
286
+ quick_replies: Tables<'tbl_quick_replies'>[];
287
+ custom_properties: CustomPropertyType[];
288
+ subscription_status: 'active' | 'inactive' | 'unpaid';
289
+ is_enterprise: boolean;
290
+ is_free_trial: boolean;
291
+ is_hubspot_connected: boolean;
292
+ is_freshdesk_connected: boolean;
293
+ is_zohodesk_connected: boolean;
294
+ access_scopes: AccessScopes;
295
+ rules: Rule[];
296
+ phone_limit: number;
297
+ user_limit: number;
298
+ }
299
+ >,
300
+ {
301
+ org_plan: OrgPlan<AllPlans | Enterprise>;
302
+ stripe_customer_details: _Stripe.Customer | null;
303
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
304
+ stripe_customer_id: _Stripe.Customer['id'] | null;
305
+ org_metadata: OrgMetadata;
306
+ ai_settings: OrgAISettings;
307
+ }
308
+ >;
309
+
310
+ export type ChatMemberType = Merge<
311
+ Tables<'tbl_chat_participants'>,
312
+ Tables<'tbl_contacts'>
313
+ >;
314
+
315
+ export type ChatType = Merge<
316
+ Tables<'view_chats'>,
317
+ {
318
+ chat_id: string;
319
+ latest_message: MessageType | null;
320
+ latest_message_timestamp: number | null;
321
+ members: { [key: string]: ChatMemberType } | null;
322
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
323
+ chat_access: { [key: string]: boolean };
324
+ label_ids: { [key: string]: boolean };
325
+ chat_org_phones?: string[];
326
+ message_unread_count: number | null;
327
+ hubspot_metadata: {
328
+ id: string;
329
+ type: string;
330
+ hubId: string;
331
+ object_data: HubspotObjectDataType;
332
+ } | null;
333
+ info_admins_only: boolean;
334
+ messages_admins_only: boolean;
335
+ unread_count?: { [key: string]: number };
336
+ active_phone: string | null;
337
+ flag_count_map?: { [key: string]: number };
338
+ is_archived?: boolean;
339
+ is_pinned?: boolean;
340
+ closed_at?: number | null;
341
+ common_chats?: string[];
342
+ freshdesk_metadata?: Record<string, any>;
343
+ zohodesk_metadata?: Record<string, any>;
344
+ pinned_messages?: {
345
+ message_id: string;
346
+ pinned_at: number;
347
+ expires_at: number;
348
+ }[];
349
+ group_metadata?: Record<string, any>;
350
+ snooze_metadata?: {
351
+ snooze_until: number;
352
+ snooze_message?: string;
353
+ snooze_by?: string;
354
+ };
355
+ member_unread_count?: {
356
+ [key: string]: number;
357
+ };
358
+ }
359
+ >;
360
+
361
+ /* -------------------------------------------------------------------------- */
362
+ /* MESSAGE */
363
+ /* -------------------------------------------------------------------------- */
364
+
365
+ export type MediaType = {
366
+ path?: string;
367
+ mimetype?: string;
368
+ filename?: string;
369
+ dimensions?: { width: number; height: number; ar: number };
370
+ size?: number;
371
+ thumbnail?: string;
372
+ filedata?: string;
373
+ compress?: boolean;
374
+ };
375
+
376
+ export type MessageType = Merge<
377
+ OverrideProperties<
378
+ TablesInsert<'tbl_chat_messages'>,
379
+ {
380
+ message_id: string;
381
+ org_id: string;
382
+ org_phone: string;
383
+ chat_id: string;
384
+ message_type: (typeof SUPPORTED_TYPES)[number];
385
+ media: MediaType | null;
386
+ flag_metadata?: MessageFlagType | null;
387
+ poll_info?: PollSendType | null;
388
+ poll_results?: PollResultType | null;
389
+ delivery_info?: DeliveryInfoType | null;
390
+ raw_data?: {
391
+ translations?: Record<string, string>;
392
+ [key: string]: unknown;
393
+ } | null;
394
+ }
395
+ >,
396
+ {
397
+ reactions?: ReactionType[];
398
+ message_payload?: SingleMessagePayload;
399
+ highlight?: number;
400
+ is_private_note?: boolean;
401
+ }
402
+ >;
403
+
404
+ export type MessageFlagType = {
405
+ status: boolean;
406
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
407
+ response_id?: string;
408
+ response_timestamp?: string;
409
+ response_email?: string;
410
+ flagged_by?: string;
411
+ flagged_at?: string;
412
+ };
413
+
414
+ export type MessageSendType = {
415
+ queue_id: string;
416
+ queue_position: string;
417
+ };
418
+
419
+ export type MessageBroadcastType = {
420
+ broadcast_id: string;
421
+ };
422
+
423
+ /* -------------------------------------------------------------------------- */
424
+
425
+ export type TicketType = OverrideProperties<
426
+ Tables<'tbl_chat_tickets'>,
427
+ {
428
+ label_ids: { [key: string]: boolean };
429
+ hubspot_metadata: {
430
+ id?: string;
431
+ type?: string;
432
+ hubId?: string;
433
+ pipeline: {
434
+ id: string;
435
+ label: string;
436
+ };
437
+ object_data?: HubspotObjectDataType;
438
+ } | null;
439
+ freshdesk_metadata: Record<string, string>;
440
+ close_ticket_metadata?:
441
+ | {
442
+ closed_by: string;
443
+ closed_at: string;
444
+ closed_message?: string | null;
445
+ send_reply_message_id?: string | null;
446
+ }
447
+ | any;
448
+ }
449
+ >;
450
+
451
+ export type ContactType = Merge<
452
+ Tables<'tbl_contacts'>,
453
+ {
454
+ chats: ChatType[] | null;
455
+ chat_ids?: string[];
456
+ }
457
+ >;
458
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
459
+
460
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
461
+
462
+ export type ChatAccessType = Merge<
463
+ TablesUpdate<'tbl_org_members'>,
464
+ {
465
+ has_access?: boolean;
466
+ email: string | null;
467
+ }
468
+ >;
469
+
470
+ export type QueueJobTypes = {
471
+ addedTimestamp: number;
472
+ attemptsMade: number;
473
+ attemptsStarted: number;
474
+ data: {
475
+ body: string;
476
+ chat_id: string;
477
+ };
478
+ finishedTimestamp: number;
479
+ id: string;
480
+ message_id: string;
481
+ processedTimestamp: number;
482
+ stacktrace: string[];
483
+ status: string;
484
+ };
485
+
486
+ export type PhoneQueueStatusType = {
487
+ active: number;
488
+ failed: number;
489
+ completed: number;
490
+ is_running: boolean;
491
+ pending: number;
492
+ };
493
+
494
+ export type PhoneType = OverrideProperties<
495
+ Tables<'tbl_org_phones'>,
496
+ {
497
+ queue_status: {
498
+ [key: string]: PhoneQueueStatusType;
499
+ };
500
+ }
501
+ >;
502
+
503
+ export type PhoneInfoType = Merge<
504
+ Pick<
505
+ PhoneType,
506
+ | 'created_at'
507
+ | 'first_connected_at'
508
+ | 'is_ready'
509
+ | 'label_ids'
510
+ | 'org_id'
511
+ | 'org_phone'
512
+ | 'phone_id'
513
+ | 'phone_image'
514
+ | 'phone_name'
515
+ | 'qr_code'
516
+ | 'updated_at'
517
+ | 'wa_state'
518
+ >,
519
+ {
520
+ labels: string[];
521
+ }
522
+ >;
523
+
524
+ /* -------------------------------- CONSTANTS ------------------------------- */
525
+
526
+ export const labelColors = [
527
+ '#9333EA',
528
+ '#0D9488',
529
+ '#DB2777',
530
+ '#2563EB',
531
+ '#F97316',
532
+ ];
533
+
534
+ export const enumChatColors = [
535
+ '#B4876E',
536
+ '#A5B337',
537
+ '#06CF9C',
538
+ '#25D366',
539
+ '#02A698',
540
+ '#7D9EF1',
541
+ '#007BFC',
542
+ '#5E47DE',
543
+ '#7F66FF',
544
+ '#9333EA',
545
+ '#FA6533',
546
+ '#C4532D',
547
+ '#DC2626',
548
+ '#FF2E74',
549
+ '#DB2777',
550
+ ] as const;
551
+
552
+ export type RepeatDaysType =
553
+ | 'monday'
554
+ | 'tuesday'
555
+ | 'wednesday'
556
+ | 'thursday'
557
+ | 'friday'
558
+ | 'saturday'
559
+ | 'sunday';
560
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
561
+
562
+ export enum WhatsappGroupActionEnum {
563
+ ADD = 'add',
564
+ REMOVE = 'remove',
565
+ PROMOTE = 'promote',
566
+ DEMOTE = 'demote',
567
+ INVITE = 'invite',
568
+ LEAVE = 'leave',
569
+ ANNOUNCE_TRUE = 'announce_true',
570
+ ANNOUNCE_FALSE = 'announce_false',
571
+ RESTRICT_TRUE = 'restrict_true',
572
+ RESTRICT_FALSE = 'restrict_false',
573
+ MEMBERADDMODE_TRUE = 'memberaddmode_true',
574
+ MEMBERADDMODE_FALSE = 'memberaddmode_false',
575
+ SUBJECT = 'subject',
576
+ DESC = 'desc',
577
+ CALL = 'call',
578
+ }
579
+
580
+ /* -------------------------- LISTING ENDPOINT -------------------------- */
581
+
582
+ type ListingType = {
583
+ from?: number;
584
+ to?: number;
585
+ count?: number;
586
+ };
587
+
588
+ export type ListNotificationsType = Merge<
589
+ ListingType,
590
+ {
591
+ notifictions?: NotificationType[];
592
+ }
593
+ >;
594
+
595
+ export type ListChatMessagesType = Merge<
596
+ ListingType,
597
+ {
598
+ messages?: MessageType[];
599
+ }
600
+ >;
601
+
602
+ export type ListContactsType = Merge<
603
+ ListingType,
604
+ {
605
+ contacts?: ContactType[];
606
+ }
607
+ >;
608
+
609
+ export type ListTicketsType = Merge<
610
+ ListingType,
611
+ {
612
+ tickets?: TicketType[];
613
+ }
614
+ >;
615
+
616
+ export type ListChatsType = Merge<
617
+ ListingType,
618
+ {
619
+ chats?: ChatType[];
620
+ }
621
+ >;
622
+
623
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
624
+
625
+ export const SUPPORTED_TYPES = [
626
+ 'chat',
627
+ 'sticker',
628
+ 'image',
629
+ 'video',
630
+ 'document',
631
+ 'vcard',
632
+ 'multi_vcard',
633
+ 'audio',
634
+ 'ptt',
635
+ 'poll_creation',
636
+ 'location',
637
+ 'ciphertext',
638
+ ] as const;
639
+
640
+ export type SendMessageContent = {
641
+ message_type?: (typeof SUPPORTED_TYPES)[number];
642
+ body?: string;
643
+ media?: MediaType;
644
+ contact_ids?: string[];
645
+ location?: {
646
+ latitude: string;
647
+ longitude: string;
648
+ options?: { name?: string; address?: string; url?: string };
649
+ };
650
+ poll?: PollSendType;
651
+ quoted_message_id?: string;
652
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
653
+ broadcast_id?: string;
654
+ performed_by?: string;
655
+ options?: Record<string, any>;
656
+ };
657
+
658
+ export type QuickReplyContent = Omit<
659
+ SendMessageContent,
660
+ 'broadcast_id' | 'variables'
661
+ >;
662
+
663
+ export type ScheduleMessagePayload = {
664
+ scheduled_id?: string;
665
+ is_repeat?: boolean | null;
666
+ scheduled_at: string;
667
+ repeat_config?: {
668
+ timezone?: string;
669
+ repeat_ends?: string;
670
+ repeat_interval?: RepeatIntervalType;
671
+ repeat_value?: number;
672
+ repeat_days?: RepeatDaysType[];
673
+ };
674
+ };
675
+
676
+ export type BroadcastVariableType = {
677
+ chat_id: string;
678
+ values: { [key: string]: string };
679
+ };
680
+
681
+ export type BroadcastMessagePayload = SendMessageContent & {
682
+ chat_ids: string[];
683
+ broadcast_id?: string;
684
+ variables?: BroadcastVariableType[];
685
+ delay?: number;
686
+ };
687
+
688
+ export type SingleMessagePayload = SendMessageContent & {
689
+ chat_id: string;
690
+ job_id?: string;
691
+ priority?: number;
692
+ };
693
+
694
+ export type MessageAttachmentFileTypes =
695
+ | 'image'
696
+ | 'audio'
697
+ | 'document'
698
+ | 'video';
699
+
700
+ export type AttachmentFileType = {
701
+ result: string;
702
+ file: File | null;
703
+ type: MessageAttachmentFileTypes;
704
+ localFileURL?: string;
705
+ };
706
+
707
+ export type AttachmentLinkType = {
708
+ link: {
709
+ url: string;
710
+ type: MessageAttachmentFileTypes;
711
+ name: string;
712
+ mimetype?: string;
713
+ };
714
+ };
715
+
716
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
717
+
718
+ /* -------------------------------- BROADCAST ------------------------------- */
719
+
720
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
721
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
722
+ } & {
723
+ chats: ChatType[];
724
+ };
725
+
726
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
727
+
728
+ export type ChatLogType = {
729
+ log: Tables<'view_chat_logs'>;
730
+ operations: Tables<'tbl_chat_logs'>[];
731
+ };
732
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
733
+
734
+ export type ChatParticipantOperationPayload = {
735
+ participant_ids: string[];
736
+ chat_ids: string[];
737
+ performed_by: string;
738
+ force_add_participants?: boolean;
739
+ };
740
+
741
+ export type ChatOperationReturn = {
742
+ [participant_id: string]: {
743
+ is_success: boolean;
744
+ message?: string;
745
+ code?: number;
746
+ isInviteV4Sent?: boolean;
747
+ };
748
+ };
749
+
750
+ /* ----------------------- BILLING - STRIPE ----------------------- */
751
+
752
+ export type StripeSubscription = _Stripe.Subscription;
753
+ export type StripeCustomer = _Stripe.Customer;
754
+ export type StripeCoupon = _Stripe.Coupon;
755
+ export type StripePrice = _Stripe.Price;
756
+ export type Stripe = _Stripe;
757
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
758
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
759
+
760
+ /* -------------------------------- REALTIME -------------------------------- */
761
+
762
+ export type PhoneStateType = {
763
+ loading: boolean;
764
+ state: string;
765
+ sync: number;
766
+ percent: number | null;
767
+ message?: string;
768
+ error?: string;
769
+ };
770
+
771
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
772
+
773
+ export type ChatInfoType = Merge<
774
+ ChatType,
775
+ {
776
+ members: {
777
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
778
+ } | null;
779
+ chat_labels: string | null;
780
+ custom_properties: { [key: string]: string } | null;
781
+ }
782
+ >;
783
+
784
+ export type TicketInfoType = {
785
+ chat: ChatInfoType;
786
+ message: {
787
+ body: string;
788
+ chat_id: string;
789
+ org_phone: string;
790
+ timestamp: string;
791
+ media_path: string;
792
+ message_id: string;
793
+ sender_name: string;
794
+ performed_by: string;
795
+ sender_phone: string;
796
+ };
797
+ ticket: {
798
+ org_id: string;
799
+ status: string;
800
+ subject: string;
801
+ assignee: string;
802
+ due_date: string;
803
+ priority: 0 | 1 | 2 | 3 | 4;
804
+ raised_by: string;
805
+ ticket_id: string;
806
+ created_at: string;
807
+ assigned_by: string;
808
+ ticket_labels: string;
809
+ quoted_message_id: string;
810
+ ticket_custom_properties: { [key: string]: string } | null;
811
+ closed_at: string;
812
+ closed_by: string;
813
+ closed_message: string;
814
+ first_assigned_at: string | null;
815
+ };
816
+ attached_messages: {
817
+ body: string;
818
+ chat_id: string;
819
+ org_phone: string;
820
+ timestamp: string;
821
+ media_path: string;
822
+ message_id: string;
823
+ sender_name: string;
824
+ performed_by: string;
825
+ sender_phone: string;
826
+ }[];
827
+ };
828
+
829
+ export type IntegrationLogObjectType =
830
+ | 'chat'
831
+ | 'message'
832
+ | 'reaction'
833
+ | 'ticket'
834
+ | 'phone';
835
+ export enum IntegrationLogType {
836
+ NEW_CHAT = 'chat.created',
837
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
838
+ NEW_MESSAGE = 'message.created',
839
+ MESSAGE_UPDATED = 'message.updated',
840
+ MESSAGE_DELETED = 'message.deleted',
841
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
842
+ MESSAGE_FLAGGED = 'message.flagged',
843
+ MESSAGE_UNFLAGGED = 'message.unflagged',
844
+ MESSAGE_TICKET_ATTACHED = 'message.ticket.attached',
845
+ REACTION_CREATED = 'reaction.created',
846
+ REACTION_UPDATED = 'reaction.updated',
847
+ NEW_TICKET = 'ticket.created',
848
+ TICKET_UPDATED = 'ticket.updated',
849
+ TICKET_DELETED = 'ticket.deleted',
850
+ PHONE_DISCONNECTED = 'org.phone.disconnected',
851
+ PHONE_CONNECTED = 'org.phone.connected',
852
+ PHONE_UPDATED = 'org.phone.updated',
853
+ PHONE_QR_UPDATED = 'org.phone.qr',
854
+ }
855
+
856
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
857
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
858
+ ? TicketInfoType
859
+ : T extends IntegrationLogType.NEW_CHAT
860
+ ? Tables<'tbl_chats'>
861
+ : T extends
862
+ | IntegrationLogType.NEW_MESSAGE
863
+ | IntegrationLogType.MESSAGE_UPDATED
864
+ | IntegrationLogType.MESSAGE_DELETED
865
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
866
+ | IntegrationLogType.MESSAGE_FLAGGED
867
+ | IntegrationLogType.MESSAGE_UNFLAGGED
868
+ | IntegrationLogType.MESSAGE_TICKET_ATTACHED
869
+ ? Tables<'tbl_chat_messages'>
870
+ : T extends
871
+ | IntegrationLogType.REACTION_CREATED
872
+ | IntegrationLogType.REACTION_UPDATED
873
+ ? Tables<'tbl_chat_reactions'>
874
+ : T extends
875
+ | IntegrationLogType.PHONE_DISCONNECTED
876
+ | IntegrationLogType.PHONE_CONNECTED
877
+ | IntegrationLogType.PHONE_UPDATED
878
+ | IntegrationLogType.PHONE_QR_UPDATED
879
+ ? Tables<'tbl_org_phones'>
880
+ : {
881
+ [key: string]: unknown;
882
+ };
883
+
884
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
885
+ OverrideProperties<
886
+ Tables<'tbl_integration_logs'>,
887
+ {
888
+ integration_name: T;
889
+ metadata: {
890
+ event: IntegrationLogMetadataType<T> & {
891
+ event_type: string;
892
+ org_id: string;
893
+ previous_attributes: {
894
+ [key: string]: unknown;
895
+ };
896
+ };
897
+ hook_id: string;
898
+ name: string;
899
+ };
900
+ }
901
+ >;
902
+
903
+ export type APIAuthDetails = {
904
+ org_details: Tables<'view_org'> | null;
905
+ phone_details: Tables<'tbl_org_phones'> | null;
906
+ token_details: Tables<'tbl_integration_tokens'> | null;
907
+ };
908
+
909
+ export type WebhookDataType = OverrideProperties<
910
+ Tables<'tbl_integration_hooks'>,
911
+ {
912
+ integration_name: string[];
913
+ }
914
+ >;
915
+
916
+ export type HubspotObjectDataType = {
917
+ createdAt: string;
918
+ archived: boolean;
919
+ id: string;
920
+ type: 'contacts' | 'tickets' | 'companies';
921
+ properties: Record<
922
+ string,
923
+ {
924
+ groupLabel: string;
925
+ groupName: string;
926
+ propertyKeyName: string;
927
+ propertyKey: string;
928
+ propertyInternalValue: string;
929
+ propertyValue: string;
930
+ propertyType: string;
931
+ propertyFieldType: string;
932
+ }[]
933
+ >;
934
+ };
935
+
936
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
937
+
938
+ export type UserPreferences = {
939
+ theme: 'light' | 'dark';
940
+ language: 'en' | 'es';
941
+ left_sidebar_open: boolean;
942
+ right_sidepanel_open: boolean;
943
+ sync_wa_unread_count: boolean;
944
+ pinned_chats: string[];
945
+ archived_chats: string[];
946
+ closed_chats: Record<string, number>;
947
+ periskope_chat_limit: number;
948
+ notifications: Record<string, boolean>;
949
+ };
950
+
951
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
952
+
953
+ export interface MostActiveMember {
954
+ sender_phone: string;
955
+ total_messages: number;
956
+ }
957
+
958
+ export interface GroupAnalyticsResult {
959
+ total_messages: number;
960
+ total_joins: number;
961
+ total_leaves: number;
962
+ total_removes: number;
963
+ total_reactions: number;
964
+ most_active_members: MostActiveMember[];
965
+ }
966
+
967
+ export interface TimeRange {
968
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
969
+ endDateTime: string;
970
+ }
971
+
972
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
973
+
974
+ export type PollSendType = {
975
+ pollName: string;
976
+ pollOptions: string[];
977
+ options?: {
978
+ allowMultipleAnswers?: boolean;
979
+ messageSecret?: number[] | null;
980
+ pollId?: string;
981
+ };
982
+ };
983
+
984
+ export type PollResultType = {
985
+ [name: string]: Record<string, string>;
986
+ };
987
+
988
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
989
+
990
+ export type CreateGroupOptions = {
991
+ messagesAdminsOnly?: boolean;
992
+ infoAdminsOnly?: boolean;
993
+ addMembersAdminsOnly?: boolean;
994
+ image?: string;
995
+ name?: string;
996
+ description?: string;
997
+ initiated_by?: string;
998
+ admins?: string[];
999
+ force_add_participants?: boolean;
1000
+ };
1001
+
1002
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
1003
+
1004
+ export type DeliveryInfoType = {
1005
+ delivered: Record<string, number | undefined>;
1006
+ read: Record<string, number | undefined>;
1007
+ pending: string[];
1008
+ read_count: number;
1009
+ delivered_count: number;
1010
+ };
1011
+
1012
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1013
+
1014
+ export type OrgCreditsType = {
1015
+ org_id: string;
1016
+ recurring_allowance: number; // recurring credits replenished every cycle
1017
+ recurring_balance: number; // recurring credits remaining in current cycle
1018
+ topup_balance: number; // topup credits remaining
1019
+ total_credits_used: number; // total credits used in current cycle
1020
+ next_renewal_date: string;
1021
+ topup_credits_used: number; // topup credits used in current cycle
1022
+ recurring_credits_used: number; // recurring credits used in current cycle
1023
+ };
1024
+
1025
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
1026
+
1027
+ export type ChatRuleInfoType = Merge<
1028
+ Pick<
1029
+ Tables<'view_chats'>,
1030
+ | 'assigned_to'
1031
+ | 'chat_id'
1032
+ | 'chat_name'
1033
+ | 'chat_type'
1034
+ | 'created_at'
1035
+ | 'group_description'
1036
+ | 'info_admins_only'
1037
+ | 'org_id'
1038
+ | 'org_phone'
1039
+ | 'chat_org_phones'
1040
+ | 'messages_admins_only'
1041
+ | 'custom_properties'
1042
+ | 'initiated_by'
1043
+ >,
1044
+ {
1045
+ has_flagged_messages: boolean;
1046
+ labels: string[];
1047
+ members: string[];
1048
+ custom_properties: { [key: string]: string } | null;
1049
+ }
1050
+ >;
1051
+
1052
+ export type SenderRuleInfoType = Merge<
1053
+ Omit<
1054
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1055
+ | 'verified_name'
1056
+ | 'verified_level'
1057
+ | 'updated_at'
1058
+ | 'short_name'
1059
+ | 'pushname'
1060
+ | 'periskope_name'
1061
+ | 'org_phone'
1062
+ | 'number'
1063
+ | 'name'
1064
+ | 'label_ids'
1065
+ | 'is_wa_contact'
1066
+ | 'is_user'
1067
+ | 'is_my_contact'
1068
+ | 'is_me'
1069
+ | 'is_imported'
1070
+ | 'is_group'
1071
+ | 'is_blocked'
1072
+ | 'contact_color'
1073
+ | 'business_profile'
1074
+ | 'id'
1075
+ | 'contact_image'
1076
+ | 'contact_type'
1077
+ | 'chat_id'
1078
+ | 'is_business'
1079
+ | 'is_enterprise'
1080
+ | 'is_super_admin'
1081
+ | 'contact_lid'
1082
+ >,
1083
+ {
1084
+ is_internal: boolean;
1085
+ labels: string[] | null;
1086
+ }
1087
+ >;
1088
+
1089
+ export type MessageRuleInfoType = {
1090
+ chat: ChatRuleInfoType;
1091
+ sender: SenderRuleInfoType;
1092
+ message: OverrideProperties<
1093
+ Omit<
1094
+ Tables<'tbl_chat_messages'>,
1095
+ | 'vcards'
1096
+ | 'updated_at'
1097
+ | 'unique_id'
1098
+ | 'token'
1099
+ | 'to'
1100
+ | 'sent_message_id'
1101
+ | 'raw_data'
1102
+ | 'delivery_info'
1103
+ | 'poll_results'
1104
+ | 'poll_info'
1105
+ | 'order_id'
1106
+ | 'mentioned_ids'
1107
+ | 'media_key'
1108
+ | 'location'
1109
+ | 'links'
1110
+ | 'is_status'
1111
+ | 'is_starred'
1112
+ | 'is_gif'
1113
+ | 'is_forwarded'
1114
+ | 'is_ephemeral'
1115
+ | 'is_deleted'
1116
+ | 'fts'
1117
+ | 'quoted_message_id'
1118
+ | 'invite_v4'
1119
+ | 'id'
1120
+ | 'has_reaction'
1121
+ | 'has_media'
1122
+ | 'duration'
1123
+ | 'broadcast'
1124
+ | 'broadcast_id'
1125
+ | 'device_type'
1126
+ | 'forwarding_score'
1127
+ | 'from'
1128
+ | 'from_me'
1129
+ | 'prev_body'
1130
+ | 'flag_response_time'
1131
+ | 'flag_metadata'
1132
+ | 'ack'
1133
+ >,
1134
+ {
1135
+ media: MediaType | null;
1136
+ }
1137
+ >;
1138
+ };
1139
+
1140
+ export type ReactionRuleInfoType = {
1141
+ chat: ChatRuleInfoType;
1142
+ sender: SenderRuleInfoType;
1143
+ message: MessageRuleInfoType['message'];
1144
+ reaction: Pick<
1145
+ Tables<'tbl_chat_reactions'>,
1146
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1147
+ >;
1148
+ };
1149
+
1150
+ export type TicketRuleInfoType = {
1151
+ chat: ChatRuleInfoType;
1152
+ sender: SenderRuleInfoType;
1153
+ ticket: Merge<
1154
+ Pick<
1155
+ Tables<'tbl_chat_tickets'>,
1156
+ | 'org_id'
1157
+ | 'status'
1158
+ | 'chat_id'
1159
+ | 'subject'
1160
+ | 'assignee'
1161
+ | 'due_date'
1162
+ | 'priority'
1163
+ | 'raised_by'
1164
+ | 'ticket_id'
1165
+ | 'created_at'
1166
+ | 'is_deleted'
1167
+ >,
1168
+ {
1169
+ labels: string[] | null;
1170
+ custom_properties: { [key: string]: string } | null;
1171
+ }
1172
+ >;
1173
+ message: MessageRuleInfoType['message'];
1174
+ };
1175
+ export type FeatureFlagReturnType = Record<string, boolean>;
1176
+
1177
+ export type RuleLogsType = OverrideProperties<
1178
+ Tables<'tbl_rules_logs'>,
1179
+ {
1180
+ actions_progress: {
1181
+ action_id: string;
1182
+ action_type: Rule['actions'][number]['type'];
1183
+ action_delay: Rule['actions'][number]['delay'];
1184
+ ran_at: string | null;
1185
+ action_status: 'success' | 'failed' | 'pending';
1186
+ action_response: {
1187
+ success: boolean;
1188
+ data: Record<string, unknown> | null;
1189
+ error: {
1190
+ message: string;
1191
+ name: string;
1192
+ stack?: string;
1193
+ _error?: Error | Record<string, unknown>;
1194
+ } | null;
1195
+ };
1196
+ }[];
1197
+ metadata: {
1198
+ conditions: Rule['conditions'];
1199
+ actions: Rule['actions'];
1200
+ rule_metadata: Pick<
1201
+ Rule,
1202
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1203
+ >;
1204
+ data: Record<string, unknown>;
1205
+ };
1206
+ conditions_progress: {
1207
+ is_valid: boolean;
1208
+ validation_progress: Record<
1209
+ string,
1210
+ {
1211
+ res: boolean;
1212
+ filter: Filter;
1213
+ value: unknown;
1214
+ }
1215
+ >;
1216
+ checked_at: string | null;
1217
+ };
1218
+ }
1219
+ >;
1220
+
1221
+ /************************** TASKS ***************************/
1222
+
1223
+ export type TaskType = OverrideProperties<
1224
+ Tables<'tbl_org_tasks'>,
1225
+ {
1226
+ reminder_setting: {
1227
+ remind_in:
1228
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1229
+ | string
1230
+ | null;
1231
+ repeat?: {
1232
+ frequency: number;
1233
+ interval: 'days' | 'weeks' | 'months' | 'years';
1234
+ end: 'never' | 'after' | 'on';
1235
+ on?: string;
1236
+ };
1237
+ } | null;
1238
+ associated_object_metadata:
1239
+ | {
1240
+ type: 'chat';
1241
+ index: 'chat_id';
1242
+ id: string;
1243
+ object: ChatType;
1244
+ }
1245
+ | {
1246
+ type: 'message';
1247
+ index: 'message_id';
1248
+ id: string;
1249
+ object: MessageType;
1250
+ }
1251
+ | {
1252
+ type: 'ticket';
1253
+ index: 'ticket_id';
1254
+ id: string;
1255
+ object: TicketType;
1256
+ }
1257
+ | null;
1258
+ status: 'open' | 'inprogress' | 'closed';
1259
+ priority: 1 | 2 | 3;
1260
+ completed_metadata?: {
1261
+ completed_at: string;
1262
+ completed_by: string;
1263
+ } | null;
1264
+ type: 'todo' | 'chat' | 'message' | 'ticket';
1265
+ }
1266
+ >;
1267
+
1268
+ type Choice = {
1269
+ id: number;
1270
+ label: string;
1271
+ value: string;
1272
+ position: number;
1273
+ };
1274
+
1275
+ export type FreshdeskCustomFieldType = {
1276
+ id: number;
1277
+ name: string;
1278
+ label: string;
1279
+ position: number;
1280
+ required_for_agents: boolean;
1281
+ archived: boolean;
1282
+ customers_can_edit: boolean;
1283
+ label_for_customers: string;
1284
+ required_for_customers: boolean;
1285
+ customers_can_filter: boolean;
1286
+ required_for_closure: boolean;
1287
+ displayed_to_customers: boolean;
1288
+ type: string;
1289
+ default: boolean;
1290
+ created_at: string;
1291
+ updated_at: string;
1292
+ choices?: Choice[];
1293
+ };
1294
+
1295
+ export type OrgWarmup = OverrideProperties<Tables<{ schema: 'internal' }, 'tbl_org_warmup'>, {
1296
+ warmup_chats: {[key: string]: string};
1297
+ }>