@periskope/types 0.6.146 → 0.6.147

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/types.ts CHANGED
@@ -1,593 +1,752 @@
1
- import type { default as _Stripe } from 'stripe';
2
- import { Merge, OverrideProperties } from 'type-fest';
3
- import { Tables, TablesUpdate } from './supabase.types';
4
-
5
- /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
6
-
7
- /* ------------------------------ PERISKOPE TYPES ------------------------------ */
8
-
9
- export enum AllPlans {
10
- FREE_TRIAL = 'free-trial',
11
- // MONTHLY_STARTER = 'monthly-starter',
12
- // YEARLY_STARTER = 'yearly-starter',
13
- // MONTHLY_PRO = 'monthly-pro',
14
- // YEARLY_PRO = 'yearly-pro',
15
- ENTERPRISE = 'enterprise',
16
- MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
17
- YEARLY_STARTER_SINGLE = 'yearly-starter-single',
18
- MONTHLY_PRO_SINGLE = 'monthly-pro-single',
19
- YEARLY_PRO_SINGLE = 'yearly-pro-single',
20
- }
21
-
22
- export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
23
-
24
- export type Enterprise = `${string}-enterprise`;
25
-
26
- export type OrgPlanEnterprise = {
27
- subscription_id: string;
28
- plan_id: Enterprise;
29
- interval: number;
30
- frequency: Frequency;
31
- user_limit: number;
32
- phone_limit: number;
33
- current_period_start: number;
34
- current_period_end: number | null;
35
- };
36
-
37
- export type OrgPlanNonEnterprise = {
38
- subscription_id: string;
39
- plan_id: AllPlans;
40
- interval: number;
41
- frequency: Frequency;
42
- user_limit: number;
43
- phone_limit: number;
44
- current_period_end: number;
45
- current_period_start: number;
46
- };
47
-
48
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
49
- ? OrgPlanEnterprise
50
- : T extends AllPlans
51
- ? OrgPlanNonEnterprise
52
- : never;
53
-
54
- export type MicrosurveyData = {
55
- key: string;
56
- text: string;
57
- checked: boolean;
58
- }[];
59
-
60
- export type OrgPreferences = {
61
- disable_ai_flagging?: boolean;
62
- disable_allow_exports?: boolean;
63
- sync_phone_contacts?: boolean;
64
- mask_phone_numbers?: boolean;
65
- show_sender_names?: boolean;
66
- };
67
-
68
- type OrgPreferenceKey = keyof OrgPreferences;
69
-
70
- export type OrgPreferencesValue = {
71
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
72
- }[OrgPreferenceKey];
73
-
74
- export type OrgMetadata = {
75
- phone_number: string;
76
- ticket_prefix: string;
77
- referralSource?: string;
78
- surveyData?: MicrosurveyData;
79
- preferences?: OrgPreferences;
80
- hubspot_pipelines?: {
81
- id: string;
82
- label: string;
83
- default_stage: { id: string; label: string };
84
- }[];
85
- partition?: boolean;
86
- tickets: {
87
- prefix?: string;
88
- emoji_ticketing: {
89
- is_enabled?: boolean;
90
- is_message_enabled?: boolean;
91
- message_template?: string;
92
- }
93
- }
94
- };
95
-
96
- type AccessScopes = {
97
- integrations: boolean;
98
- exports: boolean;
99
- };
100
-
101
- export type OrgType = OverrideProperties<
102
- Merge<
103
- Tables<'tbl_org'>,
104
- {
105
- user: Tables<'tbl_org_members'>;
106
- members: Tables<'tbl_org_members'>[];
107
- phones: Tables<'tbl_org_phones'>[];
108
- labels: Tables<'tbl_org_labels'>[];
109
- quick_replies: Tables<'tbl_quick_replies'>[];
110
- custom_properties: Tables<'tbl_custom_properties'>[];
111
- subscription_status: 'active' | 'inactive' | 'unpaid';
112
- is_enterprise: boolean;
113
- is_free_trial: boolean;
114
- is_hubspot_connected: boolean;
115
- is_freshdesk_connected: boolean;
116
- is_zohodesk_connected: boolean;
117
- access_scopes: AccessScopes;
118
- }
119
- >,
120
- {
121
- org_plan: OrgPlan<AllPlans | Enterprise>;
122
- stripe_customer_details: _Stripe.Customer | null;
123
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
124
- stripe_customer_id: _Stripe.Customer['id'] | null;
125
- org_metadata: OrgMetadata;
126
- }
127
- >;
128
-
129
- export type ChatMemberType = Merge<
130
- Tables<'tbl_chat_participants'>,
131
- Tables<'tbl_contacts'>
132
- >;
133
-
134
- export type ChatType = Merge<
135
- Tables<'view_chats'>,
136
- {
137
- chat_id: string;
138
- latest_message: MessageType | null;
139
- latest_message_timestamp: number | null;
140
- members: { [key: string]: ChatMemberType } | null;
141
- chat_type: 'user' | 'group' | 'business' | 'unknown';
142
- chat_access: { [key: string]: boolean };
143
- label_ids: { [key: string]: boolean };
144
- chat_org_phones?: string[];
145
- message_unread_count: number | null;
146
- hubspot_metadata: {
147
- id: string;
148
- type: string;
149
- hubId: string;
150
- object_data: HubspotObjectDataType;
151
- } | null;
152
- info_admins_only: boolean;
153
- messages_admins_only: boolean;
154
- unread_count?: { [key: string]: number };
155
- active_phone: string | null;
156
- flag_count_map?: { [key: string]: number };
157
- is_archived?: boolean;
158
- is_pinned?: boolean;
159
- }
160
- >;
161
-
162
- /* -------------------------------------------------------------------------- */
163
- /* MESSAGE */
164
- /* -------------------------------------------------------------------------- */
165
-
166
- export type MediaType = {
167
- path: string;
168
- mimetype?: string;
169
- filename?: string;
170
- dimensions?: { width: number; height: number; ar: number };
171
- size?: number;
172
- thumbnail?: string;
173
- };
174
-
175
- export type MessageType = Merge<
176
- OverrideProperties<
177
- Tables<'tbl_chat_messages'>,
178
- {
179
- message_id: string;
180
- org_id: string;
181
- org_phone: string;
182
- chat_id: string;
183
- message_type: (typeof SUPPORTED_TYPES)[number];
184
- media: MediaType | null;
185
- flag_metadata: MessageFlagType | null;
186
- poll_info?: PollSendType | null;
187
- poll_results?: PollResultType | null;
188
- delivery_info?: DeliveryInfoType | null;
189
- }
190
- >,
191
- {
192
- reactions?: ReactionType[];
193
- message_payload?: SingleMessagePayload;
194
- show_unread?: boolean;
195
- highlight?: number;
196
- }
197
- >;
198
-
199
- export type MessageFlagType = {
200
- status: boolean;
201
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
202
- response_id?: string;
203
- response_timestamp?: string;
204
- response_email?: string;
205
- };
206
-
207
- /* -------------------------------------------------------------------------- */
208
-
209
- export type TicketType = OverrideProperties<
210
- Tables<'tbl_chat_tickets'>,
211
- {
212
- label_ids: { [key: string]: boolean };
213
- hubspot_metadata: {
214
- id?: string;
215
- type?: string;
216
- hubId?: string;
217
- pipeline: {
218
- id: string;
219
- label: string;
220
- };
221
- object_data?: HubspotObjectDataType;
222
- } | null;
223
- freshdesk_metadata: Record<string, string>;
224
- close_ticket_metadata?:
225
- | {
226
- closed_by: string;
227
- closed_at: string;
228
- closed_message?: string | null;
229
- send_reply_message_id?: string | null;
230
- }
231
- | any;
232
- }
233
- >;
234
-
235
- export type ContactType = Merge<
236
- Tables<'tbl_contacts'>,
237
- {
238
- chats: ChatType[] | null;
239
- chat_ids?: string[];
240
- }
241
- >;
242
- export type ReactionType = Tables<'tbl_chat_reactions'>;
243
-
244
- export type NotificationType = Tables<'tbl_chat_notifications'>;
245
-
246
- export type ChatAccessType = Merge<
247
- TablesUpdate<'tbl_org_members'>,
248
- {
249
- has_access?: boolean;
250
- email: string | null;
251
- }
252
- >;
253
-
254
- /* -------------------------------- CONSTANTS ------------------------------- */
255
-
256
- export const labelColors = [
257
- '#9333EA',
258
- '#0D9488',
259
- '#DB2777',
260
- '#2563EB',
261
- '#F97316',
262
- ];
263
-
264
- export const enumChatColors = [
265
- '#B4876E',
266
- '#A5B337',
267
- '#06CF9C',
268
- '#25D366',
269
- '#02A698',
270
- '#7D9EF1',
271
- '#007BFC',
272
- '#5E47DE',
273
- '#7F66FF',
274
- '#9333EA',
275
- '#FA6533',
276
- '#C4532D',
277
- '#DC2626',
278
- '#FF2E74',
279
- '#DB2777',
280
- ] as const;
281
-
282
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
283
-
284
- export const SUPPORTED_TYPES = [
285
- 'chat',
286
- 'sticker',
287
- 'image',
288
- 'video',
289
- 'document',
290
- 'vcard',
291
- 'multi_vcard',
292
- 'audio',
293
- 'ptt',
294
- 'poll_creation',
295
- 'location',
296
- 'ciphertext',
297
- ] as const;
298
-
299
- export type SendMessageContent = {
300
- message_type?: (typeof SUPPORTED_TYPES)[number];
301
- body?: string;
302
- media?: MediaType;
303
- contact_ids?: string[];
304
- location?: {
305
- latitude: string;
306
- longitude: string;
307
- options?: { name?: string; address?: string; url?: string };
308
- };
309
- poll?: PollSendType;
310
- quoted_message_id?: string;
311
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
312
- broadcast_id?: string;
313
- performed_by?: string;
314
- };
315
-
316
- export type QuickReplyContent = Omit<
317
- SendMessageContent,
318
- 'broadcast_id' | 'variables'
319
- >;
320
-
321
- export type BroadcastVariableType = {
322
- chat_id: string;
323
- values: { [key: string]: string };
324
- };
325
-
326
- export type BroadcastMessagePayload = SendMessageContent & {
327
- chat_ids: string[];
328
- broadcast_id?: string;
329
- variables?: BroadcastVariableType[];
330
- };
331
-
332
- export type SingleMessagePayload = SendMessageContent & {
333
- chat_id: string;
334
- job_id?: string;
335
- };
336
-
337
- export type MessageAttachmentFileTypes =
338
- | 'image'
339
- | 'audio'
340
- | 'document'
341
- | 'video';
342
-
343
- export type AttachmentFileType = {
344
- result: string;
345
- file: File | null;
346
- type: MessageAttachmentFileTypes;
347
- localFileURL?: string;
348
- };
349
-
350
- export type AttachmentLinkType = {
351
- link: {
352
- url: string;
353
- type: MessageAttachmentFileTypes;
354
- name: string;
355
- mimetype?: string;
356
- };
357
- };
358
-
359
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
360
-
361
- /* -------------------------------- BROADCAST ------------------------------- */
362
-
363
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
364
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
365
- } & {
366
- chats: ChatType[];
367
- };
368
-
369
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
370
-
371
- export type ChatLogType = {
372
- log: Tables<'view_chat_logs'>;
373
- operations: Tables<'tbl_chat_logs'>[];
374
- };
375
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
376
-
377
- export type ChatParticipantOperationPayload = {
378
- participant_ids: string[];
379
- chat_ids: string[];
380
- performed_by: string;
381
- };
382
-
383
- export type ChatOperationReturn = {
384
- [participant_id: string]: {
385
- is_success: boolean;
386
- message?: string;
387
- code?: number;
388
- isInviteV4Sent?: boolean;
389
- };
390
- };
391
-
392
- /* ----------------------- BILLING - STRIPE ----------------------- */
393
-
394
- export type StripeSubscription = _Stripe.Subscription;
395
- export type StripeCustomer = _Stripe.Customer;
396
- export type StripeCoupon = _Stripe.Coupon;
397
- export type StripePrice = _Stripe.Price;
398
- export type Stripe = _Stripe;
399
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
400
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
401
-
402
- /* -------------------------------- REALTIME -------------------------------- */
403
-
404
- export type PhoneStateType = {
405
- loading: boolean;
406
- state: string;
407
- sync: number;
408
- percent: number | null;
409
- message?: string;
410
- error?: string;
411
- };
412
-
413
- /* ------------------------------- INTEGRATIONS ----------------------------- */
414
-
415
- export type ChatInfoType = Merge<
416
- ChatType,
417
- {
418
- members: {
419
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
420
- } | null;
421
- chat_labels: string | null;
422
- custom_properties: { [key: string]: string } | null;
423
- }
424
- >;
425
-
426
- export type TicketInfoType = {
427
- chat: ChatInfoType;
428
- message: {
429
- body: string;
430
- chat_id: string;
431
- org_phone: string;
432
- timestamp: string;
433
- media_path: string;
434
- message_id: string;
435
- sender_name: string;
436
- performed_by: string;
437
- sender_phone: string;
438
- };
439
- ticket: {
440
- org_id: string;
441
- status: string;
442
- subject: string;
443
- assignee: string;
444
- due_date: string;
445
- priority: 0 | 1 | 2 | 3 | 4;
446
- raised_by: string;
447
- ticket_id: string;
448
- created_at: string;
449
- assigned_by: string;
450
- ticket_labels: string;
451
- quoted_message_id: string;
452
- ticket_custom_properties: { [key: string]: string } | null;
453
- };
454
- };
455
-
456
- export type IntegrationLogObjectType =
457
- | 'chat'
458
- | 'message'
459
- | 'reaction'
460
- | 'ticket';
461
-
462
- export enum IntegrationLogType {
463
- NEW_CHAT = 'chat.created',
464
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
465
- NEW_MESSAGE = 'message.created',
466
- MESSAGE_UPDATED = 'message.updated',
467
- MESSAGE_DELETED = 'message.deleted',
468
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
469
- REACTION_CREATED = 'reaction.created',
470
- REACTION_UPDATED = 'reaction.updated',
471
- NEW_TICKET = 'ticket.created',
472
- TICKET_UPDATED = 'ticket.updated',
473
- TICKET_DELETED = 'ticket.deleted',
474
- }
475
-
476
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
477
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
478
- ? TicketInfoType
479
- : T extends IntegrationLogType.NEW_CHAT
480
- ? Tables<'tbl_chats'>
481
- : T extends
482
- | IntegrationLogType.NEW_MESSAGE
483
- | IntegrationLogType.MESSAGE_UPDATED
484
- | IntegrationLogType.MESSAGE_DELETED
485
- | IntegrationLogType.MESSAGE_ACK_UPDATED
486
- ? Tables<'tbl_chat_messages'>
487
- : T extends
488
- | IntegrationLogType.REACTION_CREATED
489
- | IntegrationLogType.REACTION_UPDATED
490
- ? Tables<'tbl_chat_reactions'>
491
- : {
492
- [key: string]: unknown;
493
- };
494
-
495
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
496
- OverrideProperties<
497
- Tables<'tbl_integration_logs'>,
498
- {
499
- integration_name: T;
500
- metadata: {
501
- event: IntegrationLogMetadataType<T> & {
502
- event_type: string;
503
- org_id: string;
504
- previous_attributes: {
505
- [key: string]: unknown;
506
- };
507
- };
508
- hook_id: string;
509
- name: string;
510
- };
511
- }
512
- >;
513
-
514
- export type APIAuthDetails = {
515
- org_details: Tables<'view_org'> | null;
516
- phone_details: Tables<'tbl_org_phones'> | null;
517
- token_details: Tables<'tbl_integration_tokens'> | null;
518
- };
519
-
520
- export type WebhookDataType = OverrideProperties<
521
- Tables<'tbl_integration_hooks'>,
522
- {
523
- integration_name: string[];
524
- }
525
- >;
526
-
527
- export type HubspotObjectDataType = {
528
- createdAt: string;
529
- archived: boolean;
530
- id: string;
531
- type: 'contacts' | 'tickets' | 'companies';
532
- properties: Record<
533
- string,
534
- {
535
- groupLabel: string;
536
- groupName: string;
537
- propertyKeyName: string;
538
- propertyKey: string;
539
- propertyInternalValue: string;
540
- propertyValue: string;
541
- propertyType: string;
542
- propertyFieldType: string;
543
- }[]
544
- >;
545
- };
546
-
547
- /* ---------------------------- USER PREFERENCES ---------------------------- */
548
-
549
- export type UserPreferences = {
550
- theme: 'light' | 'dark';
551
- language: 'en' | 'es';
552
- left_sidebar_open: boolean;
553
- right_sidepanel_open: boolean;
554
- sync_wa_unread_count: boolean;
555
- pinned_chats: string[];
556
- };
557
-
558
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
559
-
560
- export type PollSendType = {
561
- pollName: string;
562
- pollOptions: string[];
563
- options?: {
564
- allowMultipleAnswers?: boolean;
565
- messageSecret?: number[] | null;
566
- pollId?: string;
567
- };
568
- };
569
-
570
- export type PollResultType = {
571
- [name: string]: Record<string, string>;
572
- };
573
-
574
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
575
-
576
- export type CreateGroupOptions = {
577
- messagesAdminsOnly?: boolean;
578
- infoAdminsOnly?: boolean;
579
- memberAddMode?: boolean;
580
- image?: string;
581
- name?: string;
582
- description?: string;
583
- };
584
-
585
- /* ------------------------------ DELIVERY INFO ----------------------------- */
586
-
587
- export type DeliveryInfoType = {
588
- delivered: Record<string, number | undefined>;
589
- read: Record<string, number | undefined>;
590
- pending: string[];
591
- read_count: number;
592
- delivered_count: number;
593
- };
1
+ import type { default as _Stripe } from 'stripe';
2
+ import { Merge, OverrideProperties } from 'type-fest';
3
+ import { Tables, TablesUpdate } from './supabase.types';
4
+
5
+ /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
6
+
7
+ /* ------------------------------ PERISKOPE TYPES ------------------------------ */
8
+
9
+ export enum AllPlans {
10
+ FREE_TRIAL = 'free-trial',
11
+ // MONTHLY_STARTER = 'monthly-starter',
12
+ // YEARLY_STARTER = 'yearly-starter',
13
+ // MONTHLY_PRO = 'monthly-pro',
14
+ // YEARLY_PRO = 'yearly-pro',
15
+ ENTERPRISE = 'enterprise',
16
+ MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
17
+ YEARLY_STARTER_SINGLE = 'yearly-starter-single',
18
+ MONTHLY_PRO_SINGLE = 'monthly-pro-single',
19
+ YEARLY_PRO_SINGLE = 'yearly-pro-single',
20
+ }
21
+
22
+ export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
23
+
24
+ export type Enterprise = `${string}-enterprise`;
25
+
26
+ export type OrgPlanEnterprise = {
27
+ subscription_id: string;
28
+ plan_id: Enterprise;
29
+ interval: number;
30
+ frequency: Frequency;
31
+ user_limit: number;
32
+ phone_limit: number;
33
+ current_period_start: number;
34
+ current_period_end: number | null;
35
+ };
36
+
37
+ export type OrgPlanNonEnterprise = {
38
+ subscription_id: string;
39
+ plan_id: AllPlans;
40
+ interval: number;
41
+ frequency: Frequency;
42
+ user_limit: number;
43
+ phone_limit: number;
44
+ current_period_end: number;
45
+ current_period_start: number;
46
+ };
47
+
48
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
49
+ ? OrgPlanEnterprise
50
+ : T extends AllPlans
51
+ ? OrgPlanNonEnterprise
52
+ : never;
53
+
54
+ export type MicrosurveyData = {
55
+ key: string;
56
+ text: string;
57
+ checked: boolean;
58
+ }[];
59
+
60
+ export type OrgPreferences = {
61
+ disable_ai_flagging?: boolean;
62
+ disable_allow_exports?: boolean;
63
+ sync_phone_contacts?: boolean;
64
+ mask_phone_numbers?: boolean;
65
+ show_sender_names?: boolean;
66
+ };
67
+
68
+ type OrgPreferenceKey = keyof OrgPreferences;
69
+
70
+ export type OrgPreferencesValue = {
71
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
72
+ }[OrgPreferenceKey];
73
+
74
+ export type OrgMetadata = {
75
+ phone_number: string;
76
+ ticket_prefix: string;
77
+ referralSource?: string;
78
+ surveyData?: MicrosurveyData;
79
+ preferences?: OrgPreferences;
80
+ hubspot_pipelines?: {
81
+ id: string;
82
+ label: string;
83
+ default_stage: { id: string; label: string };
84
+ }[];
85
+ partition?: boolean;
86
+ tickets: {
87
+ prefix?: string;
88
+ emoji_ticketing: {
89
+ is_enabled?: boolean;
90
+ is_message_enabled?: boolean;
91
+ message_template?: string;
92
+ }
93
+ }
94
+ };
95
+
96
+ type AccessScopes = {
97
+ integrations: boolean;
98
+ exports: boolean;
99
+ };
100
+
101
+ export type OrgType = OverrideProperties<
102
+ Merge<
103
+ Tables<'tbl_org'>,
104
+ {
105
+ user: Tables<'tbl_org_members'>;
106
+ members: Tables<'tbl_org_members'>[];
107
+ phones: Tables<'tbl_org_phones'>[];
108
+ labels: Tables<'tbl_org_labels'>[];
109
+ quick_replies: Tables<'tbl_quick_replies'>[];
110
+ custom_properties: Tables<'tbl_custom_properties'>[];
111
+ subscription_status: 'active' | 'inactive' | 'unpaid';
112
+ is_enterprise: boolean;
113
+ is_free_trial: boolean;
114
+ is_hubspot_connected: boolean;
115
+ is_freshdesk_connected: boolean;
116
+ is_zohodesk_connected: boolean;
117
+ access_scopes: AccessScopes;
118
+ }
119
+ >,
120
+ {
121
+ org_plan: OrgPlan<AllPlans | Enterprise>;
122
+ stripe_customer_details: _Stripe.Customer | null;
123
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
124
+ stripe_customer_id: _Stripe.Customer['id'] | null;
125
+ org_metadata: OrgMetadata;
126
+ }
127
+ >;
128
+
129
+ export type ChatMemberType = Merge<
130
+ Tables<'tbl_chat_participants'>,
131
+ Tables<'tbl_contacts'>
132
+ >;
133
+
134
+ export type ChatType = Merge<
135
+ Tables<'view_chats'>,
136
+ {
137
+ chat_id: string;
138
+ latest_message: MessageType | null;
139
+ latest_message_timestamp: number | null;
140
+ members: { [key: string]: ChatMemberType } | null;
141
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
142
+ chat_access: { [key: string]: boolean };
143
+ label_ids: { [key: string]: boolean };
144
+ chat_org_phones?: string[];
145
+ message_unread_count: number | null;
146
+ hubspot_metadata: {
147
+ id: string;
148
+ type: string;
149
+ hubId: string;
150
+ object_data: HubspotObjectDataType;
151
+ } | null;
152
+ info_admins_only: boolean;
153
+ messages_admins_only: boolean;
154
+ unread_count?: { [key: string]: number };
155
+ active_phone: string | null;
156
+ flag_count_map?: { [key: string]: number };
157
+ is_archived?: boolean;
158
+ is_pinned?: boolean;
159
+ }
160
+ >;
161
+
162
+ /* -------------------------------------------------------------------------- */
163
+ /* MESSAGE */
164
+ /* -------------------------------------------------------------------------- */
165
+
166
+ export type MediaType = {
167
+ path: string;
168
+ mimetype?: string;
169
+ filename?: string;
170
+ dimensions?: { width: number; height: number; ar: number };
171
+ size?: number;
172
+ thumbnail?: string;
173
+ };
174
+
175
+ export type MessageType = Merge<
176
+ OverrideProperties<
177
+ Tables<'tbl_chat_messages'>,
178
+ {
179
+ message_id: string;
180
+ org_id: string;
181
+ org_phone: string;
182
+ chat_id: string;
183
+ message_type: (typeof SUPPORTED_TYPES)[number];
184
+ media: MediaType | null;
185
+ flag_metadata: MessageFlagType | null;
186
+ poll_info?: PollSendType | null;
187
+ poll_results?: PollResultType | null;
188
+ delivery_info?: DeliveryInfoType | null;
189
+ }
190
+ >,
191
+ {
192
+ reactions?: ReactionType[];
193
+ message_payload?: SingleMessagePayload;
194
+ show_unread?: boolean;
195
+ highlight?: number;
196
+ }
197
+ >;
198
+
199
+ export type MessageFlagType = {
200
+ status: boolean;
201
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
202
+ response_id?: string;
203
+ response_timestamp?: string;
204
+ response_email?: string;
205
+ };
206
+
207
+ /* -------------------------------------------------------------------------- */
208
+
209
+ export type TicketType = OverrideProperties<
210
+ Tables<'tbl_chat_tickets'>,
211
+ {
212
+ label_ids: { [key: string]: boolean };
213
+ hubspot_metadata: {
214
+ id?: string;
215
+ type?: string;
216
+ hubId?: string;
217
+ pipeline: {
218
+ id: string;
219
+ label: string;
220
+ };
221
+ object_data?: HubspotObjectDataType;
222
+ } | null;
223
+ freshdesk_metadata: Record<string, string>;
224
+ close_ticket_metadata?:
225
+ | {
226
+ closed_by: string;
227
+ closed_at: string;
228
+ closed_message?: string | null;
229
+ send_reply_message_id?: string | null;
230
+ }
231
+ | any;
232
+ }
233
+ >;
234
+
235
+ export type ContactType = Merge<
236
+ Tables<'tbl_contacts'>,
237
+ {
238
+ chats: ChatType[] | null;
239
+ chat_ids?: string[];
240
+ }
241
+ >;
242
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
243
+
244
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
245
+
246
+ export type ChatAccessType = Merge<
247
+ TablesUpdate<'tbl_org_members'>,
248
+ {
249
+ has_access?: boolean;
250
+ email: string | null;
251
+ }
252
+ >;
253
+
254
+ /* -------------------------------- CONSTANTS ------------------------------- */
255
+
256
+ export const labelColors = [
257
+ '#9333EA',
258
+ '#0D9488',
259
+ '#DB2777',
260
+ '#2563EB',
261
+ '#F97316',
262
+ ];
263
+
264
+ export const enumChatColors = [
265
+ '#B4876E',
266
+ '#A5B337',
267
+ '#06CF9C',
268
+ '#25D366',
269
+ '#02A698',
270
+ '#7D9EF1',
271
+ '#007BFC',
272
+ '#5E47DE',
273
+ '#7F66FF',
274
+ '#9333EA',
275
+ '#FA6533',
276
+ '#C4532D',
277
+ '#DC2626',
278
+ '#FF2E74',
279
+ '#DB2777',
280
+ ] as const;
281
+
282
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
283
+
284
+ export const SUPPORTED_TYPES = [
285
+ 'chat',
286
+ 'sticker',
287
+ 'image',
288
+ 'video',
289
+ 'document',
290
+ 'vcard',
291
+ 'multi_vcard',
292
+ 'audio',
293
+ 'ptt',
294
+ 'poll_creation',
295
+ 'location',
296
+ 'ciphertext',
297
+ ] as const;
298
+
299
+ export type SendMessageContent = {
300
+ message_type?: (typeof SUPPORTED_TYPES)[number];
301
+ body?: string;
302
+ media?: MediaType;
303
+ contact_ids?: string[];
304
+ location?: {
305
+ latitude: string;
306
+ longitude: string;
307
+ options?: { name?: string; address?: string; url?: string };
308
+ };
309
+ poll?: PollSendType;
310
+ quoted_message_id?: string;
311
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
312
+ broadcast_id?: string;
313
+ performed_by?: string;
314
+ };
315
+
316
+ export type QuickReplyContent = Omit<
317
+ SendMessageContent,
318
+ 'broadcast_id' | 'variables'
319
+ >;
320
+
321
+ export type BroadcastVariableType = {
322
+ chat_id: string;
323
+ values: { [key: string]: string };
324
+ };
325
+
326
+ export type BroadcastMessagePayload = SendMessageContent & {
327
+ chat_ids: string[];
328
+ broadcast_id?: string;
329
+ variables?: BroadcastVariableType[];
330
+ };
331
+
332
+ export type SingleMessagePayload = SendMessageContent & {
333
+ chat_id: string;
334
+ job_id?: string;
335
+ };
336
+
337
+ export type MessageAttachmentFileTypes =
338
+ | 'image'
339
+ | 'audio'
340
+ | 'document'
341
+ | 'video';
342
+
343
+ export type AttachmentFileType = {
344
+ result: string;
345
+ file: File | null;
346
+ type: MessageAttachmentFileTypes;
347
+ localFileURL?: string;
348
+ };
349
+
350
+ export type AttachmentLinkType = {
351
+ link: {
352
+ url: string;
353
+ type: MessageAttachmentFileTypes;
354
+ name: string;
355
+ mimetype?: string;
356
+ };
357
+ };
358
+
359
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
360
+
361
+ /* -------------------------------- BROADCAST ------------------------------- */
362
+
363
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
364
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
365
+ } & {
366
+ chats: ChatType[];
367
+ };
368
+
369
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
370
+
371
+ export type ChatLogType = {
372
+ log: Tables<'view_chat_logs'>;
373
+ operations: Tables<'tbl_chat_logs'>[];
374
+ };
375
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
376
+
377
+ export type ChatParticipantOperationPayload = {
378
+ participant_ids: string[];
379
+ chat_ids: string[];
380
+ performed_by: string;
381
+ };
382
+
383
+ export type ChatOperationReturn = {
384
+ [participant_id: string]: {
385
+ is_success: boolean;
386
+ message?: string;
387
+ code?: number;
388
+ isInviteV4Sent?: boolean;
389
+ };
390
+ };
391
+
392
+ /* ----------------------- BILLING - STRIPE ----------------------- */
393
+
394
+ export type StripeSubscription = _Stripe.Subscription;
395
+ export type StripeCustomer = _Stripe.Customer;
396
+ export type StripeCoupon = _Stripe.Coupon;
397
+ export type StripePrice = _Stripe.Price;
398
+ export type Stripe = _Stripe;
399
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
400
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
401
+
402
+ /* -------------------------------- REALTIME -------------------------------- */
403
+
404
+ export type PhoneStateType = {
405
+ loading: boolean;
406
+ state: string;
407
+ sync: number;
408
+ percent: number | null;
409
+ message?: string;
410
+ error?: string;
411
+ };
412
+
413
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
414
+
415
+ export type ChatInfoType = Merge<
416
+ ChatType,
417
+ {
418
+ members: {
419
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
420
+ } | null;
421
+ chat_labels: string | null;
422
+ custom_properties: { [key: string]: string } | null;
423
+ }
424
+ >;
425
+
426
+ export type TicketInfoType = {
427
+ chat: ChatInfoType;
428
+ message: {
429
+ body: string;
430
+ chat_id: string;
431
+ org_phone: string;
432
+ timestamp: string;
433
+ media_path: string;
434
+ message_id: string;
435
+ sender_name: string;
436
+ performed_by: string;
437
+ sender_phone: string;
438
+ };
439
+ ticket: {
440
+ org_id: string;
441
+ status: string;
442
+ subject: string;
443
+ assignee: string;
444
+ due_date: string;
445
+ priority: 0 | 1 | 2 | 3 | 4;
446
+ raised_by: string;
447
+ ticket_id: string;
448
+ created_at: string;
449
+ assigned_by: string;
450
+ ticket_labels: string;
451
+ quoted_message_id: string;
452
+ ticket_custom_properties: { [key: string]: string } | null;
453
+ };
454
+ };
455
+
456
+ export type IntegrationLogObjectType =
457
+ | 'chat'
458
+ | 'message'
459
+ | 'reaction'
460
+ | 'ticket';
461
+
462
+ export enum IntegrationLogType {
463
+ NEW_CHAT = 'chat.created',
464
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
465
+ NEW_MESSAGE = 'message.created',
466
+ MESSAGE_UPDATED = 'message.updated',
467
+ MESSAGE_DELETED = 'message.deleted',
468
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
469
+ REACTION_CREATED = 'reaction.created',
470
+ REACTION_UPDATED = 'reaction.updated',
471
+ NEW_TICKET = 'ticket.created',
472
+ TICKET_UPDATED = 'ticket.updated',
473
+ TICKET_DELETED = 'ticket.deleted',
474
+ }
475
+
476
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
477
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
478
+ ? TicketInfoType
479
+ : T extends IntegrationLogType.NEW_CHAT
480
+ ? Tables<'tbl_chats'>
481
+ : T extends
482
+ | IntegrationLogType.NEW_MESSAGE
483
+ | IntegrationLogType.MESSAGE_UPDATED
484
+ | IntegrationLogType.MESSAGE_DELETED
485
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
486
+ ? Tables<'tbl_chat_messages'>
487
+ : T extends
488
+ | IntegrationLogType.REACTION_CREATED
489
+ | IntegrationLogType.REACTION_UPDATED
490
+ ? Tables<'tbl_chat_reactions'>
491
+ : {
492
+ [key: string]: unknown;
493
+ };
494
+
495
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
496
+ OverrideProperties<
497
+ Tables<'tbl_integration_logs'>,
498
+ {
499
+ integration_name: T;
500
+ metadata: {
501
+ event: IntegrationLogMetadataType<T> & {
502
+ event_type: string;
503
+ org_id: string;
504
+ previous_attributes: {
505
+ [key: string]: unknown;
506
+ };
507
+ };
508
+ hook_id: string;
509
+ name: string;
510
+ };
511
+ }
512
+ >;
513
+
514
+ export type APIAuthDetails = {
515
+ org_details: Tables<'view_org'> | null;
516
+ phone_details: Tables<'tbl_org_phones'> | null;
517
+ token_details: Tables<'tbl_integration_tokens'> | null;
518
+ };
519
+
520
+ export type WebhookDataType = OverrideProperties<
521
+ Tables<'tbl_integration_hooks'>,
522
+ {
523
+ integration_name: string[];
524
+ }
525
+ >;
526
+
527
+ export type HubspotObjectDataType = {
528
+ createdAt: string;
529
+ archived: boolean;
530
+ id: string;
531
+ type: 'contacts' | 'tickets' | 'companies';
532
+ properties: Record<
533
+ string,
534
+ {
535
+ groupLabel: string;
536
+ groupName: string;
537
+ propertyKeyName: string;
538
+ propertyKey: string;
539
+ propertyInternalValue: string;
540
+ propertyValue: string;
541
+ propertyType: string;
542
+ propertyFieldType: string;
543
+ }[]
544
+ >;
545
+ };
546
+
547
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
548
+
549
+ export type UserPreferences = {
550
+ theme: 'light' | 'dark';
551
+ language: 'en' | 'es';
552
+ left_sidebar_open: boolean;
553
+ right_sidepanel_open: boolean;
554
+ sync_wa_unread_count: boolean;
555
+ pinned_chats: string[];
556
+ };
557
+
558
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
559
+
560
+ export type PollSendType = {
561
+ pollName: string;
562
+ pollOptions: string[];
563
+ options?: {
564
+ allowMultipleAnswers?: boolean;
565
+ messageSecret?: number[] | null;
566
+ pollId?: string;
567
+ };
568
+ };
569
+
570
+ export type PollResultType = {
571
+ [name: string]: Record<string, string>;
572
+ };
573
+
574
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
575
+
576
+ export type CreateGroupOptions = {
577
+ messagesAdminsOnly?: boolean;
578
+ infoAdminsOnly?: boolean;
579
+ memberAddMode?: boolean;
580
+ image?: string;
581
+ name?: string;
582
+ description?: string;
583
+ };
584
+
585
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
586
+
587
+ export type DeliveryInfoType = {
588
+ delivered: Record<string, number | undefined>;
589
+ read: Record<string, number | undefined>;
590
+ pending: string[];
591
+ read_count: number;
592
+ delivered_count: number;
593
+ };
594
+
595
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
596
+
597
+ export type OrgCreditsType = {
598
+ org_id: string;
599
+ recurring_allowance: number; // recurring credits replenished every month
600
+ recurring_balance: number; // recurring credits remaining in current month
601
+ topup_balance: number; // topup credits remaining
602
+ total_credits_used: number; // total credits used in current month
603
+ next_renewal_date: string;
604
+ };
605
+
606
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
607
+
608
+ export type ChatRuleInfoType = Merge<
609
+ Pick<
610
+ Tables<'view_chats'>,
611
+ | 'assigned_to'
612
+ | 'chat_id'
613
+ | 'chat_name'
614
+ | 'chat_type'
615
+ | 'created_at'
616
+ | 'group_description'
617
+ | 'info_admins_only'
618
+ | 'is_exited'
619
+ | 'is_muted'
620
+ | 'org_id'
621
+ | 'org_phone'
622
+ | 'chat_org_phones'
623
+ | 'messages_admins_only'
624
+ | 'custom_properties'
625
+ >,
626
+ {
627
+ has_flagged_messages: boolean;
628
+ labels: string[];
629
+ members: string[];
630
+ custom_properties: { [key: string]: string } | null;
631
+ }
632
+ >;
633
+
634
+ export type SenderRuleInfoType = Merge<
635
+ Omit<
636
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
637
+ | 'verified_name'
638
+ | 'verified_level'
639
+ | 'updated_at'
640
+ | 'short_name'
641
+ | 'pushname'
642
+ | 'periskope_name'
643
+ | 'org_phone'
644
+ | 'number'
645
+ | 'name'
646
+ | 'label_ids'
647
+ | 'is_wa_contact'
648
+ | 'is_user'
649
+ | 'is_my_contact'
650
+ | 'is_me'
651
+ | 'is_imported'
652
+ | 'is_group'
653
+ | 'is_blocked'
654
+ | 'contact_color'
655
+ | 'business_profile'
656
+ | 'id'
657
+ | 'contact_image'
658
+ | 'contact_type'
659
+ | 'chat_id'
660
+ >,
661
+ {
662
+ is_internal: boolean;
663
+ labels: string[] | null;
664
+ }
665
+ >;
666
+
667
+ export type MessageRuleInfoType = {
668
+ chat: ChatRuleInfoType;
669
+ sender: SenderRuleInfoType;
670
+ message: OverrideProperties<
671
+ Omit<
672
+ Tables<'tbl_chat_messages'>,
673
+ | 'vcards'
674
+ | 'updated_at'
675
+ | 'unique_id'
676
+ | 'token'
677
+ | 'to'
678
+ | 'sent_message_id'
679
+ | 'raw_data'
680
+ | 'delivery_info'
681
+ | 'poll_results'
682
+ | 'poll_info'
683
+ | 'order_id'
684
+ | 'mentioned_ids'
685
+ | 'media_key'
686
+ | 'location'
687
+ | 'links'
688
+ | 'is_status'
689
+ | 'is_starred'
690
+ | 'is_gif'
691
+ | 'is_forwarded'
692
+ | 'is_ephemeral'
693
+ | 'is_deleted'
694
+ | 'fts'
695
+ | 'quoted_message_id'
696
+ | 'invite_v4'
697
+ | 'id'
698
+ | 'has_reaction'
699
+ | 'has_media'
700
+ | 'duration'
701
+ | 'broadcast'
702
+ | 'broadcast_id'
703
+ | 'device_type'
704
+ | 'forwarding_score'
705
+ | 'from'
706
+ | 'from_me'
707
+ | 'message_ticket_id'
708
+ | 'prev_body'
709
+ | 'flag_response_time'
710
+ | 'flag_metadata'
711
+ >,
712
+ {
713
+ media: MediaType | null;
714
+ }
715
+ >;
716
+ };
717
+
718
+ export type ReactionRuleInfoType = {
719
+ chat: ChatRuleInfoType;
720
+ sender: SenderRuleInfoType;
721
+ message: MessageRuleInfoType['message'];
722
+ reaction: Pick<
723
+ Tables<'tbl_chat_reactions'>,
724
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
725
+ >;
726
+ };
727
+
728
+ export type TicketRuleInfoType = {
729
+ chat: ChatRuleInfoType;
730
+ sender: SenderRuleInfoType;
731
+ ticket: Merge<
732
+ Pick<
733
+ Tables<'tbl_chat_tickets'>,
734
+ | 'org_id'
735
+ | 'status'
736
+ | 'chat_id'
737
+ | 'subject'
738
+ | 'assignee'
739
+ | 'due_date'
740
+ | 'priority'
741
+ | 'raised_by'
742
+ | 'ticket_id'
743
+ | 'created_at'
744
+ | 'is_deleted'
745
+ >,
746
+ {
747
+ labels: string[] | null;
748
+ custom_properties: { [key: string]: string } | null;
749
+ }
750
+ >;
751
+ message: MessageRuleInfoType['message'];
752
+ };