@periskope/types 0.6.270 → 0.6.271

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,1241 +1,1241 @@
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
- group_metadata?: Record<string, any>;
325
- snooze_metadata?: {
326
- snooze_until: number;
327
- snooze_message?: string;
328
- snooze_by?: string;
329
- },
330
- member_unread_count?: {
331
- [key: string]: number;
332
- };
333
- }
334
- >;
335
-
336
- /* -------------------------------------------------------------------------- */
337
- /* MESSAGE */
338
- /* -------------------------------------------------------------------------- */
339
-
340
- export type MediaType = {
341
- path?: string;
342
- mimetype?: string;
343
- filename?: string;
344
- dimensions?: { width: number; height: number; ar: number };
345
- size?: number;
346
- thumbnail?: string;
347
- filedata?: string;
348
- compress?: boolean;
349
- };
350
-
351
- export type MessageType = Merge<
352
- OverrideProperties<
353
- TablesInsert<'tbl_chat_messages'>,
354
- {
355
- message_id: string;
356
- org_id: string;
357
- org_phone: string;
358
- chat_id: string;
359
- message_type: (typeof SUPPORTED_TYPES)[number];
360
- media: MediaType | null;
361
- flag_metadata?: MessageFlagType | null;
362
- poll_info?: PollSendType | null;
363
- poll_results?: PollResultType | null;
364
- delivery_info?: DeliveryInfoType | null;
365
- raw_data?: {
366
- translations?: Record<string, string>;
367
- [key: string]: unknown;
368
- } | null;
369
- }
370
- >,
371
- {
372
- reactions?: ReactionType[];
373
- message_payload?: SingleMessagePayload;
374
- highlight?: number;
375
- is_private_note?: boolean;
376
- }
377
- >;
378
-
379
- export type MessageFlagType = {
380
- status: boolean;
381
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
382
- response_id?: string;
383
- response_timestamp?: string;
384
- response_email?: string;
385
- flagged_by?: string;
386
- flagged_at?: string;
387
- };
388
-
389
- export type MessageSendType = {
390
- queue_id: string;
391
- queue_position: string;
392
- };
393
-
394
- export type MessageBroadcastType = {
395
- broadcast_id: string;
396
- };
397
-
398
- /* -------------------------------------------------------------------------- */
399
-
400
- export type TicketType = OverrideProperties<
401
- Tables<'tbl_chat_tickets'>,
402
- {
403
- label_ids: { [key: string]: boolean };
404
- hubspot_metadata: {
405
- id?: string;
406
- type?: string;
407
- hubId?: string;
408
- pipeline: {
409
- id: string;
410
- label: string;
411
- };
412
- object_data?: HubspotObjectDataType;
413
- } | null;
414
- freshdesk_metadata: Record<string, string>;
415
- close_ticket_metadata?:
416
- | {
417
- closed_by: string;
418
- closed_at: string;
419
- closed_message?: string | null;
420
- send_reply_message_id?: string | null;
421
- }
422
- | any;
423
- }
424
- >;
425
-
426
- export type ContactType = Merge<
427
- Tables<'tbl_contacts'>,
428
- {
429
- chats: ChatType[] | null;
430
- chat_ids?: string[];
431
- }
432
- >;
433
- export type ReactionType = Tables<'tbl_chat_reactions'>;
434
-
435
- export type NotificationType = Tables<'tbl_chat_notifications'>;
436
-
437
- export type ChatAccessType = Merge<
438
- TablesUpdate<'tbl_org_members'>,
439
- {
440
- has_access?: boolean;
441
- email: string | null;
442
- }
443
- >;
444
-
445
- export type QueueJobTypes = {
446
- addedTimestamp: number;
447
- attemptsMade: number;
448
- attemptsStarted: number;
449
- data: {
450
- body: string;
451
- chat_id: string;
452
- };
453
- finishedTimestamp: number;
454
- id: string;
455
- message_id: string;
456
- processedTimestamp: number;
457
- stacktrace: string[];
458
- status: string;
459
- };
460
-
461
- export type PhoneQueueStatusType = {
462
- active: number;
463
- failed: number;
464
- completed: number;
465
- is_running: boolean;
466
- pending: number;
467
- };
468
-
469
- export type PhoneType = OverrideProperties<
470
- Tables<'tbl_org_phones'>,
471
- {
472
- queue_status: {
473
- [key: string]: PhoneQueueStatusType;
474
- };
475
- }
476
- >;
477
-
478
- export type PhoneInfoType = Merge<
479
- Pick<
480
- PhoneType,
481
- | 'created_at'
482
- | 'first_connected_at'
483
- | 'is_ready'
484
- | 'label_ids'
485
- | 'org_id'
486
- | 'org_phone'
487
- | 'phone_id'
488
- | 'phone_image'
489
- | 'phone_name'
490
- | 'qr_code'
491
- | 'updated_at'
492
- | 'wa_state'
493
- >,
494
- {
495
- labels: string[];
496
- }
497
- >;
498
-
499
- /* -------------------------------- CONSTANTS ------------------------------- */
500
-
501
- export const labelColors = [
502
- '#9333EA',
503
- '#0D9488',
504
- '#DB2777',
505
- '#2563EB',
506
- '#F97316',
507
- ];
508
-
509
- export const enumChatColors = [
510
- '#B4876E',
511
- '#A5B337',
512
- '#06CF9C',
513
- '#25D366',
514
- '#02A698',
515
- '#7D9EF1',
516
- '#007BFC',
517
- '#5E47DE',
518
- '#7F66FF',
519
- '#9333EA',
520
- '#FA6533',
521
- '#C4532D',
522
- '#DC2626',
523
- '#FF2E74',
524
- '#DB2777',
525
- ] as const;
526
-
527
- export type RepeatDaysType =
528
- | 'monday'
529
- | 'tuesday'
530
- | 'wednesday'
531
- | 'thursday'
532
- | 'friday'
533
- | 'saturday'
534
- | 'sunday';
535
- export type RepeatIntervalType = 'day' | 'week' | 'month';
536
-
537
- /* -------------------------- LISTING ENDPOINT -------------------------- */
538
-
539
- type ListingType = {
540
- from?: number;
541
- to?: number;
542
- count?: number;
543
- };
544
-
545
- export type ListNotificationsType = Merge<
546
- ListingType,
547
- {
548
- notifictions?: NotificationType[];
549
- }
550
- >;
551
-
552
- export type ListChatMessagesType = Merge<
553
- ListingType,
554
- {
555
- messages?: MessageType[];
556
- }
557
- >;
558
-
559
- export type ListContactsType = Merge<
560
- ListingType,
561
- {
562
- contacts?: ContactType[];
563
- }
564
- >;
565
-
566
- export type ListTicketsType = Merge<
567
- ListingType,
568
- {
569
- tickets?: TicketType[];
570
- }
571
- >;
572
-
573
- export type ListChatsType = Merge<
574
- ListingType,
575
- {
576
- chats?: ChatType[];
577
- }
578
- >;
579
-
580
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
581
-
582
- export const SUPPORTED_TYPES = [
583
- 'chat',
584
- 'sticker',
585
- 'image',
586
- 'video',
587
- 'document',
588
- 'vcard',
589
- 'multi_vcard',
590
- 'audio',
591
- 'ptt',
592
- 'poll_creation',
593
- 'location',
594
- 'ciphertext',
595
- ] as const;
596
-
597
- export type SendMessageContent = {
598
- message_type?: (typeof SUPPORTED_TYPES)[number];
599
- body?: string;
600
- media?: MediaType;
601
- contact_ids?: string[];
602
- location?: {
603
- latitude: string;
604
- longitude: string;
605
- options?: { name?: string; address?: string; url?: string };
606
- };
607
- poll?: PollSendType;
608
- quoted_message_id?: string;
609
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
610
- broadcast_id?: string;
611
- performed_by?: string;
612
- options?: Record<string, any>;
613
- };
614
-
615
- export type QuickReplyContent = Omit<
616
- SendMessageContent,
617
- 'broadcast_id' | 'variables'
618
- >;
619
-
620
- export type ScheduleMessagePayload = {
621
- scheduled_id?: string;
622
- is_repeat?: boolean | null;
623
- scheduled_at: string;
624
- repeat_config?: {
625
- timezone?: string;
626
- repeat_ends?: string;
627
- repeat_interval?: RepeatIntervalType;
628
- repeat_value?: number;
629
- repeat_days?: RepeatDaysType[];
630
- };
631
- };
632
-
633
- export type BroadcastVariableType = {
634
- chat_id: string;
635
- values: { [key: string]: string };
636
- };
637
-
638
- export type BroadcastMessagePayload = SendMessageContent & {
639
- chat_ids: string[];
640
- broadcast_id?: string;
641
- variables?: BroadcastVariableType[];
642
- delay?: number;
643
- };
644
-
645
- export type SingleMessagePayload = SendMessageContent & {
646
- chat_id: string;
647
- job_id?: string;
648
- priority?: number;
649
- };
650
-
651
- export type MessageAttachmentFileTypes =
652
- | 'image'
653
- | 'audio'
654
- | 'document'
655
- | 'video';
656
-
657
- export type AttachmentFileType = {
658
- result: string;
659
- file: File | null;
660
- type: MessageAttachmentFileTypes;
661
- localFileURL?: string;
662
- };
663
-
664
- export type AttachmentLinkType = {
665
- link: {
666
- url: string;
667
- type: MessageAttachmentFileTypes;
668
- name: string;
669
- mimetype?: string;
670
- };
671
- };
672
-
673
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
674
-
675
- /* -------------------------------- BROADCAST ------------------------------- */
676
-
677
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
678
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
679
- } & {
680
- chats: ChatType[];
681
- };
682
-
683
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
684
-
685
- export type ChatLogType = {
686
- log: Tables<'view_chat_logs'>;
687
- operations: Tables<'tbl_chat_logs'>[];
688
- };
689
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
690
-
691
- export type ChatParticipantOperationPayload = {
692
- participant_ids: string[];
693
- chat_ids: string[];
694
- performed_by: string;
695
- };
696
-
697
- export type ChatOperationReturn = {
698
- [participant_id: string]: {
699
- is_success: boolean;
700
- message?: string;
701
- code?: number;
702
- isInviteV4Sent?: boolean;
703
- };
704
- };
705
-
706
- /* ----------------------- BILLING - STRIPE ----------------------- */
707
-
708
- export type StripeSubscription = _Stripe.Subscription;
709
- export type StripeCustomer = _Stripe.Customer;
710
- export type StripeCoupon = _Stripe.Coupon;
711
- export type StripePrice = _Stripe.Price;
712
- export type Stripe = _Stripe;
713
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
714
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
715
-
716
- /* -------------------------------- REALTIME -------------------------------- */
717
-
718
- export type PhoneStateType = {
719
- loading: boolean;
720
- state: string;
721
- sync: number;
722
- percent: number | null;
723
- message?: string;
724
- error?: string;
725
- };
726
-
727
- /* ------------------------------- INTEGRATIONS ----------------------------- */
728
-
729
- export type ChatInfoType = Merge<
730
- ChatType,
731
- {
732
- members: {
733
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
734
- } | null;
735
- chat_labels: string | null;
736
- custom_properties: { [key: string]: string } | null;
737
- }
738
- >;
739
-
740
- export type TicketInfoType = {
741
- chat: ChatInfoType;
742
- message: {
743
- body: string;
744
- chat_id: string;
745
- org_phone: string;
746
- timestamp: string;
747
- media_path: string;
748
- message_id: string;
749
- sender_name: string;
750
- performed_by: string;
751
- sender_phone: string;
752
- };
753
- ticket: {
754
- org_id: string;
755
- status: string;
756
- subject: string;
757
- assignee: string;
758
- due_date: string;
759
- priority: 0 | 1 | 2 | 3 | 4;
760
- raised_by: string;
761
- ticket_id: string;
762
- created_at: string;
763
- assigned_by: string;
764
- ticket_labels: string;
765
- quoted_message_id: string;
766
- ticket_custom_properties: { [key: string]: string } | null;
767
- };
768
- attached_messages: {
769
- body: string;
770
- chat_id: string;
771
- org_phone: string;
772
- timestamp: string;
773
- media_path: string;
774
- message_id: string;
775
- sender_name: string;
776
- performed_by: string;
777
- sender_phone: string;
778
- }[];
779
- };
780
-
781
- export type IntegrationLogObjectType =
782
- | 'chat'
783
- | 'message'
784
- | 'reaction'
785
- | 'ticket'
786
- | 'phone';
787
- export enum IntegrationLogType {
788
- NEW_CHAT = 'chat.created',
789
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
790
- NEW_MESSAGE = 'message.created',
791
- MESSAGE_UPDATED = 'message.updated',
792
- MESSAGE_DELETED = 'message.deleted',
793
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
794
- REACTION_CREATED = 'reaction.created',
795
- REACTION_UPDATED = 'reaction.updated',
796
- NEW_TICKET = 'ticket.created',
797
- TICKET_UPDATED = 'ticket.updated',
798
- TICKET_DELETED = 'ticket.deleted',
799
- MESSAGE_FLAGGED = 'message.flagged',
800
- MESSAGE_UNFLAGGED = 'message.unflagged',
801
- PHONE_DISCONNECTED = 'org.phone.disconnected',
802
- PHONE_CONNECTED = 'org.phone.connected',
803
- PHONE_UPDATED = 'org.phone.updated',
804
- PHONE_QR_UPDATED = 'org.phone.qr',
805
- }
806
-
807
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
808
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
809
- ? TicketInfoType
810
- : T extends IntegrationLogType.NEW_CHAT
811
- ? Tables<'tbl_chats'>
812
- : T extends
813
- | IntegrationLogType.NEW_MESSAGE
814
- | IntegrationLogType.MESSAGE_UPDATED
815
- | IntegrationLogType.MESSAGE_DELETED
816
- | IntegrationLogType.MESSAGE_ACK_UPDATED
817
- | IntegrationLogType.MESSAGE_FLAGGED
818
- | IntegrationLogType.MESSAGE_UNFLAGGED
819
- ? Tables<'tbl_chat_messages'>
820
- : T extends
821
- | IntegrationLogType.REACTION_CREATED
822
- | IntegrationLogType.REACTION_UPDATED
823
- ? Tables<'tbl_chat_reactions'>
824
- : T extends
825
- | IntegrationLogType.PHONE_DISCONNECTED
826
- | IntegrationLogType.PHONE_CONNECTED
827
- | IntegrationLogType.PHONE_UPDATED
828
- | IntegrationLogType.PHONE_QR_UPDATED
829
- ? Tables<'tbl_org_phones'>
830
- : {
831
- [key: string]: unknown;
832
- };
833
-
834
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
835
- OverrideProperties<
836
- Tables<'tbl_integration_logs'>,
837
- {
838
- integration_name: T;
839
- metadata: {
840
- event: IntegrationLogMetadataType<T> & {
841
- event_type: string;
842
- org_id: string;
843
- previous_attributes: {
844
- [key: string]: unknown;
845
- };
846
- };
847
- hook_id: string;
848
- name: string;
849
- };
850
- }
851
- >;
852
-
853
- export type APIAuthDetails = {
854
- org_details: Tables<'view_org'> | null;
855
- phone_details: Tables<'tbl_org_phones'> | null;
856
- token_details: Tables<'tbl_integration_tokens'> | null;
857
- };
858
-
859
- export type WebhookDataType = OverrideProperties<
860
- Tables<'tbl_integration_hooks'>,
861
- {
862
- integration_name: string[];
863
- }
864
- >;
865
-
866
- export type HubspotObjectDataType = {
867
- createdAt: string;
868
- archived: boolean;
869
- id: string;
870
- type: 'contacts' | 'tickets' | 'companies';
871
- properties: Record<
872
- string,
873
- {
874
- groupLabel: string;
875
- groupName: string;
876
- propertyKeyName: string;
877
- propertyKey: string;
878
- propertyInternalValue: string;
879
- propertyValue: string;
880
- propertyType: string;
881
- propertyFieldType: string;
882
- }[]
883
- >;
884
- };
885
-
886
- /* ---------------------------- USER PREFERENCES ---------------------------- */
887
-
888
- export type UserPreferences = {
889
- theme: 'light' | 'dark';
890
- language: 'en' | 'es';
891
- left_sidebar_open: boolean;
892
- right_sidepanel_open: boolean;
893
- sync_wa_unread_count: boolean;
894
- pinned_chats: string[];
895
- archived_chats: string[];
896
- closed_chats: Record<string, number>;
897
- periskope_chat_limit: number;
898
- notifications: Record<string, boolean>;
899
- };
900
-
901
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
902
-
903
- export interface MostActiveMember {
904
- sender_phone: string;
905
- total_messages: number;
906
- }
907
-
908
- export interface GroupAnalyticsResult {
909
- total_messages: number;
910
- total_joins: number;
911
- total_leaves: number;
912
- total_removes: number;
913
- total_reactions: number;
914
- most_active_members: MostActiveMember[];
915
- }
916
-
917
- export interface TimeRange {
918
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
919
- endDateTime: string;
920
- }
921
-
922
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
923
-
924
- export type PollSendType = {
925
- pollName: string;
926
- pollOptions: string[];
927
- options?: {
928
- allowMultipleAnswers?: boolean;
929
- messageSecret?: number[] | null;
930
- pollId?: string;
931
- };
932
- };
933
-
934
- export type PollResultType = {
935
- [name: string]: Record<string, string>;
936
- };
937
-
938
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
939
-
940
- export type CreateGroupOptions = {
941
- messagesAdminsOnly?: boolean;
942
- infoAdminsOnly?: boolean;
943
- addMembersAdminsOnly?: boolean;
944
- image?: string;
945
- name?: string;
946
- description?: string;
947
- initiated_by?: string;
948
- admins?: string[];
949
- };
950
-
951
- /* ------------------------------ DELIVERY INFO ----------------------------- */
952
-
953
- export type DeliveryInfoType = {
954
- delivered: Record<string, number | undefined>;
955
- read: Record<string, number | undefined>;
956
- pending: string[];
957
- read_count: number;
958
- delivered_count: number;
959
- };
960
-
961
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
962
-
963
- export type OrgCreditsType = {
964
- org_id: string;
965
- recurring_allowance: number; // recurring credits replenished every cycle
966
- recurring_balance: number; // recurring credits remaining in current cycle
967
- topup_balance: number; // topup credits remaining
968
- total_credits_used: number; // total credits used in current cycle
969
- next_renewal_date: string;
970
- topup_credits_used: number; // topup credits used in current cycle
971
- recurring_credits_used: number; // recurring credits used in current cycle
972
- };
973
-
974
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
975
-
976
- export type ChatRuleInfoType = Merge<
977
- Pick<
978
- Tables<'view_chats'>,
979
- | 'assigned_to'
980
- | 'chat_id'
981
- | 'chat_name'
982
- | 'chat_type'
983
- | 'created_at'
984
- | 'group_description'
985
- | 'info_admins_only'
986
- | 'org_id'
987
- | 'org_phone'
988
- | 'chat_org_phones'
989
- | 'messages_admins_only'
990
- | 'custom_properties'
991
- | 'initiated_by'
992
- >,
993
- {
994
- has_flagged_messages: boolean;
995
- labels: string[];
996
- members: string[];
997
- custom_properties: { [key: string]: string } | null;
998
- }
999
- >;
1000
-
1001
- export type SenderRuleInfoType = Merge<
1002
- Omit<
1003
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1004
- | 'verified_name'
1005
- | 'verified_level'
1006
- | 'updated_at'
1007
- | 'short_name'
1008
- | 'pushname'
1009
- | 'periskope_name'
1010
- | 'org_phone'
1011
- | 'number'
1012
- | 'name'
1013
- | 'label_ids'
1014
- | 'is_wa_contact'
1015
- | 'is_user'
1016
- | 'is_my_contact'
1017
- | 'is_me'
1018
- | 'is_imported'
1019
- | 'is_group'
1020
- | 'is_blocked'
1021
- | 'contact_color'
1022
- | 'business_profile'
1023
- | 'id'
1024
- | 'contact_image'
1025
- | 'contact_type'
1026
- | 'chat_id'
1027
- | 'is_business'
1028
- | 'is_enterprise'
1029
- | 'is_super_admin'
1030
- >,
1031
- {
1032
- is_internal: boolean;
1033
- labels: string[] | null;
1034
- }
1035
- >;
1036
-
1037
- export type MessageRuleInfoType = {
1038
- chat: ChatRuleInfoType;
1039
- sender: SenderRuleInfoType;
1040
- message: OverrideProperties<
1041
- Omit<
1042
- Tables<'tbl_chat_messages'>,
1043
- | 'vcards'
1044
- | 'updated_at'
1045
- | 'unique_id'
1046
- | 'token'
1047
- | 'to'
1048
- | 'sent_message_id'
1049
- | 'raw_data'
1050
- | 'delivery_info'
1051
- | 'poll_results'
1052
- | 'poll_info'
1053
- | 'order_id'
1054
- | 'mentioned_ids'
1055
- | 'media_key'
1056
- | 'location'
1057
- | 'links'
1058
- | 'is_status'
1059
- | 'is_starred'
1060
- | 'is_gif'
1061
- | 'is_forwarded'
1062
- | 'is_ephemeral'
1063
- | 'is_deleted'
1064
- | 'fts'
1065
- | 'quoted_message_id'
1066
- | 'invite_v4'
1067
- | 'id'
1068
- | 'has_reaction'
1069
- | 'has_media'
1070
- | 'duration'
1071
- | 'broadcast'
1072
- | 'broadcast_id'
1073
- | 'device_type'
1074
- | 'forwarding_score'
1075
- | 'from'
1076
- | 'from_me'
1077
- | 'prev_body'
1078
- | 'flag_response_time'
1079
- | 'flag_metadata'
1080
- | 'ack'
1081
- >,
1082
- {
1083
- media: MediaType | null;
1084
- }
1085
- >;
1086
- };
1087
-
1088
- export type ReactionRuleInfoType = {
1089
- chat: ChatRuleInfoType;
1090
- sender: SenderRuleInfoType;
1091
- message: MessageRuleInfoType['message'];
1092
- reaction: Pick<
1093
- Tables<'tbl_chat_reactions'>,
1094
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1095
- >;
1096
- };
1097
-
1098
- export type TicketRuleInfoType = {
1099
- chat: ChatRuleInfoType;
1100
- sender: SenderRuleInfoType;
1101
- ticket: Merge<
1102
- Pick<
1103
- Tables<'tbl_chat_tickets'>,
1104
- | 'org_id'
1105
- | 'status'
1106
- | 'chat_id'
1107
- | 'subject'
1108
- | 'assignee'
1109
- | 'due_date'
1110
- | 'priority'
1111
- | 'raised_by'
1112
- | 'ticket_id'
1113
- | 'created_at'
1114
- | 'is_deleted'
1115
- >,
1116
- {
1117
- labels: string[] | null;
1118
- custom_properties: { [key: string]: string } | null;
1119
- }
1120
- >;
1121
- message: MessageRuleInfoType['message'];
1122
- };
1123
- export type FeatureFlagReturnType = Record<string, boolean>;
1124
-
1125
- export type RuleLogsType = OverrideProperties<
1126
- Tables<'tbl_rules_logs'>,
1127
- {
1128
- actions_progress: {
1129
- action_id: string;
1130
- action_type: Rule['actions'][number]['type'];
1131
- action_delay: Rule['actions'][number]['delay'];
1132
- ran_at: string | null;
1133
- action_status: 'success' | 'failed' | 'pending';
1134
- action_response: {
1135
- success: boolean;
1136
- data: Record<string, unknown> | null;
1137
- error: {
1138
- message: string;
1139
- name: string;
1140
- stack?: string;
1141
- _error?: Error | Record<string, unknown>;
1142
- } | null;
1143
- };
1144
- }[];
1145
- metadata: {
1146
- conditions: Rule['conditions'];
1147
- actions: Rule['actions'];
1148
- rule_metadata: Pick<
1149
- Rule,
1150
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1151
- >;
1152
- data: Record<string, unknown>;
1153
- };
1154
- conditions_progress: {
1155
- is_valid: boolean;
1156
- validation_progress: Record<
1157
- string,
1158
- {
1159
- res: boolean;
1160
- filter: Filter;
1161
- value: unknown;
1162
- }
1163
- >;
1164
- checked_at: string | null;
1165
- };
1166
- }
1167
- >;
1168
-
1169
- /************************** TASKS ***************************/
1170
-
1171
- export type TaskType = OverrideProperties<
1172
- Tables<'tbl_org_tasks'>,
1173
- {
1174
- reminder_setting: {
1175
- remind_in:
1176
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1177
- | string
1178
- | null;
1179
- repeat?: {
1180
- frequency: number;
1181
- interval: 'days' | 'weeks' | 'months' | 'years';
1182
- end: 'never' | 'after' | 'on';
1183
- on?: string;
1184
- };
1185
- } | null;
1186
- associated_object_metadata:
1187
- | {
1188
- type: 'chat';
1189
- index: 'chat_id';
1190
- id: string;
1191
- object: ChatType;
1192
- }
1193
- | {
1194
- type: 'message';
1195
- index: 'message_id';
1196
- id: string;
1197
- object: MessageType;
1198
- }
1199
- | {
1200
- type: 'ticket';
1201
- index: 'ticket_id';
1202
- id: string;
1203
- object: TicketType;
1204
- }
1205
- | null;
1206
- status: 'open' | 'inprogress' | 'closed';
1207
- priority: 1 | 2 | 3;
1208
- completed_metadata?: {
1209
- completed_at: string;
1210
- completed_by: string;
1211
- } | null;
1212
- type: 'todo' | 'chat' | 'message' | 'ticket';
1213
- }
1214
- >;
1215
-
1216
- type Choice = {
1217
- id: number;
1218
- label: string;
1219
- value: string;
1220
- position: number;
1221
- };
1222
-
1223
- export type FreshdeskCustomFieldType = {
1224
- id: number;
1225
- name: string;
1226
- label: string;
1227
- position: number;
1228
- required_for_agents: boolean;
1229
- archived: boolean;
1230
- customers_can_edit: boolean;
1231
- label_for_customers: string;
1232
- required_for_customers: boolean;
1233
- customers_can_filter: boolean;
1234
- required_for_closure: boolean;
1235
- displayed_to_customers: boolean;
1236
- type: string;
1237
- default: boolean;
1238
- created_at: string;
1239
- updated_at: string;
1240
- choices?: Choice[];
1241
- };
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
+ group_metadata?: Record<string, any>;
325
+ snooze_metadata?: {
326
+ snooze_until: number;
327
+ snooze_message?: string;
328
+ snooze_by?: string;
329
+ },
330
+ member_unread_count?: {
331
+ [key: string]: number;
332
+ };
333
+ }
334
+ >;
335
+
336
+ /* -------------------------------------------------------------------------- */
337
+ /* MESSAGE */
338
+ /* -------------------------------------------------------------------------- */
339
+
340
+ export type MediaType = {
341
+ path?: string;
342
+ mimetype?: string;
343
+ filename?: string;
344
+ dimensions?: { width: number; height: number; ar: number };
345
+ size?: number;
346
+ thumbnail?: string;
347
+ filedata?: string;
348
+ compress?: boolean;
349
+ };
350
+
351
+ export type MessageType = Merge<
352
+ OverrideProperties<
353
+ TablesInsert<'tbl_chat_messages'>,
354
+ {
355
+ message_id: string;
356
+ org_id: string;
357
+ org_phone: string;
358
+ chat_id: string;
359
+ message_type: (typeof SUPPORTED_TYPES)[number];
360
+ media: MediaType | null;
361
+ flag_metadata?: MessageFlagType | null;
362
+ poll_info?: PollSendType | null;
363
+ poll_results?: PollResultType | null;
364
+ delivery_info?: DeliveryInfoType | null;
365
+ raw_data?: {
366
+ translations?: Record<string, string>;
367
+ [key: string]: unknown;
368
+ } | null;
369
+ }
370
+ >,
371
+ {
372
+ reactions?: ReactionType[];
373
+ message_payload?: SingleMessagePayload;
374
+ highlight?: number;
375
+ is_private_note?: boolean;
376
+ }
377
+ >;
378
+
379
+ export type MessageFlagType = {
380
+ status: boolean;
381
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
382
+ response_id?: string;
383
+ response_timestamp?: string;
384
+ response_email?: string;
385
+ flagged_by?: string;
386
+ flagged_at?: string;
387
+ };
388
+
389
+ export type MessageSendType = {
390
+ queue_id: string;
391
+ queue_position: string;
392
+ };
393
+
394
+ export type MessageBroadcastType = {
395
+ broadcast_id: string;
396
+ };
397
+
398
+ /* -------------------------------------------------------------------------- */
399
+
400
+ export type TicketType = OverrideProperties<
401
+ Tables<'tbl_chat_tickets'>,
402
+ {
403
+ label_ids: { [key: string]: boolean };
404
+ hubspot_metadata: {
405
+ id?: string;
406
+ type?: string;
407
+ hubId?: string;
408
+ pipeline: {
409
+ id: string;
410
+ label: string;
411
+ };
412
+ object_data?: HubspotObjectDataType;
413
+ } | null;
414
+ freshdesk_metadata: Record<string, string>;
415
+ close_ticket_metadata?:
416
+ | {
417
+ closed_by: string;
418
+ closed_at: string;
419
+ closed_message?: string | null;
420
+ send_reply_message_id?: string | null;
421
+ }
422
+ | any;
423
+ }
424
+ >;
425
+
426
+ export type ContactType = Merge<
427
+ Tables<'tbl_contacts'>,
428
+ {
429
+ chats: ChatType[] | null;
430
+ chat_ids?: string[];
431
+ }
432
+ >;
433
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
434
+
435
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
436
+
437
+ export type ChatAccessType = Merge<
438
+ TablesUpdate<'tbl_org_members'>,
439
+ {
440
+ has_access?: boolean;
441
+ email: string | null;
442
+ }
443
+ >;
444
+
445
+ export type QueueJobTypes = {
446
+ addedTimestamp: number;
447
+ attemptsMade: number;
448
+ attemptsStarted: number;
449
+ data: {
450
+ body: string;
451
+ chat_id: string;
452
+ };
453
+ finishedTimestamp: number;
454
+ id: string;
455
+ message_id: string;
456
+ processedTimestamp: number;
457
+ stacktrace: string[];
458
+ status: string;
459
+ };
460
+
461
+ export type PhoneQueueStatusType = {
462
+ active: number;
463
+ failed: number;
464
+ completed: number;
465
+ is_running: boolean;
466
+ pending: number;
467
+ };
468
+
469
+ export type PhoneType = OverrideProperties<
470
+ Tables<'tbl_org_phones'>,
471
+ {
472
+ queue_status: {
473
+ [key: string]: PhoneQueueStatusType;
474
+ };
475
+ }
476
+ >;
477
+
478
+ export type PhoneInfoType = Merge<
479
+ Pick<
480
+ PhoneType,
481
+ | 'created_at'
482
+ | 'first_connected_at'
483
+ | 'is_ready'
484
+ | 'label_ids'
485
+ | 'org_id'
486
+ | 'org_phone'
487
+ | 'phone_id'
488
+ | 'phone_image'
489
+ | 'phone_name'
490
+ | 'qr_code'
491
+ | 'updated_at'
492
+ | 'wa_state'
493
+ >,
494
+ {
495
+ labels: string[];
496
+ }
497
+ >;
498
+
499
+ /* -------------------------------- CONSTANTS ------------------------------- */
500
+
501
+ export const labelColors = [
502
+ '#9333EA',
503
+ '#0D9488',
504
+ '#DB2777',
505
+ '#2563EB',
506
+ '#F97316',
507
+ ];
508
+
509
+ export const enumChatColors = [
510
+ '#B4876E',
511
+ '#A5B337',
512
+ '#06CF9C',
513
+ '#25D366',
514
+ '#02A698',
515
+ '#7D9EF1',
516
+ '#007BFC',
517
+ '#5E47DE',
518
+ '#7F66FF',
519
+ '#9333EA',
520
+ '#FA6533',
521
+ '#C4532D',
522
+ '#DC2626',
523
+ '#FF2E74',
524
+ '#DB2777',
525
+ ] as const;
526
+
527
+ export type RepeatDaysType =
528
+ | 'monday'
529
+ | 'tuesday'
530
+ | 'wednesday'
531
+ | 'thursday'
532
+ | 'friday'
533
+ | 'saturday'
534
+ | 'sunday';
535
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
536
+
537
+ /* -------------------------- LISTING ENDPOINT -------------------------- */
538
+
539
+ type ListingType = {
540
+ from?: number;
541
+ to?: number;
542
+ count?: number;
543
+ };
544
+
545
+ export type ListNotificationsType = Merge<
546
+ ListingType,
547
+ {
548
+ notifictions?: NotificationType[];
549
+ }
550
+ >;
551
+
552
+ export type ListChatMessagesType = Merge<
553
+ ListingType,
554
+ {
555
+ messages?: MessageType[];
556
+ }
557
+ >;
558
+
559
+ export type ListContactsType = Merge<
560
+ ListingType,
561
+ {
562
+ contacts?: ContactType[];
563
+ }
564
+ >;
565
+
566
+ export type ListTicketsType = Merge<
567
+ ListingType,
568
+ {
569
+ tickets?: TicketType[];
570
+ }
571
+ >;
572
+
573
+ export type ListChatsType = Merge<
574
+ ListingType,
575
+ {
576
+ chats?: ChatType[];
577
+ }
578
+ >;
579
+
580
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
581
+
582
+ export const SUPPORTED_TYPES = [
583
+ 'chat',
584
+ 'sticker',
585
+ 'image',
586
+ 'video',
587
+ 'document',
588
+ 'vcard',
589
+ 'multi_vcard',
590
+ 'audio',
591
+ 'ptt',
592
+ 'poll_creation',
593
+ 'location',
594
+ 'ciphertext',
595
+ ] as const;
596
+
597
+ export type SendMessageContent = {
598
+ message_type?: (typeof SUPPORTED_TYPES)[number];
599
+ body?: string;
600
+ media?: MediaType;
601
+ contact_ids?: string[];
602
+ location?: {
603
+ latitude: string;
604
+ longitude: string;
605
+ options?: { name?: string; address?: string; url?: string };
606
+ };
607
+ poll?: PollSendType;
608
+ quoted_message_id?: string;
609
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
610
+ broadcast_id?: string;
611
+ performed_by?: string;
612
+ options?: Record<string, any>;
613
+ };
614
+
615
+ export type QuickReplyContent = Omit<
616
+ SendMessageContent,
617
+ 'broadcast_id' | 'variables'
618
+ >;
619
+
620
+ export type ScheduleMessagePayload = {
621
+ scheduled_id?: string;
622
+ is_repeat?: boolean | null;
623
+ scheduled_at: string;
624
+ repeat_config?: {
625
+ timezone?: string;
626
+ repeat_ends?: string;
627
+ repeat_interval?: RepeatIntervalType;
628
+ repeat_value?: number;
629
+ repeat_days?: RepeatDaysType[];
630
+ };
631
+ };
632
+
633
+ export type BroadcastVariableType = {
634
+ chat_id: string;
635
+ values: { [key: string]: string };
636
+ };
637
+
638
+ export type BroadcastMessagePayload = SendMessageContent & {
639
+ chat_ids: string[];
640
+ broadcast_id?: string;
641
+ variables?: BroadcastVariableType[];
642
+ delay?: number;
643
+ };
644
+
645
+ export type SingleMessagePayload = SendMessageContent & {
646
+ chat_id: string;
647
+ job_id?: string;
648
+ priority?: number;
649
+ };
650
+
651
+ export type MessageAttachmentFileTypes =
652
+ | 'image'
653
+ | 'audio'
654
+ | 'document'
655
+ | 'video';
656
+
657
+ export type AttachmentFileType = {
658
+ result: string;
659
+ file: File | null;
660
+ type: MessageAttachmentFileTypes;
661
+ localFileURL?: string;
662
+ };
663
+
664
+ export type AttachmentLinkType = {
665
+ link: {
666
+ url: string;
667
+ type: MessageAttachmentFileTypes;
668
+ name: string;
669
+ mimetype?: string;
670
+ };
671
+ };
672
+
673
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
674
+
675
+ /* -------------------------------- BROADCAST ------------------------------- */
676
+
677
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
678
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
679
+ } & {
680
+ chats: ChatType[];
681
+ };
682
+
683
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
684
+
685
+ export type ChatLogType = {
686
+ log: Tables<'view_chat_logs'>;
687
+ operations: Tables<'tbl_chat_logs'>[];
688
+ };
689
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
690
+
691
+ export type ChatParticipantOperationPayload = {
692
+ participant_ids: string[];
693
+ chat_ids: string[];
694
+ performed_by: string;
695
+ };
696
+
697
+ export type ChatOperationReturn = {
698
+ [participant_id: string]: {
699
+ is_success: boolean;
700
+ message?: string;
701
+ code?: number;
702
+ isInviteV4Sent?: boolean;
703
+ };
704
+ };
705
+
706
+ /* ----------------------- BILLING - STRIPE ----------------------- */
707
+
708
+ export type StripeSubscription = _Stripe.Subscription;
709
+ export type StripeCustomer = _Stripe.Customer;
710
+ export type StripeCoupon = _Stripe.Coupon;
711
+ export type StripePrice = _Stripe.Price;
712
+ export type Stripe = _Stripe;
713
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
714
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
715
+
716
+ /* -------------------------------- REALTIME -------------------------------- */
717
+
718
+ export type PhoneStateType = {
719
+ loading: boolean;
720
+ state: string;
721
+ sync: number;
722
+ percent: number | null;
723
+ message?: string;
724
+ error?: string;
725
+ };
726
+
727
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
728
+
729
+ export type ChatInfoType = Merge<
730
+ ChatType,
731
+ {
732
+ members: {
733
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
734
+ } | null;
735
+ chat_labels: string | null;
736
+ custom_properties: { [key: string]: string } | null;
737
+ }
738
+ >;
739
+
740
+ export type TicketInfoType = {
741
+ chat: ChatInfoType;
742
+ message: {
743
+ body: string;
744
+ chat_id: string;
745
+ org_phone: string;
746
+ timestamp: string;
747
+ media_path: string;
748
+ message_id: string;
749
+ sender_name: string;
750
+ performed_by: string;
751
+ sender_phone: string;
752
+ };
753
+ ticket: {
754
+ org_id: string;
755
+ status: string;
756
+ subject: string;
757
+ assignee: string;
758
+ due_date: string;
759
+ priority: 0 | 1 | 2 | 3 | 4;
760
+ raised_by: string;
761
+ ticket_id: string;
762
+ created_at: string;
763
+ assigned_by: string;
764
+ ticket_labels: string;
765
+ quoted_message_id: string;
766
+ ticket_custom_properties: { [key: string]: string } | null;
767
+ };
768
+ attached_messages: {
769
+ body: string;
770
+ chat_id: string;
771
+ org_phone: string;
772
+ timestamp: string;
773
+ media_path: string;
774
+ message_id: string;
775
+ sender_name: string;
776
+ performed_by: string;
777
+ sender_phone: string;
778
+ }[];
779
+ };
780
+
781
+ export type IntegrationLogObjectType =
782
+ | 'chat'
783
+ | 'message'
784
+ | 'reaction'
785
+ | 'ticket'
786
+ | 'phone';
787
+ export enum IntegrationLogType {
788
+ NEW_CHAT = 'chat.created',
789
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
790
+ NEW_MESSAGE = 'message.created',
791
+ MESSAGE_UPDATED = 'message.updated',
792
+ MESSAGE_DELETED = 'message.deleted',
793
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
794
+ REACTION_CREATED = 'reaction.created',
795
+ REACTION_UPDATED = 'reaction.updated',
796
+ NEW_TICKET = 'ticket.created',
797
+ TICKET_UPDATED = 'ticket.updated',
798
+ TICKET_DELETED = 'ticket.deleted',
799
+ MESSAGE_FLAGGED = 'message.flagged',
800
+ MESSAGE_UNFLAGGED = 'message.unflagged',
801
+ PHONE_DISCONNECTED = 'org.phone.disconnected',
802
+ PHONE_CONNECTED = 'org.phone.connected',
803
+ PHONE_UPDATED = 'org.phone.updated',
804
+ PHONE_QR_UPDATED = 'org.phone.qr',
805
+ }
806
+
807
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
808
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
809
+ ? TicketInfoType
810
+ : T extends IntegrationLogType.NEW_CHAT
811
+ ? Tables<'tbl_chats'>
812
+ : T extends
813
+ | IntegrationLogType.NEW_MESSAGE
814
+ | IntegrationLogType.MESSAGE_UPDATED
815
+ | IntegrationLogType.MESSAGE_DELETED
816
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
817
+ | IntegrationLogType.MESSAGE_FLAGGED
818
+ | IntegrationLogType.MESSAGE_UNFLAGGED
819
+ ? Tables<'tbl_chat_messages'>
820
+ : T extends
821
+ | IntegrationLogType.REACTION_CREATED
822
+ | IntegrationLogType.REACTION_UPDATED
823
+ ? Tables<'tbl_chat_reactions'>
824
+ : T extends
825
+ | IntegrationLogType.PHONE_DISCONNECTED
826
+ | IntegrationLogType.PHONE_CONNECTED
827
+ | IntegrationLogType.PHONE_UPDATED
828
+ | IntegrationLogType.PHONE_QR_UPDATED
829
+ ? Tables<'tbl_org_phones'>
830
+ : {
831
+ [key: string]: unknown;
832
+ };
833
+
834
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
835
+ OverrideProperties<
836
+ Tables<'tbl_integration_logs'>,
837
+ {
838
+ integration_name: T;
839
+ metadata: {
840
+ event: IntegrationLogMetadataType<T> & {
841
+ event_type: string;
842
+ org_id: string;
843
+ previous_attributes: {
844
+ [key: string]: unknown;
845
+ };
846
+ };
847
+ hook_id: string;
848
+ name: string;
849
+ };
850
+ }
851
+ >;
852
+
853
+ export type APIAuthDetails = {
854
+ org_details: Tables<'view_org'> | null;
855
+ phone_details: Tables<'tbl_org_phones'> | null;
856
+ token_details: Tables<'tbl_integration_tokens'> | null;
857
+ };
858
+
859
+ export type WebhookDataType = OverrideProperties<
860
+ Tables<'tbl_integration_hooks'>,
861
+ {
862
+ integration_name: string[];
863
+ }
864
+ >;
865
+
866
+ export type HubspotObjectDataType = {
867
+ createdAt: string;
868
+ archived: boolean;
869
+ id: string;
870
+ type: 'contacts' | 'tickets' | 'companies';
871
+ properties: Record<
872
+ string,
873
+ {
874
+ groupLabel: string;
875
+ groupName: string;
876
+ propertyKeyName: string;
877
+ propertyKey: string;
878
+ propertyInternalValue: string;
879
+ propertyValue: string;
880
+ propertyType: string;
881
+ propertyFieldType: string;
882
+ }[]
883
+ >;
884
+ };
885
+
886
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
887
+
888
+ export type UserPreferences = {
889
+ theme: 'light' | 'dark';
890
+ language: 'en' | 'es';
891
+ left_sidebar_open: boolean;
892
+ right_sidepanel_open: boolean;
893
+ sync_wa_unread_count: boolean;
894
+ pinned_chats: string[];
895
+ archived_chats: string[];
896
+ closed_chats: Record<string, number>;
897
+ periskope_chat_limit: number;
898
+ notifications: Record<string, boolean>;
899
+ };
900
+
901
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
902
+
903
+ export interface MostActiveMember {
904
+ sender_phone: string;
905
+ total_messages: number;
906
+ }
907
+
908
+ export interface GroupAnalyticsResult {
909
+ total_messages: number;
910
+ total_joins: number;
911
+ total_leaves: number;
912
+ total_removes: number;
913
+ total_reactions: number;
914
+ most_active_members: MostActiveMember[];
915
+ }
916
+
917
+ export interface TimeRange {
918
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
919
+ endDateTime: string;
920
+ }
921
+
922
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
923
+
924
+ export type PollSendType = {
925
+ pollName: string;
926
+ pollOptions: string[];
927
+ options?: {
928
+ allowMultipleAnswers?: boolean;
929
+ messageSecret?: number[] | null;
930
+ pollId?: string;
931
+ };
932
+ };
933
+
934
+ export type PollResultType = {
935
+ [name: string]: Record<string, string>;
936
+ };
937
+
938
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
939
+
940
+ export type CreateGroupOptions = {
941
+ messagesAdminsOnly?: boolean;
942
+ infoAdminsOnly?: boolean;
943
+ addMembersAdminsOnly?: boolean;
944
+ image?: string;
945
+ name?: string;
946
+ description?: string;
947
+ initiated_by?: string;
948
+ admins?: string[];
949
+ };
950
+
951
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
952
+
953
+ export type DeliveryInfoType = {
954
+ delivered: Record<string, number | undefined>;
955
+ read: Record<string, number | undefined>;
956
+ pending: string[];
957
+ read_count: number;
958
+ delivered_count: number;
959
+ };
960
+
961
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
962
+
963
+ export type OrgCreditsType = {
964
+ org_id: string;
965
+ recurring_allowance: number; // recurring credits replenished every cycle
966
+ recurring_balance: number; // recurring credits remaining in current cycle
967
+ topup_balance: number; // topup credits remaining
968
+ total_credits_used: number; // total credits used in current cycle
969
+ next_renewal_date: string;
970
+ topup_credits_used: number; // topup credits used in current cycle
971
+ recurring_credits_used: number; // recurring credits used in current cycle
972
+ };
973
+
974
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
975
+
976
+ export type ChatRuleInfoType = Merge<
977
+ Pick<
978
+ Tables<'view_chats'>,
979
+ | 'assigned_to'
980
+ | 'chat_id'
981
+ | 'chat_name'
982
+ | 'chat_type'
983
+ | 'created_at'
984
+ | 'group_description'
985
+ | 'info_admins_only'
986
+ | 'org_id'
987
+ | 'org_phone'
988
+ | 'chat_org_phones'
989
+ | 'messages_admins_only'
990
+ | 'custom_properties'
991
+ | 'initiated_by'
992
+ >,
993
+ {
994
+ has_flagged_messages: boolean;
995
+ labels: string[];
996
+ members: string[];
997
+ custom_properties: { [key: string]: string } | null;
998
+ }
999
+ >;
1000
+
1001
+ export type SenderRuleInfoType = Merge<
1002
+ Omit<
1003
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1004
+ | 'verified_name'
1005
+ | 'verified_level'
1006
+ | 'updated_at'
1007
+ | 'short_name'
1008
+ | 'pushname'
1009
+ | 'periskope_name'
1010
+ | 'org_phone'
1011
+ | 'number'
1012
+ | 'name'
1013
+ | 'label_ids'
1014
+ | 'is_wa_contact'
1015
+ | 'is_user'
1016
+ | 'is_my_contact'
1017
+ | 'is_me'
1018
+ | 'is_imported'
1019
+ | 'is_group'
1020
+ | 'is_blocked'
1021
+ | 'contact_color'
1022
+ | 'business_profile'
1023
+ | 'id'
1024
+ | 'contact_image'
1025
+ | 'contact_type'
1026
+ | 'chat_id'
1027
+ | 'is_business'
1028
+ | 'is_enterprise'
1029
+ | 'is_super_admin'
1030
+ >,
1031
+ {
1032
+ is_internal: boolean;
1033
+ labels: string[] | null;
1034
+ }
1035
+ >;
1036
+
1037
+ export type MessageRuleInfoType = {
1038
+ chat: ChatRuleInfoType;
1039
+ sender: SenderRuleInfoType;
1040
+ message: OverrideProperties<
1041
+ Omit<
1042
+ Tables<'tbl_chat_messages'>,
1043
+ | 'vcards'
1044
+ | 'updated_at'
1045
+ | 'unique_id'
1046
+ | 'token'
1047
+ | 'to'
1048
+ | 'sent_message_id'
1049
+ | 'raw_data'
1050
+ | 'delivery_info'
1051
+ | 'poll_results'
1052
+ | 'poll_info'
1053
+ | 'order_id'
1054
+ | 'mentioned_ids'
1055
+ | 'media_key'
1056
+ | 'location'
1057
+ | 'links'
1058
+ | 'is_status'
1059
+ | 'is_starred'
1060
+ | 'is_gif'
1061
+ | 'is_forwarded'
1062
+ | 'is_ephemeral'
1063
+ | 'is_deleted'
1064
+ | 'fts'
1065
+ | 'quoted_message_id'
1066
+ | 'invite_v4'
1067
+ | 'id'
1068
+ | 'has_reaction'
1069
+ | 'has_media'
1070
+ | 'duration'
1071
+ | 'broadcast'
1072
+ | 'broadcast_id'
1073
+ | 'device_type'
1074
+ | 'forwarding_score'
1075
+ | 'from'
1076
+ | 'from_me'
1077
+ | 'prev_body'
1078
+ | 'flag_response_time'
1079
+ | 'flag_metadata'
1080
+ | 'ack'
1081
+ >,
1082
+ {
1083
+ media: MediaType | null;
1084
+ }
1085
+ >;
1086
+ };
1087
+
1088
+ export type ReactionRuleInfoType = {
1089
+ chat: ChatRuleInfoType;
1090
+ sender: SenderRuleInfoType;
1091
+ message: MessageRuleInfoType['message'];
1092
+ reaction: Pick<
1093
+ Tables<'tbl_chat_reactions'>,
1094
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1095
+ >;
1096
+ };
1097
+
1098
+ export type TicketRuleInfoType = {
1099
+ chat: ChatRuleInfoType;
1100
+ sender: SenderRuleInfoType;
1101
+ ticket: Merge<
1102
+ Pick<
1103
+ Tables<'tbl_chat_tickets'>,
1104
+ | 'org_id'
1105
+ | 'status'
1106
+ | 'chat_id'
1107
+ | 'subject'
1108
+ | 'assignee'
1109
+ | 'due_date'
1110
+ | 'priority'
1111
+ | 'raised_by'
1112
+ | 'ticket_id'
1113
+ | 'created_at'
1114
+ | 'is_deleted'
1115
+ >,
1116
+ {
1117
+ labels: string[] | null;
1118
+ custom_properties: { [key: string]: string } | null;
1119
+ }
1120
+ >;
1121
+ message: MessageRuleInfoType['message'];
1122
+ };
1123
+ export type FeatureFlagReturnType = Record<string, boolean>;
1124
+
1125
+ export type RuleLogsType = OverrideProperties<
1126
+ Tables<'tbl_rules_logs'>,
1127
+ {
1128
+ actions_progress: {
1129
+ action_id: string;
1130
+ action_type: Rule['actions'][number]['type'];
1131
+ action_delay: Rule['actions'][number]['delay'];
1132
+ ran_at: string | null;
1133
+ action_status: 'success' | 'failed' | 'pending';
1134
+ action_response: {
1135
+ success: boolean;
1136
+ data: Record<string, unknown> | null;
1137
+ error: {
1138
+ message: string;
1139
+ name: string;
1140
+ stack?: string;
1141
+ _error?: Error | Record<string, unknown>;
1142
+ } | null;
1143
+ };
1144
+ }[];
1145
+ metadata: {
1146
+ conditions: Rule['conditions'];
1147
+ actions: Rule['actions'];
1148
+ rule_metadata: Pick<
1149
+ Rule,
1150
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1151
+ >;
1152
+ data: Record<string, unknown>;
1153
+ };
1154
+ conditions_progress: {
1155
+ is_valid: boolean;
1156
+ validation_progress: Record<
1157
+ string,
1158
+ {
1159
+ res: boolean;
1160
+ filter: Filter;
1161
+ value: unknown;
1162
+ }
1163
+ >;
1164
+ checked_at: string | null;
1165
+ };
1166
+ }
1167
+ >;
1168
+
1169
+ /************************** TASKS ***************************/
1170
+
1171
+ export type TaskType = OverrideProperties<
1172
+ Tables<'tbl_org_tasks'>,
1173
+ {
1174
+ reminder_setting: {
1175
+ remind_in:
1176
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1177
+ | string
1178
+ | null;
1179
+ repeat?: {
1180
+ frequency: number;
1181
+ interval: 'days' | 'weeks' | 'months' | 'years';
1182
+ end: 'never' | 'after' | 'on';
1183
+ on?: string;
1184
+ };
1185
+ } | null;
1186
+ associated_object_metadata:
1187
+ | {
1188
+ type: 'chat';
1189
+ index: 'chat_id';
1190
+ id: string;
1191
+ object: ChatType;
1192
+ }
1193
+ | {
1194
+ type: 'message';
1195
+ index: 'message_id';
1196
+ id: string;
1197
+ object: MessageType;
1198
+ }
1199
+ | {
1200
+ type: 'ticket';
1201
+ index: 'ticket_id';
1202
+ id: string;
1203
+ object: TicketType;
1204
+ }
1205
+ | null;
1206
+ status: 'open' | 'inprogress' | 'closed';
1207
+ priority: 1 | 2 | 3;
1208
+ completed_metadata?: {
1209
+ completed_at: string;
1210
+ completed_by: string;
1211
+ } | null;
1212
+ type: 'todo' | 'chat' | 'message' | 'ticket';
1213
+ }
1214
+ >;
1215
+
1216
+ type Choice = {
1217
+ id: number;
1218
+ label: string;
1219
+ value: string;
1220
+ position: number;
1221
+ };
1222
+
1223
+ export type FreshdeskCustomFieldType = {
1224
+ id: number;
1225
+ name: string;
1226
+ label: string;
1227
+ position: number;
1228
+ required_for_agents: boolean;
1229
+ archived: boolean;
1230
+ customers_can_edit: boolean;
1231
+ label_for_customers: string;
1232
+ required_for_customers: boolean;
1233
+ customers_can_filter: boolean;
1234
+ required_for_closure: boolean;
1235
+ displayed_to_customers: boolean;
1236
+ type: string;
1237
+ default: boolean;
1238
+ created_at: string;
1239
+ updated_at: string;
1240
+ choices?: Choice[];
1241
+ };