-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi.types.ts
More file actions
698 lines (604 loc) · 16.8 KB
/
Copy pathapi.types.ts
File metadata and controls
698 lines (604 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
import { InstanceInterface, PollMessageData, TypeInstance } from 'types';
export interface UserInterface {
idUser: string;
apiTokenUser: string;
login: string;
projectId: string;
}
export interface SendingResponseInterface {
idMessage: string;
}
export type DeleteStatusParametersInterface = InstanceInterface &
Pick<SendingResponseInterface, 'idMessage'>;
export interface SendingBaseParametersInterface {
chatId: string;
message: string;
quotedMessageId?: string;
archiveChat?: boolean;
}
export interface SendMessageParametersInterface
extends InstanceInterface,
SendingBaseParametersInterface {
linkPreview?: boolean;
refetchLastMessages?: boolean;
}
// Todo interface for body
export interface ReceiveNotificationResponseInterface {
receiptId: number;
body: Record<string, any>;
}
export type DeleteNotificationParameters = InstanceInterface &
Pick<ReceiveNotificationResponseInterface, 'receiptId'>;
export interface ResultResponseInterface {
result: boolean;
}
export type EditMessageParameters = GetChatInformationParameters & { message: string };
export type TypeConnectionMessage = 'outgoing' | 'incoming';
export type StatusMessage = 'pending' | 'sent' | 'delivered' | 'read';
export type TelegramChatType = 'user' | 'group' | 'supergroup' | 'channel' | 'bot';
export type TypeMessage =
| 'textMessage'
| 'imageMessage'
| 'videoMessage'
| 'documentMessage'
| 'audioMessage'
| 'locationMessage'
| 'contactMessage'
| 'extendedTextMessage'
| 'pollMessage'
| 'deletedMessage'
| 'editedMessage'
| 'reactionMessage'
| 'stickerMessage'
| 'templateMessage'
| 'templateButtonsReplyMessage'
| 'interactiveButtons'
| 'pollUpdateMessage';
export type Contact = {
displayName: string;
vcard: string;
};
export interface InteractiveButton {
type: 'call' | 'url' | 'copy' | 'reply';
buttonId: string;
buttonText: string;
copyCode?: string;
phoneNumber?: string;
url?: string;
}
interface InteractiveButtons {
titleText?: string;
contentText: string;
footerText?: string;
headerText?: string;
buttons: InteractiveButton[];
}
// Todo rewrite interface
export interface MessageInterface
extends SendingResponseInterface,
Partial<LocationInterface>,
Pick<SendingBaseParametersInterface, 'chatId'> {
type: TypeConnectionMessage;
timestamp: number;
statusMessage?: StatusMessage;
typeMessage: TypeMessage;
chatType?: TelegramChatType;
senderId?: string;
senderName?: string;
senderType?: TelegramChatType;
senderContactName?: string;
textMessage?: string;
caption?: string;
contact?: Contact;
extendedTextMessage?: ExtendedTextMessage;
extendedTextMessageData?: ExtendedTextMessageData;
quotedMessage?: QuotedMessageInterface;
templateMessage?: TemplateMessageInterface;
templateButtonReplyMessage?: TemplateButtonReplyMessage;
interactiveButtons?: InteractiveButtons;
downloadUrl?: string;
location?: LocationInterface;
fileName?: string;
isDeleted?: boolean;
isEdited?: boolean;
editedMessageId?: string;
deletedMessageId?: string;
pollMessageData?: PollMessageData;
}
export interface QuotedMessageInterface extends Partial<MessageInterface> {
stanzaId: string;
participant?: string;
type?: TypeConnectionMessage;
typeMessage?: TypeMessage;
isEdited?: boolean;
isDeleted?: boolean;
}
export type GetChatHistoryResponse = MessageInterface[];
export interface LocationInterface {
nameLocation?: string;
address?: string;
latitude: string;
longitude: string;
jpegThumbnail: string;
}
export interface ExtendedTextMessage {
text: string;
description: string;
title: string;
previewType: string;
jpegThumbnail: string;
mediaType?: 'IMAGE' | 'VIDEO';
showAdAttribution?: boolean;
sourceId?: string;
sourceType?: string;
sourceUrl?: string;
thumbnailUrl?: string;
}
export interface ExtendedTextMessageData {
text?: string;
}
export type TemplateMessageInterface = IncomingTemplateMessage | OutgoingTemplateMessage;
export interface OutgoingTemplateMessage {
templateId: string;
params?: string[];
}
export interface IncomingTemplateMessage {
contentText: string;
titleText?: string;
footerText?: string;
mediaUrl?: string;
buttons: {
urlButton: IncomingTemplateButton;
quickReplyButton: IncomingTemplateButton;
callButton: IncomingTemplateButton;
}[];
}
export interface IncomingTemplateButton {
displayText: string;
[key: string]: string;
}
export interface TemplateButtonReplyMessage {
stanzaId: string;
selectedIndex: number;
selectedId: string;
selectedDisplayText: string;
}
export interface GetChatHistoryParametersInterface
extends InstanceInterface,
Pick<SendingBaseParametersInterface, 'chatId'> {
count?: number;
}
export type GetChatInformationParameters = { onlySenderDelete?: boolean } & Pick<
SendingBaseParametersInterface,
'chatId'
> &
SendingResponseInterface &
InstanceInterface;
export interface LastMessagesParametersInterface extends InstanceInterface {
minutesToRefetch?: number;
minutes?: number;
allMessages?: boolean;
}
export interface GroupBaseParametersInterface extends InstanceInterface {
groupId?: string;
chatId?: string;
}
export interface UpdateGroupNameInterface extends GroupBaseParametersInterface {
groupName: string;
}
export interface UpdateGroupNameResponseInterface {
updateGroupName: boolean;
}
export interface GroupParticipantApiInterface extends GroupBaseParametersInterface {
participantChatId: string;
}
export type SetGroupAdminInterface = GroupParticipantApiInterface;
export interface AddGroupParticipantResponseInterface {
addParticipant: boolean;
}
export interface RemoveGroupParticipantResponseInterface {
removeParticipant: boolean;
}
export interface SetGroupAdminResponseInterface {
setGroupAdmin: boolean;
}
export interface RemoveGroupAdminResponseInterface {
removeAdmin: boolean;
}
export interface SetGroupPictureInterface extends GroupBaseParametersInterface {
file: File;
}
export interface SetGroupPictureResponseInterface {
setGroupPicture: boolean;
urlAvatar: string;
reason: string;
}
export interface LeaveGroupResponseInterface {
leaveGroup: boolean;
removeAdmin?: boolean;
}
export type GetGroupDataResponseInterface =
| GetGroupDataSuccessResponseInterface
| GetGroupDataErrorResponse;
export interface GetGroupDataSuccessResponseInterface
extends Pick<GroupBaseParametersInterface, 'groupId'> {
owner: string;
subject: string;
creation: string;
description?: string;
participants: GroupParticipantInterface[];
subjectTime: number;
subjectOwner: string;
groupInviteLink: string;
allowParticipantsSendInviteLink?: boolean;
allowParticipantsSendMessageHistory?: boolean;
chatId?: string;
}
export type GetGroupDataErrorResponse = 'Error: item-not-found' | 'Error: forbidden';
export interface GroupParticipantInterface {
id: string;
chatId?: string;
name?: string;
isAdmin: boolean;
isSuperAdmin: boolean;
}
export interface CheckWhatsappParametersInterface extends InstanceInterface {
phoneNumber: string;
}
export interface CheckWhatsappResponseInterface {
existsWhatsapp: boolean;
}
export interface GetContactsParametersInterface extends InstanceInterface {
group?: boolean;
count?: number;
}
export interface ContactListItemInterface {
id: string;
name: string;
contactName?: string;
type: 'user' | 'group' | 'supergroup' | 'channel' | 'bot';
phoneNumber?: string;
}
export interface UpsertContactPayloadInterface {
chatId: string;
firstName: string;
lastName?: string;
saveInAddressbook?: boolean;
}
export type AddContactParametersInterface = InstanceInterface & UpsertContactPayloadInterface;
export type EditContactParametersInterface = InstanceInterface & UpsertContactPayloadInterface;
export type DeleteContactParametersInterface = InstanceInterface &
Pick<UpsertContactPayloadInterface, 'chatId'>;
export type RequestWithChatIdParameters = InstanceInterface &
Pick<SendingBaseParametersInterface, 'chatId'>;
export interface GetAvatarResponseInterface {
existsWhatsapp: boolean;
available: boolean;
urlAvatar: string;
base64Avatar?: string;
reason: 'bad request data' | 'get avatar timeout limit exceeded';
}
export interface GetContactInfoResponseInterface
extends Pick<SendingBaseParametersInterface, 'chatId'> {
avatar: string;
name: string;
contactName?: string;
email: string;
category: string;
description: string;
products: ProductInterface[];
lastSeen: string | null;
isArchive: boolean;
isDisappearing: boolean;
isBusiness: boolean;
isMute: boolean;
messageExpiration: number;
muteExpiration: number | null;
base64Avatar?: string;
}
interface ProductInterface {
id: number;
imageUrls: Record<string, unknown>;
availability: string;
reviewStatus: Record<string, unknown>;
name: string;
description: string;
price: string;
isHidden: boolean;
}
export interface SendFileByUploadResponseInterface extends SendingResponseInterface {
urlFile: string;
}
export interface SendFileByUploadParametersInterface
extends InstanceInterface,
Pick<SendingBaseParametersInterface, 'chatId' | 'quotedMessageId'>,
SendingBaseFileParametersInterface {
file: File;
}
export interface SendingBaseFileParametersInterface {
fileName?: string;
caption?: string;
}
export interface SendContactParametersInterface
extends InstanceInterface,
Pick<SendingBaseParametersInterface, 'chatId' | 'quotedMessageId'> {
contact: ContactInterface;
}
export type ContactInterface =
| {
phoneContact: string | number;
firstName?: string;
middleName?: string;
lastName?: string;
company?: string;
}
| {
chatId: string;
};
export interface SendLocationParametersInterface
extends InstanceInterface,
Pick<SendingBaseParametersInterface, 'chatId' | 'quotedMessageId'> {
nameLocation?: string;
address?: string;
latitude: number;
longitude: number;
}
export interface SendPollParametersInterface
extends InstanceInterface,
Pick<SendingBaseParametersInterface, 'chatId' | 'message' | 'quotedMessageId'> {
multipleAnswers?: boolean;
options: { optionName: string }[];
}
export enum StateInstanceEnum {
Authorized = 'authorized',
NotAuthorized = 'notAuthorized',
Blocked = 'blocked',
SleepMode = 'sleepMode',
Starting = 'starting',
YellowCard = 'yellowCard',
PendingCode = 'pendingCode',
Suspended = 'suspended',
}
export interface GetStateInstanceResponseInterface {
stateInstance: StateInstanceEnum;
}
export enum AppMethodsEnum {
GetInstances = 'user.instances.list',
Login = 'loginUser',
Verify = 'verifyUser',
GetProfileSettings = 'user.profile.getSettings',
}
export type AppApiResponse<Data> = AppApiSuccessResponseInterface<Data> | AppApiErrorResponse;
export interface AppApiSuccessResponseInterface<Data> {
result: true;
data: Data;
error: object;
}
export interface AppApiErrorResponse {
result: false;
data: object;
error: {
code: number;
description: string;
};
}
export interface UserLoginDataInterface extends Pick<UserInterface, 'login'> {
password: string;
}
export enum TariffsEnum {
Developer = 'DEVELOPER',
Business = 'BUSINESS',
BusinessUSD = 'BUSINESS_USD',
BusinessKZT = 'BUSINESS_KZT',
}
export interface ExpandedInstanceInterface extends InstanceInterface {
deleted: boolean;
idInstanceDeleted: boolean;
isExpired: boolean;
isFree: boolean;
isPartner: boolean;
name: string;
partnerUserUiid: string;
tariff: TariffsEnum;
timeCreated: string;
timeDeleted: string;
expirationDate: string;
typeAccount: string;
typeInstance: TypeInstance;
}
export type GetInstancesResponse = AppApiResponse<ExpandedInstanceInterface[]>;
export interface GetWaSettingsResponseInterface {
stateInstance: StateInstanceEnum;
avatar: string;
phone: string;
deviceId: string;
chatId?: string;
base64Avatar?: string;
}
export interface GetProfileBaseSettingsResponseInterface<T extends boolean> {
country: string;
language: string;
isPartner: T;
isWaba: boolean;
}
export type GetProfileSettingsResponse =
| GetProfileBaseSettingsResponseInterface<false>
| (GetProfileBaseSettingsResponseInterface<true> & { partnerToken: string });
export interface UploadFileParametersInterface extends InstanceInterface {
file: File;
}
export interface SendFileByUrlParametersInterface
extends InstanceInterface,
Omit<SendingBaseParametersInterface, 'message'>,
Required<Pick<SendingBaseFileParametersInterface, 'fileName'>>,
Omit<SendingBaseFileParametersInterface, 'fileName'> {
urlFile: string;
}
interface BaseButton {
buttonId: string;
buttonText: string;
type: string;
}
interface CopyButton extends BaseButton {
type: 'copy';
copyCode: string;
}
interface CallButton extends BaseButton {
type: 'call';
phoneNumber: string;
}
interface UrlButton extends BaseButton {
type: 'url';
url: string;
}
interface ReplyButton extends BaseButton {
type: 'reply';
url: string;
}
export type Button = CopyButton | CallButton | UrlButton | ReplyButton;
export interface SendInteractiveButtonsInterface
extends InstanceInterface,
Pick<SendingBaseParametersInterface, 'chatId'> {
header: string;
footer: string;
body: string;
buttons: Button[];
}
export type FontType =
| 'SERIF'
| 'SANS_SERIF'
| 'NORICAN_REGULAR'
| 'BRYNDAN_WRITE'
| 'OSWALD_HEAVY';
export interface SendTextStatusInterface extends InstanceInterface {
message: string;
backgroundColor?: string;
font?: FontType;
participants?: string[];
}
export interface SendVoiceStatusInterface extends InstanceInterface {
urlFile: string;
optimisticDownloadUrl?: string;
caption?: string;
fileName: string;
participants?: string[];
}
export interface StatusesJournalParametersInterface extends InstanceInterface {
minutes?: number;
}
export interface StatusJournalTextMessage {
text: string;
backgroundColor?: string;
font?: FontType;
}
export interface StatusJournalItemInterface {
type: 'incoming' | 'outgoing';
idMessage: string;
timestamp: number;
typeMessage:
| 'extendedTextMessage'
| 'imageMessage'
| 'videoMessage'
| 'audioMessage'
| 'deletedMessage';
chatId: string;
statusMessage?: StatusMessage;
sendByApi?: boolean;
participants?: string[];
senderId?: string;
senderName?: string;
senderContactName?: string;
textMessage?: string;
downloadUrl?: string;
caption?: string;
fileName?: string;
jpegThumbnail?: string;
mimeType?: string;
extendedTextMessage?: StatusJournalTextMessage;
}
export interface DownloadFileResponseInterface {
downloadUrl: string;
}
export interface QrWebsocketResponseInterface {
type: 'qrCode' | 'error' | 'accountData' | 'alreadyLogged' | 'timeoutExpired' | 'timeout';
message: string;
}
export interface GetQRResponseInterface {
status: boolean;
code: string;
}
export interface LogoutResponseInterface {
isLogout: boolean;
}
export interface StartAuthorizationResponseInterface {
status: boolean;
data: {
status: 'success' | 'fail';
reason: string;
};
}
export interface SendMaxAuthCodeParametersInterface extends InstanceInterface {
code: string;
password?: string;
}
export type FlagRequest = 'yes' | 'no';
export interface GetSettingsResponseInterface {
wid: string;
typeAccount: string;
typeInstance: string;
webhookUrl: string;
webhookUrlToken: string;
delaySendMessagesMilliseconds: number;
markIncomingMessagesReaded: FlagRequest;
markIncomingMessagesReadedOnReply: FlagRequest;
sharedSession: FlagRequest;
countryInstance: string;
outgoingWebhook: FlagRequest;
outgoingMessageWebhook: FlagRequest;
outgoingAPIMessageWebhook: FlagRequest;
stateWebhook: FlagRequest;
incomingWebhook: FlagRequest;
incomingBlockWebhook: FlagRequest;
deviceWebhook: FlagRequest;
statusInstanceWebhook: FlagRequest;
enableMessagesHistory: FlagRequest;
keepOnlineStatus: FlagRequest;
pollMessageWebhook: FlagRequest;
incomingCallWebhook: FlagRequest;
deletedMessageWebhook: FlagRequest;
editedMessageWebhook: FlagRequest;
}
export interface ExpandedGetSettingsInterface
extends GetSettingsResponseInterface,
Pick<
ExpandedInstanceInterface,
'idInstance' | 'name' | 'tariff' | 'expirationDate' | 'isExpired'
> {
proxyInstance: string;
avatarInfoWebhook: FlagRequest;
pollMessageWebhook: FlagRequest;
incomingCallWebhook: FlagRequest;
}
export type InstanceData = ExpandedGetSettingsInterface &
Pick<
ExpandedInstanceInterface,
| 'deleted'
| 'isFree'
| 'isPartner'
| 'partnerUserUiid'
| 'timeCreated'
| 'timeDeleted'
| 'typeInstance'
> &
Pick<InstanceInterface, 'apiTokenInstance' | 'apiUrl' | 'mediaUrl'>;
export interface QRResponseInterface {
type: 'qrCode' | 'error' | 'alreadyLogged' | 'pending_password';
message: 'string';
}
export interface GetChatsResponseInterface {
chatId: string;
name: string;
type: TelegramChatType;
// MAX/Telegram getChats returns the phone as a number, not a string
phoneNumber?: string | number;
}