@periskope/types 0.6.260 → 0.6.261

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