@periskope/types 0.6.199 → 0.6.201

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,965 +1,969 @@
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 OrgMetadata = {
82
- phone_number: string;
83
- ticket_prefix: string;
84
- referralSource?: string;
85
- surveyData?: MicrosurveyData;
86
- preferences?: OrgPreferences;
87
- hubspot: {
88
- hubspot_pipelines?: {
89
- id: string;
90
- label: string;
91
- default_stage: { id: string; label: string };
92
- }[];
93
- hubspot_hidden_fields?: string[];
94
- };
95
- partition?: boolean;
96
- tickets: {
97
- prefix?: string;
98
- emoji_ticketing: {
99
- is_enabled?: boolean;
100
- is_message_enabled?: boolean;
101
- message_template?: string;
102
- };
103
- };
104
- attribution?: Object;
105
- affiliate_id?: string;
106
- custom_properties?: {
107
- chats_order?: {
108
- [id: string]: number;
109
- };
110
- tickets_order?: {
111
- [id: string]: number;
112
- };
113
- };
114
- rules?: {
115
- limit?: number;
116
- };
117
- ai?: {
118
- flag_prompt?: string;
119
- };
120
- };
121
-
122
- type AccessScopes = {
123
- feature_flags: Record<string, boolean>;
124
- integrations: boolean;
125
- rules: boolean;
126
- exports: boolean;
127
- };
128
-
129
- export type OrgType = OverrideProperties<
130
- Merge<
131
- Tables<'tbl_org'>,
132
- {
133
- user: Tables<'tbl_org_members'>;
134
- members: Tables<'tbl_org_members'>[];
135
- phones: Tables<'tbl_org_phones'>[];
136
- labels: Tables<'tbl_org_labels'>[];
137
- quick_replies: Tables<'tbl_quick_replies'>[];
138
- custom_properties: Tables<'tbl_custom_properties'>[];
139
- subscription_status: 'active' | 'inactive' | 'unpaid';
140
- is_enterprise: boolean;
141
- is_free_trial: boolean;
142
- is_hubspot_connected: boolean;
143
- is_freshdesk_connected: boolean;
144
- is_zohodesk_connected: boolean;
145
- access_scopes: AccessScopes;
146
- rules: Rule[];
147
- }
148
- >,
149
- {
150
- org_plan: OrgPlan<AllPlans | Enterprise>;
151
- stripe_customer_details: _Stripe.Customer | null;
152
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
153
- stripe_customer_id: _Stripe.Customer['id'] | null;
154
- org_metadata: OrgMetadata;
155
- }
156
- >;
157
-
158
- export type ChatMemberType = Merge<
159
- Tables<'tbl_chat_participants'>,
160
- Tables<'tbl_contacts'>
161
- >;
162
-
163
- export type ChatType = Merge<
164
- Tables<'view_chats'>,
165
- {
166
- chat_id: string;
167
- latest_message: MessageType | null;
168
- latest_message_timestamp: number | null;
169
- members: { [key: string]: ChatMemberType } | null;
170
- chat_type: 'user' | 'group' | 'business' | 'unknown';
171
- chat_access: { [key: string]: boolean };
172
- label_ids: { [key: string]: boolean };
173
- chat_org_phones?: string[];
174
- message_unread_count: number | null;
175
- hubspot_metadata: {
176
- id: string;
177
- type: string;
178
- hubId: string;
179
- object_data: HubspotObjectDataType;
180
- } | null;
181
- info_admins_only: boolean;
182
- messages_admins_only: boolean;
183
- unread_count?: { [key: string]: number };
184
- active_phone: string | null;
185
- flag_count_map?: { [key: string]: number };
186
- is_archived?: boolean;
187
- is_pinned?: boolean;
188
- closed_at?: number | null;
189
- common_chats?: string[];
190
- freshdesk_metadata?: Record<string, any>;
191
- zohodesk_metadata?: Record<string, any>;
192
- pinned_messages?: Record<string, number>;
193
- }
194
- >;
195
-
196
- /* -------------------------------------------------------------------------- */
197
- /* MESSAGE */
198
- /* -------------------------------------------------------------------------- */
199
-
200
- export type MediaType = {
201
- path?: string;
202
- mimetype?: string;
203
- filename?: string;
204
- dimensions?: { width: number; height: number; ar: number };
205
- size?: number;
206
- thumbnail?: string;
207
- filedata?: string;
208
- compress?: boolean;
209
- };
210
-
211
- export type MessageType = Merge<
212
- OverrideProperties<
213
- TablesInsert<'tbl_chat_messages'>,
214
- {
215
- message_id: string;
216
- org_id: string;
217
- org_phone: string;
218
- chat_id: string;
219
- message_type: (typeof SUPPORTED_TYPES)[number];
220
- media: MediaType | null;
221
- flag_metadata?: MessageFlagType | null;
222
- poll_info?: PollSendType | null;
223
- poll_results?: PollResultType | null;
224
- delivery_info?: DeliveryInfoType | null;
225
- }
226
- >,
227
- {
228
- reactions?: ReactionType[];
229
- message_payload?: SingleMessagePayload;
230
- highlight?: number;
231
- is_private_note?: boolean;
232
- }
233
- >;
234
-
235
- export type MessageFlagType = {
236
- status: boolean;
237
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
238
- response_id?: string;
239
- response_timestamp?: string;
240
- response_email?: string;
241
- };
242
-
243
- /* -------------------------------------------------------------------------- */
244
-
245
- export type TicketType = OverrideProperties<
246
- Tables<'tbl_chat_tickets'>,
247
- {
248
- label_ids: { [key: string]: boolean };
249
- hubspot_metadata: {
250
- id?: string;
251
- type?: string;
252
- hubId?: string;
253
- pipeline: {
254
- id: string;
255
- label: string;
256
- };
257
- object_data?: HubspotObjectDataType;
258
- } | null;
259
- freshdesk_metadata: Record<string, string>;
260
- close_ticket_metadata?:
261
- | {
262
- closed_by: string;
263
- closed_at: string;
264
- closed_message?: string | null;
265
- send_reply_message_id?: string | null;
266
- }
267
- | any;
268
- }
269
- >;
270
-
271
- export type ContactType = Merge<
272
- Tables<'tbl_contacts'>,
273
- {
274
- chats: ChatType[] | null;
275
- chat_ids?: string[];
276
- }
277
- >;
278
- export type ReactionType = Tables<'tbl_chat_reactions'>;
279
-
280
- export type NotificationType = Tables<'tbl_chat_notifications'>;
281
-
282
- export type ChatAccessType = Merge<
283
- TablesUpdate<'tbl_org_members'>,
284
- {
285
- has_access?: boolean;
286
- email: string | null;
287
- }
288
- >;
289
-
290
- export type PhoneQueueStatusType = {
291
- active: number;
292
- failed: number;
293
- completed: number;
294
- is_running: boolean;
295
- pending: number;
296
- };
297
-
298
- export type PhoneType = OverrideProperties<
299
- Tables<'tbl_org_phones'>,
300
- {
301
- queue_status: {
302
- [key: string]: PhoneQueueStatusType;
303
- };
304
- }
305
- >;
306
-
307
- /* -------------------------------- CONSTANTS ------------------------------- */
308
-
309
- export const labelColors = [
310
- '#9333EA',
311
- '#0D9488',
312
- '#DB2777',
313
- '#2563EB',
314
- '#F97316',
315
- ];
316
-
317
- export const enumChatColors = [
318
- '#B4876E',
319
- '#A5B337',
320
- '#06CF9C',
321
- '#25D366',
322
- '#02A698',
323
- '#7D9EF1',
324
- '#007BFC',
325
- '#5E47DE',
326
- '#7F66FF',
327
- '#9333EA',
328
- '#FA6533',
329
- '#C4532D',
330
- '#DC2626',
331
- '#FF2E74',
332
- '#DB2777',
333
- ] as const;
334
-
335
- export type RepeatDaysType =
336
- | 'monday'
337
- | 'tuesday'
338
- | 'wednesday'
339
- | 'thursday'
340
- | 'friday'
341
- | 'saturday'
342
- | 'sunday';
343
- export type RepeatIntervalType = 'day' | 'week' | 'month';
344
-
345
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
346
-
347
- export const SUPPORTED_TYPES = [
348
- 'chat',
349
- 'sticker',
350
- 'image',
351
- 'video',
352
- 'document',
353
- 'vcard',
354
- 'multi_vcard',
355
- 'audio',
356
- 'ptt',
357
- 'poll_creation',
358
- 'location',
359
- 'ciphertext',
360
- ] as const;
361
-
362
- export type SendMessageContent = {
363
- message_type?: (typeof SUPPORTED_TYPES)[number];
364
- body?: string;
365
- media?: MediaType;
366
- contact_ids?: string[];
367
- location?: {
368
- latitude: string;
369
- longitude: string;
370
- options?: { name?: string; address?: string; url?: string };
371
- };
372
- poll?: PollSendType;
373
- quoted_message_id?: string;
374
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
375
- broadcast_id?: string;
376
- performed_by?: string;
377
- };
378
-
379
- export type QuickReplyContent = Omit<
380
- SendMessageContent,
381
- 'broadcast_id' | 'variables'
382
- >;
383
-
384
- export type ScheduleMessagePayload = {
385
- scheduled_id?: string;
386
- is_repeat?: boolean | null;
387
- scheduled_at: string;
388
- repeat_config?: {
389
- repeat_ends?: string;
390
- repeat_interval?: RepeatIntervalType;
391
- repeat_value?: number;
392
- repeat_days?: RepeatDaysType[];
393
- };
394
- };
395
-
396
- export type BroadcastVariableType = {
397
- chat_id: string;
398
- values: { [key: string]: string };
399
- };
400
-
401
- export type BroadcastMessagePayload = SendMessageContent & {
402
- chat_ids: string[];
403
- broadcast_id?: string;
404
- variables?: BroadcastVariableType[];
405
- delay?: number;
406
- };
407
-
408
- export type SingleMessagePayload = SendMessageContent & {
409
- chat_id: string;
410
- job_id?: string;
411
- priority?: number;
412
- };
413
-
414
- export type MessageAttachmentFileTypes =
415
- | 'image'
416
- | 'audio'
417
- | 'document'
418
- | 'video';
419
-
420
- export type AttachmentFileType = {
421
- result: string;
422
- file: File | null;
423
- type: MessageAttachmentFileTypes;
424
- localFileURL?: string;
425
- };
426
-
427
- export type AttachmentLinkType = {
428
- link: {
429
- url: string;
430
- type: MessageAttachmentFileTypes;
431
- name: string;
432
- mimetype?: string;
433
- };
434
- };
435
-
436
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
437
-
438
- /* -------------------------------- BROADCAST ------------------------------- */
439
-
440
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
441
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
442
- } & {
443
- chats: ChatType[];
444
- };
445
-
446
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
447
-
448
- export type ChatLogType = {
449
- log: Tables<'view_chat_logs'>;
450
- operations: Tables<'tbl_chat_logs'>[];
451
- };
452
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
453
-
454
- export type ChatParticipantOperationPayload = {
455
- participant_ids: string[];
456
- chat_ids: string[];
457
- performed_by: string;
458
- };
459
-
460
- export type ChatOperationReturn = {
461
- [participant_id: string]: {
462
- is_success: boolean;
463
- message?: string;
464
- code?: number;
465
- isInviteV4Sent?: boolean;
466
- };
467
- };
468
-
469
- /* ----------------------- BILLING - STRIPE ----------------------- */
470
-
471
- export type StripeSubscription = _Stripe.Subscription;
472
- export type StripeCustomer = _Stripe.Customer;
473
- export type StripeCoupon = _Stripe.Coupon;
474
- export type StripePrice = _Stripe.Price;
475
- export type Stripe = _Stripe;
476
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
477
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
478
-
479
- /* -------------------------------- REALTIME -------------------------------- */
480
-
481
- export type PhoneStateType = {
482
- loading: boolean;
483
- state: string;
484
- sync: number;
485
- percent: number | null;
486
- message?: string;
487
- error?: string;
488
- };
489
-
490
- /* ------------------------------- INTEGRATIONS ----------------------------- */
491
-
492
- export type ChatInfoType = Merge<
493
- ChatType,
494
- {
495
- members: {
496
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
497
- } | null;
498
- chat_labels: string | null;
499
- custom_properties: { [key: string]: string } | null;
500
- }
501
- >;
502
-
503
- export type TicketInfoType = {
504
- chat: ChatInfoType;
505
- message: {
506
- body: string;
507
- chat_id: string;
508
- org_phone: string;
509
- timestamp: string;
510
- media_path: string;
511
- message_id: string;
512
- sender_name: string;
513
- performed_by: string;
514
- sender_phone: string;
515
- };
516
- ticket: {
517
- org_id: string;
518
- status: string;
519
- subject: string;
520
- assignee: string;
521
- due_date: string;
522
- priority: 0 | 1 | 2 | 3 | 4;
523
- raised_by: string;
524
- ticket_id: string;
525
- created_at: string;
526
- assigned_by: string;
527
- ticket_labels: string;
528
- quoted_message_id: string;
529
- ticket_custom_properties: { [key: string]: string } | null;
530
- };
531
- attached_messages: {
532
- body: string;
533
- chat_id: string;
534
- org_phone: string;
535
- timestamp: string;
536
- media_path: string;
537
- message_id: string;
538
- sender_name: string;
539
- performed_by: string;
540
- sender_phone: string;
541
- }[];
542
- };
543
-
544
- export type IntegrationLogObjectType =
545
- | 'chat'
546
- | 'message'
547
- | 'reaction'
548
- | 'ticket';
549
-
550
- export enum IntegrationLogType {
551
- NEW_CHAT = 'chat.created',
552
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
553
- NEW_MESSAGE = 'message.created',
554
- MESSAGE_UPDATED = 'message.updated',
555
- MESSAGE_DELETED = 'message.deleted',
556
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
557
- REACTION_CREATED = 'reaction.created',
558
- REACTION_UPDATED = 'reaction.updated',
559
- NEW_TICKET = 'ticket.created',
560
- TICKET_UPDATED = 'ticket.updated',
561
- TICKET_DELETED = 'ticket.deleted',
562
- MESSAGE_FLAGGED = 'message.flagged',
563
- MESSAGE_UNFLAGGED = 'message.unflagged',
564
- }
565
-
566
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
567
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
568
- ? TicketInfoType
569
- : T extends IntegrationLogType.NEW_CHAT
570
- ? Tables<'tbl_chats'>
571
- : T extends
572
- | IntegrationLogType.NEW_MESSAGE
573
- | IntegrationLogType.MESSAGE_UPDATED
574
- | IntegrationLogType.MESSAGE_DELETED
575
- | IntegrationLogType.MESSAGE_ACK_UPDATED
576
- | IntegrationLogType.MESSAGE_FLAGGED
577
- | IntegrationLogType.MESSAGE_UNFLAGGED
578
- ? Tables<'tbl_chat_messages'>
579
- : T extends
580
- | IntegrationLogType.REACTION_CREATED
581
- | IntegrationLogType.REACTION_UPDATED
582
- ? Tables<'tbl_chat_reactions'>
583
- : {
584
- [key: string]: unknown;
585
- };
586
-
587
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
588
- OverrideProperties<
589
- Tables<'tbl_integration_logs'>,
590
- {
591
- integration_name: T;
592
- metadata: {
593
- event: IntegrationLogMetadataType<T> & {
594
- event_type: string;
595
- org_id: string;
596
- previous_attributes: {
597
- [key: string]: unknown;
598
- };
599
- };
600
- hook_id: string;
601
- name: string;
602
- };
603
- }
604
- >;
605
-
606
- export type APIAuthDetails = {
607
- org_details: Tables<'view_org'> | null;
608
- phone_details: Tables<'tbl_org_phones'> | null;
609
- token_details: Tables<'tbl_integration_tokens'> | null;
610
- };
611
-
612
- export type WebhookDataType = OverrideProperties<
613
- Tables<'tbl_integration_hooks'>,
614
- {
615
- integration_name: string[];
616
- }
617
- >;
618
-
619
- export type HubspotObjectDataType = {
620
- createdAt: string;
621
- archived: boolean;
622
- id: string;
623
- type: 'contacts' | 'tickets' | 'companies';
624
- properties: Record<
625
- string,
626
- {
627
- groupLabel: string;
628
- groupName: string;
629
- propertyKeyName: string;
630
- propertyKey: string;
631
- propertyInternalValue: string;
632
- propertyValue: string;
633
- propertyType: string;
634
- propertyFieldType: string;
635
- }[]
636
- >;
637
- };
638
-
639
- /* ---------------------------- USER PREFERENCES ---------------------------- */
640
-
641
- export type UserPreferences = {
642
- theme: 'light' | 'dark';
643
- language: 'en' | 'es';
644
- left_sidebar_open: boolean;
645
- right_sidepanel_open: boolean;
646
- sync_wa_unread_count: boolean;
647
- pinned_chats: string[];
648
- archived_chats: string[];
649
- closed_chats: Record<string, number>;
650
- periskope_chat_limit: number;
651
- notifications: Record<string, boolean>;
652
- };
653
-
654
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
655
-
656
- export type PollSendType = {
657
- pollName: string;
658
- pollOptions: string[];
659
- options?: {
660
- allowMultipleAnswers?: boolean;
661
- messageSecret?: number[] | null;
662
- pollId?: string;
663
- };
664
- };
665
-
666
- export type PollResultType = {
667
- [name: string]: Record<string, string>;
668
- };
669
-
670
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
671
-
672
- export type CreateGroupOptions = {
673
- messagesAdminsOnly?: boolean;
674
- infoAdminsOnly?: boolean;
675
- addMembersAdminsOnly?: boolean;
676
- image?: string;
677
- name?: string;
678
- description?: string;
679
- initiated_by?: string;
680
- };
681
-
682
- /* ------------------------------ DELIVERY INFO ----------------------------- */
683
-
684
- export type DeliveryInfoType = {
685
- delivered: Record<string, number | undefined>;
686
- read: Record<string, number | undefined>;
687
- pending: string[];
688
- read_count: number;
689
- delivered_count: number;
690
- };
691
-
692
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
693
-
694
- export type OrgCreditsType = {
695
- org_id: string;
696
- recurring_allowance: number; // recurring credits replenished every month
697
- recurring_balance: number; // recurring credits remaining in current month
698
- topup_balance: number; // topup credits remaining
699
- total_credits_used: number; // total credits used in current month
700
- next_renewal_date: string;
701
- };
702
-
703
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
704
-
705
- export type ChatRuleInfoType = Merge<
706
- Pick<
707
- Tables<'view_chats'>,
708
- | 'assigned_to'
709
- | 'chat_id'
710
- | 'chat_name'
711
- | 'chat_type'
712
- | 'created_at'
713
- | 'group_description'
714
- | 'info_admins_only'
715
- | 'org_id'
716
- | 'org_phone'
717
- | 'chat_org_phones'
718
- | 'messages_admins_only'
719
- | 'custom_properties'
720
- >,
721
- {
722
- has_flagged_messages: boolean;
723
- labels: string[];
724
- members: string[];
725
- custom_properties: { [key: string]: string } | null;
726
- }
727
- >;
728
-
729
- export type SenderRuleInfoType = Merge<
730
- Omit<
731
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
732
- | 'verified_name'
733
- | 'verified_level'
734
- | 'updated_at'
735
- | 'short_name'
736
- | 'pushname'
737
- | 'periskope_name'
738
- | 'org_phone'
739
- | 'number'
740
- | 'name'
741
- | 'label_ids'
742
- | 'is_wa_contact'
743
- | 'is_user'
744
- | 'is_my_contact'
745
- | 'is_me'
746
- | 'is_imported'
747
- | 'is_group'
748
- | 'is_blocked'
749
- | 'contact_color'
750
- | 'business_profile'
751
- | 'id'
752
- | 'contact_image'
753
- | 'contact_type'
754
- | 'chat_id'
755
- | 'is_business'
756
- | 'is_enterprise'
757
- | 'is_super_admin'
758
- >,
759
- {
760
- is_internal: boolean;
761
- labels: string[] | null;
762
- }
763
- >;
764
-
765
- export type MessageRuleInfoType = {
766
- chat: ChatRuleInfoType;
767
- sender: SenderRuleInfoType;
768
- message: OverrideProperties<
769
- Omit<
770
- Tables<'tbl_chat_messages'>,
771
- | 'vcards'
772
- | 'updated_at'
773
- | 'unique_id'
774
- | 'token'
775
- | 'to'
776
- | 'sent_message_id'
777
- | 'raw_data'
778
- | 'delivery_info'
779
- | 'poll_results'
780
- | 'poll_info'
781
- | 'order_id'
782
- | 'mentioned_ids'
783
- | 'media_key'
784
- | 'location'
785
- | 'links'
786
- | 'is_status'
787
- | 'is_starred'
788
- | 'is_gif'
789
- | 'is_forwarded'
790
- | 'is_ephemeral'
791
- | 'is_deleted'
792
- | 'fts'
793
- | 'quoted_message_id'
794
- | 'invite_v4'
795
- | 'id'
796
- | 'has_reaction'
797
- | 'has_media'
798
- | 'duration'
799
- | 'broadcast'
800
- | 'broadcast_id'
801
- | 'device_type'
802
- | 'forwarding_score'
803
- | 'from'
804
- | 'from_me'
805
- | 'prev_body'
806
- | 'flag_response_time'
807
- | 'flag_metadata'
808
- | 'ack'
809
- >,
810
- {
811
- media: MediaType | null;
812
- }
813
- >;
814
- };
815
-
816
- export type ReactionRuleInfoType = {
817
- chat: ChatRuleInfoType;
818
- sender: SenderRuleInfoType;
819
- message: MessageRuleInfoType['message'];
820
- reaction: Pick<
821
- Tables<'tbl_chat_reactions'>,
822
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
823
- >;
824
- };
825
-
826
- export type TicketRuleInfoType = {
827
- chat: ChatRuleInfoType;
828
- sender: SenderRuleInfoType;
829
- ticket: Merge<
830
- Pick<
831
- Tables<'tbl_chat_tickets'>,
832
- | 'org_id'
833
- | 'status'
834
- | 'chat_id'
835
- | 'subject'
836
- | 'assignee'
837
- | 'due_date'
838
- | 'priority'
839
- | 'raised_by'
840
- | 'ticket_id'
841
- | 'created_at'
842
- | 'is_deleted'
843
- >,
844
- {
845
- labels: string[] | null;
846
- custom_properties: { [key: string]: string } | null;
847
- }
848
- >;
849
- message: MessageRuleInfoType['message'];
850
- };
851
- export type FeatureFlagReturnType = Record<string, boolean>;
852
-
853
- export type RuleLogsType = OverrideProperties<
854
- Tables<'tbl_rules_logs'>,
855
- {
856
- actions_progress: {
857
- action_id: string;
858
- action_type: Rule['actions'][number]['type'];
859
- action_delay: Rule['actions'][number]['delay'];
860
- ran_at: string | null;
861
- action_status: 'success' | 'failed' | 'pending';
862
- action_response: {
863
- success: boolean;
864
- data: Record<string, unknown> | null;
865
- error: {
866
- message: string;
867
- name: string;
868
- stack?: string;
869
- _error?: Error | Record<string, unknown>;
870
- } | null;
871
- };
872
- }[];
873
- metadata: {
874
- conditions: Rule['conditions'];
875
- actions: Rule['actions'];
876
- data: Record<string, unknown>;
877
- };
878
- conditions_progress: {
879
- is_valid: boolean;
880
- validation_progress: Record<
881
- string,
882
- {
883
- res: boolean;
884
- filter: Filter;
885
- value: unknown;
886
- }
887
- >;
888
- checked_at: string | null;
889
- };
890
- }
891
- >;
892
-
893
- /************************** TASKS ***************************/
894
-
895
- export type TaskType = OverrideProperties<
896
- Tables<'tbl_org_tasks'>,
897
- {
898
- reminder_setting: {
899
- remind_in:
900
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
901
- | string
902
- | null;
903
- repeat?: {
904
- frequency: number;
905
- interval: 'days' | 'weeks' | 'months' | 'years';
906
- end: 'never' | 'after' | 'on';
907
- on?: string;
908
- };
909
- } | null;
910
- associated_object_metadata:
911
- | {
912
- type: 'chat';
913
- index: 'chat_id';
914
- id: string;
915
- object: ChatType;
916
- }
917
- | {
918
- type: 'message';
919
- index: 'message_id';
920
- id: string;
921
- object: MessageType;
922
- }
923
- | {
924
- type: 'ticket';
925
- index: 'ticket_id';
926
- id: string;
927
- object: TicketType;
928
- }
929
- | null;
930
- status: 'open' | 'inprogress' | 'closed';
931
- priority: 1 | 2 | 3;
932
- completed_metadata?: {
933
- completed_at: string;
934
- completed_by: string;
935
- } | null;
936
- type: 'todo' | 'chat' | 'message' | 'ticket';
937
- }
938
- >;
939
-
940
- type Choice = {
941
- id: number;
942
- label: string;
943
- value: string;
944
- position: number;
945
- };
946
-
947
- export type FreshdeskCustomFieldType = {
948
- id: number;
949
- name: string;
950
- label: string;
951
- position: number;
952
- required_for_agents: boolean;
953
- archived: boolean;
954
- customers_can_edit: boolean;
955
- label_for_customers: string;
956
- required_for_customers: boolean;
957
- customers_can_filter: boolean;
958
- required_for_closure: boolean;
959
- displayed_to_customers: boolean;
960
- type: string;
961
- default: boolean;
962
- created_at: string;
963
- updated_at: string;
964
- choices?: Choice[];
965
- };
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 OrgMetadata = {
82
+ phone_number: string;
83
+ ticket_prefix: string;
84
+ referralSource?: string;
85
+ surveyData?: MicrosurveyData;
86
+ preferences?: OrgPreferences;
87
+ hubspot: {
88
+ hubspot_pipelines?: {
89
+ id: string;
90
+ label: string;
91
+ default_stage: { id: string; label: string };
92
+ }[];
93
+ hubspot_hidden_fields?: string[];
94
+ };
95
+ partition?: boolean;
96
+ tickets: {
97
+ prefix?: string;
98
+ emoji_ticketing: {
99
+ is_enabled?: boolean;
100
+ is_message_enabled?: boolean;
101
+ message_template?: string;
102
+ };
103
+ };
104
+ attribution?: Object;
105
+ affiliate_id?: string;
106
+ custom_properties?: {
107
+ chats_order?: {
108
+ [id: string]: number;
109
+ };
110
+ tickets_order?: {
111
+ [id: string]: number;
112
+ };
113
+ };
114
+ rules?: {
115
+ limit?: number;
116
+ };
117
+ ai?: {
118
+ flag_prompt?: string;
119
+ };
120
+ };
121
+
122
+ type AccessScopes = {
123
+ feature_flags: Record<string, boolean>;
124
+ integrations: boolean;
125
+ rules: boolean;
126
+ exports: boolean;
127
+ };
128
+
129
+ export type OrgType = OverrideProperties<
130
+ Merge<
131
+ Tables<'tbl_org'>,
132
+ {
133
+ user: Tables<'tbl_org_members'>;
134
+ members: Tables<'tbl_org_members'>[];
135
+ phones: Tables<'tbl_org_phones'>[];
136
+ labels: Tables<'tbl_org_labels'>[];
137
+ quick_replies: Tables<'tbl_quick_replies'>[];
138
+ custom_properties: Tables<'tbl_custom_properties'>[];
139
+ subscription_status: 'active' | 'inactive' | 'unpaid';
140
+ is_enterprise: boolean;
141
+ is_free_trial: boolean;
142
+ is_hubspot_connected: boolean;
143
+ is_freshdesk_connected: boolean;
144
+ is_zohodesk_connected: boolean;
145
+ access_scopes: AccessScopes;
146
+ rules: Rule[];
147
+ }
148
+ >,
149
+ {
150
+ org_plan: OrgPlan<AllPlans | Enterprise>;
151
+ stripe_customer_details: _Stripe.Customer | null;
152
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
153
+ stripe_customer_id: _Stripe.Customer['id'] | null;
154
+ org_metadata: OrgMetadata;
155
+ }
156
+ >;
157
+
158
+ export type ChatMemberType = Merge<
159
+ Tables<'tbl_chat_participants'>,
160
+ Tables<'tbl_contacts'>
161
+ >;
162
+
163
+ export type ChatType = Merge<
164
+ Tables<'view_chats'>,
165
+ {
166
+ chat_id: string;
167
+ latest_message: MessageType | null;
168
+ latest_message_timestamp: number | null;
169
+ members: { [key: string]: ChatMemberType } | null;
170
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
171
+ chat_access: { [key: string]: boolean };
172
+ label_ids: { [key: string]: boolean };
173
+ chat_org_phones?: string[];
174
+ message_unread_count: number | null;
175
+ hubspot_metadata: {
176
+ id: string;
177
+ type: string;
178
+ hubId: string;
179
+ object_data: HubspotObjectDataType;
180
+ } | null;
181
+ info_admins_only: boolean;
182
+ messages_admins_only: boolean;
183
+ unread_count?: { [key: string]: number };
184
+ active_phone: string | null;
185
+ flag_count_map?: { [key: string]: number };
186
+ is_archived?: boolean;
187
+ is_pinned?: boolean;
188
+ closed_at?: number | null;
189
+ common_chats?: string[];
190
+ freshdesk_metadata?: Record<string, any>;
191
+ zohodesk_metadata?: Record<string, any>;
192
+ pinned_messages?: Record<string, number>;
193
+ }
194
+ >;
195
+
196
+ /* -------------------------------------------------------------------------- */
197
+ /* MESSAGE */
198
+ /* -------------------------------------------------------------------------- */
199
+
200
+ export type MediaType = {
201
+ path?: string;
202
+ mimetype?: string;
203
+ filename?: string;
204
+ dimensions?: { width: number; height: number; ar: number };
205
+ size?: number;
206
+ thumbnail?: string;
207
+ filedata?: string;
208
+ compress?: boolean;
209
+ };
210
+
211
+ export type MessageType = Merge<
212
+ OverrideProperties<
213
+ TablesInsert<'tbl_chat_messages'>,
214
+ {
215
+ message_id: string;
216
+ org_id: string;
217
+ org_phone: string;
218
+ chat_id: string;
219
+ message_type: (typeof SUPPORTED_TYPES)[number];
220
+ media: MediaType | null;
221
+ flag_metadata?: MessageFlagType | null;
222
+ poll_info?: PollSendType | null;
223
+ poll_results?: PollResultType | null;
224
+ delivery_info?: DeliveryInfoType | null;
225
+ }
226
+ >,
227
+ {
228
+ reactions?: ReactionType[];
229
+ message_payload?: SingleMessagePayload;
230
+ highlight?: number;
231
+ is_private_note?: boolean;
232
+ }
233
+ >;
234
+
235
+ export type MessageFlagType = {
236
+ status: boolean;
237
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
238
+ response_id?: string;
239
+ response_timestamp?: string;
240
+ response_email?: string;
241
+ };
242
+
243
+ /* -------------------------------------------------------------------------- */
244
+
245
+ export type TicketType = OverrideProperties<
246
+ Tables<'tbl_chat_tickets'>,
247
+ {
248
+ label_ids: { [key: string]: boolean };
249
+ hubspot_metadata: {
250
+ id?: string;
251
+ type?: string;
252
+ hubId?: string;
253
+ pipeline: {
254
+ id: string;
255
+ label: string;
256
+ };
257
+ object_data?: HubspotObjectDataType;
258
+ } | null;
259
+ freshdesk_metadata: Record<string, string>;
260
+ close_ticket_metadata?:
261
+ | {
262
+ closed_by: string;
263
+ closed_at: string;
264
+ closed_message?: string | null;
265
+ send_reply_message_id?: string | null;
266
+ }
267
+ | any;
268
+ }
269
+ >;
270
+
271
+ export type ContactType = Merge<
272
+ Tables<'tbl_contacts'>,
273
+ {
274
+ chats: ChatType[] | null;
275
+ chat_ids?: string[];
276
+ }
277
+ >;
278
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
279
+
280
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
281
+
282
+ export type ChatAccessType = Merge<
283
+ TablesUpdate<'tbl_org_members'>,
284
+ {
285
+ has_access?: boolean;
286
+ email: string | null;
287
+ }
288
+ >;
289
+
290
+ export type PhoneQueueStatusType = {
291
+ active: number;
292
+ failed: number;
293
+ completed: number;
294
+ is_running: boolean;
295
+ pending: number;
296
+ };
297
+
298
+ export type PhoneType = OverrideProperties<
299
+ Tables<'tbl_org_phones'>,
300
+ {
301
+ queue_status: {
302
+ [key: string]: PhoneQueueStatusType;
303
+ };
304
+ }
305
+ >;
306
+
307
+ /* -------------------------------- CONSTANTS ------------------------------- */
308
+
309
+ export const labelColors = [
310
+ '#9333EA',
311
+ '#0D9488',
312
+ '#DB2777',
313
+ '#2563EB',
314
+ '#F97316',
315
+ ];
316
+
317
+ export const enumChatColors = [
318
+ '#B4876E',
319
+ '#A5B337',
320
+ '#06CF9C',
321
+ '#25D366',
322
+ '#02A698',
323
+ '#7D9EF1',
324
+ '#007BFC',
325
+ '#5E47DE',
326
+ '#7F66FF',
327
+ '#9333EA',
328
+ '#FA6533',
329
+ '#C4532D',
330
+ '#DC2626',
331
+ '#FF2E74',
332
+ '#DB2777',
333
+ ] as const;
334
+
335
+ export type RepeatDaysType =
336
+ | 'monday'
337
+ | 'tuesday'
338
+ | 'wednesday'
339
+ | 'thursday'
340
+ | 'friday'
341
+ | 'saturday'
342
+ | 'sunday';
343
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
344
+
345
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
346
+
347
+ export const SUPPORTED_TYPES = [
348
+ 'chat',
349
+ 'sticker',
350
+ 'image',
351
+ 'video',
352
+ 'document',
353
+ 'vcard',
354
+ 'multi_vcard',
355
+ 'audio',
356
+ 'ptt',
357
+ 'poll_creation',
358
+ 'location',
359
+ 'ciphertext',
360
+ ] as const;
361
+
362
+ export type SendMessageContent = {
363
+ message_type?: (typeof SUPPORTED_TYPES)[number];
364
+ body?: string;
365
+ media?: MediaType;
366
+ contact_ids?: string[];
367
+ location?: {
368
+ latitude: string;
369
+ longitude: string;
370
+ options?: { name?: string; address?: string; url?: string };
371
+ };
372
+ poll?: PollSendType;
373
+ quoted_message_id?: string;
374
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
375
+ broadcast_id?: string;
376
+ performed_by?: string;
377
+ };
378
+
379
+ export type QuickReplyContent = Omit<
380
+ SendMessageContent,
381
+ 'broadcast_id' | 'variables'
382
+ >;
383
+
384
+ export type ScheduleMessagePayload = {
385
+ scheduled_id?: string;
386
+ is_repeat?: boolean | null;
387
+ scheduled_at: string;
388
+ repeat_config?: {
389
+ repeat_ends?: string;
390
+ repeat_interval?: RepeatIntervalType;
391
+ repeat_value?: number;
392
+ repeat_days?: RepeatDaysType[];
393
+ };
394
+ };
395
+
396
+ export type BroadcastVariableType = {
397
+ chat_id: string;
398
+ values: { [key: string]: string };
399
+ };
400
+
401
+ export type BroadcastMessagePayload = SendMessageContent & {
402
+ chat_ids: string[];
403
+ broadcast_id?: string;
404
+ variables?: BroadcastVariableType[];
405
+ delay?: number;
406
+ };
407
+
408
+ export type SingleMessagePayload = SendMessageContent & {
409
+ chat_id: string;
410
+ job_id?: string;
411
+ priority?: number;
412
+ };
413
+
414
+ export type MessageAttachmentFileTypes =
415
+ | 'image'
416
+ | 'audio'
417
+ | 'document'
418
+ | 'video';
419
+
420
+ export type AttachmentFileType = {
421
+ result: string;
422
+ file: File | null;
423
+ type: MessageAttachmentFileTypes;
424
+ localFileURL?: string;
425
+ };
426
+
427
+ export type AttachmentLinkType = {
428
+ link: {
429
+ url: string;
430
+ type: MessageAttachmentFileTypes;
431
+ name: string;
432
+ mimetype?: string;
433
+ };
434
+ };
435
+
436
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
437
+
438
+ /* -------------------------------- BROADCAST ------------------------------- */
439
+
440
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
441
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
442
+ } & {
443
+ chats: ChatType[];
444
+ };
445
+
446
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
447
+
448
+ export type ChatLogType = {
449
+ log: Tables<'view_chat_logs'>;
450
+ operations: Tables<'tbl_chat_logs'>[];
451
+ };
452
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
453
+
454
+ export type ChatParticipantOperationPayload = {
455
+ participant_ids: string[];
456
+ chat_ids: string[];
457
+ performed_by: string;
458
+ };
459
+
460
+ export type ChatOperationReturn = {
461
+ [participant_id: string]: {
462
+ is_success: boolean;
463
+ message?: string;
464
+ code?: number;
465
+ isInviteV4Sent?: boolean;
466
+ };
467
+ };
468
+
469
+ /* ----------------------- BILLING - STRIPE ----------------------- */
470
+
471
+ export type StripeSubscription = _Stripe.Subscription;
472
+ export type StripeCustomer = _Stripe.Customer;
473
+ export type StripeCoupon = _Stripe.Coupon;
474
+ export type StripePrice = _Stripe.Price;
475
+ export type Stripe = _Stripe;
476
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
477
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
478
+
479
+ /* -------------------------------- REALTIME -------------------------------- */
480
+
481
+ export type PhoneStateType = {
482
+ loading: boolean;
483
+ state: string;
484
+ sync: number;
485
+ percent: number | null;
486
+ message?: string;
487
+ error?: string;
488
+ };
489
+
490
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
491
+
492
+ export type ChatInfoType = Merge<
493
+ ChatType,
494
+ {
495
+ members: {
496
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
497
+ } | null;
498
+ chat_labels: string | null;
499
+ custom_properties: { [key: string]: string } | null;
500
+ }
501
+ >;
502
+
503
+ export type TicketInfoType = {
504
+ chat: ChatInfoType;
505
+ message: {
506
+ body: string;
507
+ chat_id: string;
508
+ org_phone: string;
509
+ timestamp: string;
510
+ media_path: string;
511
+ message_id: string;
512
+ sender_name: string;
513
+ performed_by: string;
514
+ sender_phone: string;
515
+ };
516
+ ticket: {
517
+ org_id: string;
518
+ status: string;
519
+ subject: string;
520
+ assignee: string;
521
+ due_date: string;
522
+ priority: 0 | 1 | 2 | 3 | 4;
523
+ raised_by: string;
524
+ ticket_id: string;
525
+ created_at: string;
526
+ assigned_by: string;
527
+ ticket_labels: string;
528
+ quoted_message_id: string;
529
+ ticket_custom_properties: { [key: string]: string } | null;
530
+ };
531
+ attached_messages: {
532
+ body: string;
533
+ chat_id: string;
534
+ org_phone: string;
535
+ timestamp: string;
536
+ media_path: string;
537
+ message_id: string;
538
+ sender_name: string;
539
+ performed_by: string;
540
+ sender_phone: string;
541
+ }[];
542
+ };
543
+
544
+ export type IntegrationLogObjectType =
545
+ | 'chat'
546
+ | 'message'
547
+ | 'reaction'
548
+ | 'ticket';
549
+
550
+ export enum IntegrationLogType {
551
+ NEW_CHAT = 'chat.created',
552
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
553
+ NEW_MESSAGE = 'message.created',
554
+ MESSAGE_UPDATED = 'message.updated',
555
+ MESSAGE_DELETED = 'message.deleted',
556
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
557
+ REACTION_CREATED = 'reaction.created',
558
+ REACTION_UPDATED = 'reaction.updated',
559
+ NEW_TICKET = 'ticket.created',
560
+ TICKET_UPDATED = 'ticket.updated',
561
+ TICKET_DELETED = 'ticket.deleted',
562
+ MESSAGE_FLAGGED = 'message.flagged',
563
+ MESSAGE_UNFLAGGED = 'message.unflagged',
564
+ }
565
+
566
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
567
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
568
+ ? TicketInfoType
569
+ : T extends IntegrationLogType.NEW_CHAT
570
+ ? Tables<'tbl_chats'>
571
+ : T extends
572
+ | IntegrationLogType.NEW_MESSAGE
573
+ | IntegrationLogType.MESSAGE_UPDATED
574
+ | IntegrationLogType.MESSAGE_DELETED
575
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
576
+ | IntegrationLogType.MESSAGE_FLAGGED
577
+ | IntegrationLogType.MESSAGE_UNFLAGGED
578
+ ? Tables<'tbl_chat_messages'>
579
+ : T extends
580
+ | IntegrationLogType.REACTION_CREATED
581
+ | IntegrationLogType.REACTION_UPDATED
582
+ ? Tables<'tbl_chat_reactions'>
583
+ : {
584
+ [key: string]: unknown;
585
+ };
586
+
587
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
588
+ OverrideProperties<
589
+ Tables<'tbl_integration_logs'>,
590
+ {
591
+ integration_name: T;
592
+ metadata: {
593
+ event: IntegrationLogMetadataType<T> & {
594
+ event_type: string;
595
+ org_id: string;
596
+ previous_attributes: {
597
+ [key: string]: unknown;
598
+ };
599
+ };
600
+ hook_id: string;
601
+ name: string;
602
+ };
603
+ }
604
+ >;
605
+
606
+ export type APIAuthDetails = {
607
+ org_details: Tables<'view_org'> | null;
608
+ phone_details: Tables<'tbl_org_phones'> | null;
609
+ token_details: Tables<'tbl_integration_tokens'> | null;
610
+ };
611
+
612
+ export type WebhookDataType = OverrideProperties<
613
+ Tables<'tbl_integration_hooks'>,
614
+ {
615
+ integration_name: string[];
616
+ }
617
+ >;
618
+
619
+ export type HubspotObjectDataType = {
620
+ createdAt: string;
621
+ archived: boolean;
622
+ id: string;
623
+ type: 'contacts' | 'tickets' | 'companies';
624
+ properties: Record<
625
+ string,
626
+ {
627
+ groupLabel: string;
628
+ groupName: string;
629
+ propertyKeyName: string;
630
+ propertyKey: string;
631
+ propertyInternalValue: string;
632
+ propertyValue: string;
633
+ propertyType: string;
634
+ propertyFieldType: string;
635
+ }[]
636
+ >;
637
+ };
638
+
639
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
640
+
641
+ export type UserPreferences = {
642
+ theme: 'light' | 'dark';
643
+ language: 'en' | 'es';
644
+ left_sidebar_open: boolean;
645
+ right_sidepanel_open: boolean;
646
+ sync_wa_unread_count: boolean;
647
+ pinned_chats: string[];
648
+ archived_chats: string[];
649
+ closed_chats: Record<string, number>;
650
+ periskope_chat_limit: number;
651
+ notifications: Record<string, boolean>;
652
+ };
653
+
654
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
655
+
656
+ export type PollSendType = {
657
+ pollName: string;
658
+ pollOptions: string[];
659
+ options?: {
660
+ allowMultipleAnswers?: boolean;
661
+ messageSecret?: number[] | null;
662
+ pollId?: string;
663
+ };
664
+ };
665
+
666
+ export type PollResultType = {
667
+ [name: string]: Record<string, string>;
668
+ };
669
+
670
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
671
+
672
+ export type CreateGroupOptions = {
673
+ messagesAdminsOnly?: boolean;
674
+ infoAdminsOnly?: boolean;
675
+ addMembersAdminsOnly?: boolean;
676
+ image?: string;
677
+ name?: string;
678
+ description?: string;
679
+ initiated_by?: string;
680
+ };
681
+
682
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
683
+
684
+ export type DeliveryInfoType = {
685
+ delivered: Record<string, number | undefined>;
686
+ read: Record<string, number | undefined>;
687
+ pending: string[];
688
+ read_count: number;
689
+ delivered_count: number;
690
+ };
691
+
692
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
693
+
694
+ export type OrgCreditsType = {
695
+ org_id: string;
696
+ recurring_allowance: number; // recurring credits replenished every month
697
+ recurring_balance: number; // recurring credits remaining in current month
698
+ topup_balance: number; // topup credits remaining
699
+ total_credits_used: number; // total credits used in current month
700
+ next_renewal_date: string;
701
+ };
702
+
703
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
704
+
705
+ export type ChatRuleInfoType = Merge<
706
+ Pick<
707
+ Tables<'view_chats'>,
708
+ | 'assigned_to'
709
+ | 'chat_id'
710
+ | 'chat_name'
711
+ | 'chat_type'
712
+ | 'created_at'
713
+ | 'group_description'
714
+ | 'info_admins_only'
715
+ | 'org_id'
716
+ | 'org_phone'
717
+ | 'chat_org_phones'
718
+ | 'messages_admins_only'
719
+ | 'custom_properties'
720
+ >,
721
+ {
722
+ has_flagged_messages: boolean;
723
+ labels: string[];
724
+ members: string[];
725
+ custom_properties: { [key: string]: string } | null;
726
+ }
727
+ >;
728
+
729
+ export type SenderRuleInfoType = Merge<
730
+ Omit<
731
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
732
+ | 'verified_name'
733
+ | 'verified_level'
734
+ | 'updated_at'
735
+ | 'short_name'
736
+ | 'pushname'
737
+ | 'periskope_name'
738
+ | 'org_phone'
739
+ | 'number'
740
+ | 'name'
741
+ | 'label_ids'
742
+ | 'is_wa_contact'
743
+ | 'is_user'
744
+ | 'is_my_contact'
745
+ | 'is_me'
746
+ | 'is_imported'
747
+ | 'is_group'
748
+ | 'is_blocked'
749
+ | 'contact_color'
750
+ | 'business_profile'
751
+ | 'id'
752
+ | 'contact_image'
753
+ | 'contact_type'
754
+ | 'chat_id'
755
+ | 'is_business'
756
+ | 'is_enterprise'
757
+ | 'is_super_admin'
758
+ >,
759
+ {
760
+ is_internal: boolean;
761
+ labels: string[] | null;
762
+ }
763
+ >;
764
+
765
+ export type MessageRuleInfoType = {
766
+ chat: ChatRuleInfoType;
767
+ sender: SenderRuleInfoType;
768
+ message: OverrideProperties<
769
+ Omit<
770
+ Tables<'tbl_chat_messages'>,
771
+ | 'vcards'
772
+ | 'updated_at'
773
+ | 'unique_id'
774
+ | 'token'
775
+ | 'to'
776
+ | 'sent_message_id'
777
+ | 'raw_data'
778
+ | 'delivery_info'
779
+ | 'poll_results'
780
+ | 'poll_info'
781
+ | 'order_id'
782
+ | 'mentioned_ids'
783
+ | 'media_key'
784
+ | 'location'
785
+ | 'links'
786
+ | 'is_status'
787
+ | 'is_starred'
788
+ | 'is_gif'
789
+ | 'is_forwarded'
790
+ | 'is_ephemeral'
791
+ | 'is_deleted'
792
+ | 'fts'
793
+ | 'quoted_message_id'
794
+ | 'invite_v4'
795
+ | 'id'
796
+ | 'has_reaction'
797
+ | 'has_media'
798
+ | 'duration'
799
+ | 'broadcast'
800
+ | 'broadcast_id'
801
+ | 'device_type'
802
+ | 'forwarding_score'
803
+ | 'from'
804
+ | 'from_me'
805
+ | 'prev_body'
806
+ | 'flag_response_time'
807
+ | 'flag_metadata'
808
+ | 'ack'
809
+ >,
810
+ {
811
+ media: MediaType | null;
812
+ }
813
+ >;
814
+ };
815
+
816
+ export type ReactionRuleInfoType = {
817
+ chat: ChatRuleInfoType;
818
+ sender: SenderRuleInfoType;
819
+ message: MessageRuleInfoType['message'];
820
+ reaction: Pick<
821
+ Tables<'tbl_chat_reactions'>,
822
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
823
+ >;
824
+ };
825
+
826
+ export type TicketRuleInfoType = {
827
+ chat: ChatRuleInfoType;
828
+ sender: SenderRuleInfoType;
829
+ ticket: Merge<
830
+ Pick<
831
+ Tables<'tbl_chat_tickets'>,
832
+ | 'org_id'
833
+ | 'status'
834
+ | 'chat_id'
835
+ | 'subject'
836
+ | 'assignee'
837
+ | 'due_date'
838
+ | 'priority'
839
+ | 'raised_by'
840
+ | 'ticket_id'
841
+ | 'created_at'
842
+ | 'is_deleted'
843
+ >,
844
+ {
845
+ labels: string[] | null;
846
+ custom_properties: { [key: string]: string } | null;
847
+ }
848
+ >;
849
+ message: MessageRuleInfoType['message'];
850
+ };
851
+ export type FeatureFlagReturnType = Record<string, boolean>;
852
+
853
+ export type RuleLogsType = OverrideProperties<
854
+ Tables<'tbl_rules_logs'>,
855
+ {
856
+ actions_progress: {
857
+ action_id: string;
858
+ action_type: Rule['actions'][number]['type'];
859
+ action_delay: Rule['actions'][number]['delay'];
860
+ ran_at: string | null;
861
+ action_status: 'success' | 'failed' | 'pending';
862
+ action_response: {
863
+ success: boolean;
864
+ data: Record<string, unknown> | null;
865
+ error: {
866
+ message: string;
867
+ name: string;
868
+ stack?: string;
869
+ _error?: Error | Record<string, unknown>;
870
+ } | null;
871
+ };
872
+ }[];
873
+ metadata: {
874
+ conditions: Rule['conditions'];
875
+ actions: Rule['actions'];
876
+ rule_metadata: Pick<
877
+ Rule,
878
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
879
+ >;
880
+ data: Record<string, unknown>;
881
+ };
882
+ conditions_progress: {
883
+ is_valid: boolean;
884
+ validation_progress: Record<
885
+ string,
886
+ {
887
+ res: boolean;
888
+ filter: Filter;
889
+ value: unknown;
890
+ }
891
+ >;
892
+ checked_at: string | null;
893
+ };
894
+ }
895
+ >;
896
+
897
+ /************************** TASKS ***************************/
898
+
899
+ export type TaskType = OverrideProperties<
900
+ Tables<'tbl_org_tasks'>,
901
+ {
902
+ reminder_setting: {
903
+ remind_in:
904
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
905
+ | string
906
+ | null;
907
+ repeat?: {
908
+ frequency: number;
909
+ interval: 'days' | 'weeks' | 'months' | 'years';
910
+ end: 'never' | 'after' | 'on';
911
+ on?: string;
912
+ };
913
+ } | null;
914
+ associated_object_metadata:
915
+ | {
916
+ type: 'chat';
917
+ index: 'chat_id';
918
+ id: string;
919
+ object: ChatType;
920
+ }
921
+ | {
922
+ type: 'message';
923
+ index: 'message_id';
924
+ id: string;
925
+ object: MessageType;
926
+ }
927
+ | {
928
+ type: 'ticket';
929
+ index: 'ticket_id';
930
+ id: string;
931
+ object: TicketType;
932
+ }
933
+ | null;
934
+ status: 'open' | 'inprogress' | 'closed';
935
+ priority: 1 | 2 | 3;
936
+ completed_metadata?: {
937
+ completed_at: string;
938
+ completed_by: string;
939
+ } | null;
940
+ type: 'todo' | 'chat' | 'message' | 'ticket';
941
+ }
942
+ >;
943
+
944
+ type Choice = {
945
+ id: number;
946
+ label: string;
947
+ value: string;
948
+ position: number;
949
+ };
950
+
951
+ export type FreshdeskCustomFieldType = {
952
+ id: number;
953
+ name: string;
954
+ label: string;
955
+ position: number;
956
+ required_for_agents: boolean;
957
+ archived: boolean;
958
+ customers_can_edit: boolean;
959
+ label_for_customers: string;
960
+ required_for_customers: boolean;
961
+ customers_can_filter: boolean;
962
+ required_for_closure: boolean;
963
+ displayed_to_customers: boolean;
964
+ type: string;
965
+ default: boolean;
966
+ created_at: string;
967
+ updated_at: string;
968
+ choices?: Choice[];
969
+ };