@periskope/types 0.6.205 → 0.6.206

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