@gymspace/evolution 1.0.0
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/README.md +1273 -0
- package/dist/index.d.mts +1790 -0
- package/dist/index.d.ts +1790 -0
- package/dist/index.js +1091 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1077 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +63 -0
- package/src/api/errors.ts +220 -0
- package/src/api/routes.ts +76 -0
- package/src/api/service.ts +141 -0
- package/src/index.ts +89 -0
- package/src/modules/chats/index.ts +253 -0
- package/src/modules/chats/schemas/archive.ts +15 -0
- package/src/modules/chats/schemas/check.ts +20 -0
- package/src/modules/chats/schemas/delete-message.ts +16 -0
- package/src/modules/chats/schemas/fetch-profile-picture.ts +13 -0
- package/src/modules/chats/schemas/find-all.ts +49 -0
- package/src/modules/chats/schemas/find-contacts.ts +17 -0
- package/src/modules/chats/schemas/find-messages.ts +55 -0
- package/src/modules/chats/schemas/find-status-message.ts +11 -0
- package/src/modules/chats/schemas/get-base64-from-media-message.ts +20 -0
- package/src/modules/chats/schemas/index.ts +33 -0
- package/src/modules/chats/schemas/mark-as-read.ts +20 -0
- package/src/modules/chats/schemas/mark-as-unread.ts +17 -0
- package/src/modules/chats/schemas/presence.ts +41 -0
- package/src/modules/chats/schemas/update-message.ts +16 -0
- package/src/modules/groups/index.ts +246 -0
- package/src/modules/groups/schemas/accept-invite-code.ts +14 -0
- package/src/modules/groups/schemas/common.ts +89 -0
- package/src/modules/groups/schemas/create.ts +15 -0
- package/src/modules/groups/schemas/fetch-invite-code.ts +13 -0
- package/src/modules/groups/schemas/find-all.ts +26 -0
- package/src/modules/groups/schemas/find-by-invite-code.ts +39 -0
- package/src/modules/groups/schemas/find-by-jid.ts +14 -0
- package/src/modules/groups/schemas/find-members.ts +16 -0
- package/src/modules/groups/schemas/index.ts +24 -0
- package/src/modules/groups/schemas/leave.ts +14 -0
- package/src/modules/groups/schemas/revoke-invite-code.ts +14 -0
- package/src/modules/groups/schemas/send-group-invite.ts +15 -0
- package/src/modules/groups/schemas/toggle-ephemeral.ts +15 -0
- package/src/modules/groups/schemas/update-description.ts +15 -0
- package/src/modules/groups/schemas/update-members.ts +18 -0
- package/src/modules/groups/schemas/update-picture.ts +15 -0
- package/src/modules/groups/schemas/update-setting.ts +16 -0
- package/src/modules/groups/schemas/update-subject.ts +15 -0
- package/src/modules/index.ts +7 -0
- package/src/modules/instance/index.ts +126 -0
- package/src/modules/instance/schemas/connect.ts +14 -0
- package/src/modules/instance/schemas/connection-state.ts +16 -0
- package/src/modules/instance/schemas/create.ts +99 -0
- package/src/modules/instance/schemas/delete.ts +21 -0
- package/src/modules/instance/schemas/fetch-all.ts +57 -0
- package/src/modules/instance/schemas/index.ts +8 -0
- package/src/modules/instance/schemas/logout.ts +22 -0
- package/src/modules/instance/schemas/restart.ts +13 -0
- package/src/modules/instance/schemas/set-presence.ts +20 -0
- package/src/modules/messages/index.ts +246 -0
- package/src/modules/messages/schemas/audio.ts +12 -0
- package/src/modules/messages/schemas/base.ts +11 -0
- package/src/modules/messages/schemas/contact.ts +70 -0
- package/src/modules/messages/schemas/document.ts +12 -0
- package/src/modules/messages/schemas/image.ts +12 -0
- package/src/modules/messages/schemas/index.ts +31 -0
- package/src/modules/messages/schemas/list.ts +36 -0
- package/src/modules/messages/schemas/location.ts +76 -0
- package/src/modules/messages/schemas/media.ts +51 -0
- package/src/modules/messages/schemas/poll.ts +87 -0
- package/src/modules/messages/schemas/reaction.ts +21 -0
- package/src/modules/messages/schemas/status.ts +18 -0
- package/src/modules/messages/schemas/sticker.ts +77 -0
- package/src/modules/messages/schemas/template.ts +39 -0
- package/src/modules/messages/schemas/text.ts +88 -0
- package/src/modules/messages/schemas/video.ts +12 -0
- package/src/modules/messages/schemas/voice.ts +94 -0
- package/src/modules/profile/index.ts +110 -0
- package/src/modules/profile/schemas/fetch-business-profile.ts +29 -0
- package/src/modules/profile/schemas/fetch-privacy-settings.ts +11 -0
- package/src/modules/profile/schemas/fetch-profile.ts +23 -0
- package/src/modules/profile/schemas/index.ts +8 -0
- package/src/modules/profile/schemas/remove-picture.ts +4 -0
- package/src/modules/profile/schemas/update-name.ts +11 -0
- package/src/modules/profile/schemas/update-picture.ts +11 -0
- package/src/modules/profile/schemas/update-privacy-settings.ts +18 -0
- package/src/modules/profile/schemas/update-status.ts +11 -0
- package/src/modules/settings/index.ts +28 -0
- package/src/modules/settings/schemas/find.ts +11 -0
- package/src/modules/settings/schemas/index.ts +2 -0
- package/src/modules/settings/schemas/set.ts +18 -0
- package/src/modules/webhook/index.ts +28 -0
- package/src/modules/webhook/schemas/find.ts +7 -0
- package/src/modules/webhook/schemas/index.ts +2 -0
- package/src/modules/webhook/schemas/set.ts +16 -0
- package/src/schemas/client.ts +23 -0
- package/src/schemas/common.ts +44 -0
- package/src/types/api.ts +17 -0
- package/src/types/events.ts +53 -0
- package/src/types/messages.ts +5 -0
- package/src/types/tags.ts +14 -0
- package/src/types/webhooks.ts +255 -0
- package/src/utils/phone-numer-from-jid.ts +9 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Routes } from "@/api/routes";
|
|
2
|
+
import type { ApiService } from "@/api/service";
|
|
3
|
+
import type { MethodOptions } from "@/types/api";
|
|
4
|
+
|
|
5
|
+
import type * as Audio from "./schemas/audio";
|
|
6
|
+
import type * as Contact from "./schemas/contact";
|
|
7
|
+
import type * as Document from "./schemas/document";
|
|
8
|
+
import type * as Image from "./schemas/image";
|
|
9
|
+
import type * as List from "./schemas/list";
|
|
10
|
+
import type * as Location from "./schemas/location";
|
|
11
|
+
import type * as Reaction from "./schemas/reaction";
|
|
12
|
+
import type * as Status from "./schemas/status";
|
|
13
|
+
import type * as Sticker from "./schemas/sticker";
|
|
14
|
+
import type * as Template from "./schemas/template";
|
|
15
|
+
import type * as Text from "./schemas/text";
|
|
16
|
+
import type * as Video from "./schemas/video";
|
|
17
|
+
import type * as Voice from "./schemas/voice";
|
|
18
|
+
|
|
19
|
+
export class MessagesModule {
|
|
20
|
+
constructor(private readonly api: ApiService) {}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sends a text message
|
|
24
|
+
* @param options - Text message options
|
|
25
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
26
|
+
*/
|
|
27
|
+
async sendText(
|
|
28
|
+
options: Text.TextMessageOptions,
|
|
29
|
+
methodOptions?: MethodOptions
|
|
30
|
+
): Promise<Text.TextMessageResponse> {
|
|
31
|
+
const response = await this.api.post(Routes.Message.SendText, {
|
|
32
|
+
body: options,
|
|
33
|
+
...methodOptions,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return response as Text.TextMessageResponse;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Sends an image
|
|
41
|
+
* @param options - Image message options
|
|
42
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
43
|
+
*/
|
|
44
|
+
async sendImage(
|
|
45
|
+
options: Image.ImageMessageOptions,
|
|
46
|
+
methodOptions?: MethodOptions
|
|
47
|
+
): Promise<Image.ImageMessageResponse> {
|
|
48
|
+
options.mediatype = "image";
|
|
49
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
50
|
+
body: options,
|
|
51
|
+
...methodOptions,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return response as Image.ImageMessageResponse;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sends a video
|
|
59
|
+
* @param options - Video message options
|
|
60
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
61
|
+
*/
|
|
62
|
+
async sendVideo(
|
|
63
|
+
options: Video.VideoMessageOptions,
|
|
64
|
+
methodOptions?: MethodOptions
|
|
65
|
+
): Promise<Video.VideoMessageResponse> {
|
|
66
|
+
options.mediatype = "video";
|
|
67
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
68
|
+
body: options,
|
|
69
|
+
...methodOptions,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return response as Video.VideoMessageResponse;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Sends a document
|
|
77
|
+
* @param options - Document message options
|
|
78
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
79
|
+
*/
|
|
80
|
+
async sendDocument(
|
|
81
|
+
options: Document.DocumentMessageOptions,
|
|
82
|
+
methodOptions?: MethodOptions
|
|
83
|
+
): Promise<Document.DocumentMessageResponse> {
|
|
84
|
+
options.mediatype = "document";
|
|
85
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
86
|
+
body: options,
|
|
87
|
+
...methodOptions,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return response as Document.DocumentMessageResponse;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Sends an audio
|
|
95
|
+
* @param options - Audio message options
|
|
96
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
97
|
+
*/
|
|
98
|
+
async sendAudio(
|
|
99
|
+
options: Audio.AudioMessageOptions,
|
|
100
|
+
methodOptions?: MethodOptions
|
|
101
|
+
): Promise<Audio.AudioMessageResponse> {
|
|
102
|
+
options.mediatype = "audio";
|
|
103
|
+
const response = await this.api.post(Routes.Message.SendMedia, {
|
|
104
|
+
body: options,
|
|
105
|
+
...methodOptions,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return response as Audio.AudioMessageResponse;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Sends a voice message
|
|
113
|
+
* @param options - Voice message options
|
|
114
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
115
|
+
*/
|
|
116
|
+
async sendVoice(
|
|
117
|
+
options: Voice.VoiceMessageOptions,
|
|
118
|
+
methodOptions?: MethodOptions
|
|
119
|
+
): Promise<Voice.VoiceMessageResponse> {
|
|
120
|
+
const response = await this.api.post(Routes.Message.SendVoice, {
|
|
121
|
+
body: options,
|
|
122
|
+
...methodOptions,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return response as Voice.VoiceMessageResponse;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Sends a sticker
|
|
130
|
+
* @param options - Sticker message options
|
|
131
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
132
|
+
*/
|
|
133
|
+
async sendSticker(
|
|
134
|
+
options: Sticker.StickerMessageOptions,
|
|
135
|
+
methodOptions?: MethodOptions
|
|
136
|
+
): Promise<Sticker.StickerMessageResponse> {
|
|
137
|
+
const response = await this.api.post(Routes.Message.SendSticker, {
|
|
138
|
+
body: options,
|
|
139
|
+
...methodOptions,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return response as Sticker.StickerMessageResponse;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Sends a location
|
|
147
|
+
* @param options - Location message options
|
|
148
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
149
|
+
*/
|
|
150
|
+
async sendLocation(
|
|
151
|
+
options: Location.LocationMessageOptions,
|
|
152
|
+
methodOptions?: MethodOptions
|
|
153
|
+
): Promise<Location.LocationMessageResponse> {
|
|
154
|
+
const response = await this.api.post(Routes.Message.SendLocation, {
|
|
155
|
+
body: options,
|
|
156
|
+
...methodOptions,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return response as Location.LocationMessageResponse;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Sends a contact
|
|
164
|
+
* @param options - Contact message options
|
|
165
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
166
|
+
*/
|
|
167
|
+
async sendContact(
|
|
168
|
+
options: Contact.ContactMessageOptions,
|
|
169
|
+
methodOptions?: MethodOptions
|
|
170
|
+
): Promise<Contact.ContactMessageResponse> {
|
|
171
|
+
const response = await this.api.post(Routes.Message.SendContact, {
|
|
172
|
+
body: options,
|
|
173
|
+
...methodOptions,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return response as Contact.ContactMessageResponse;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Sends a reaction
|
|
181
|
+
* @param options - Reaction message options
|
|
182
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
183
|
+
*/
|
|
184
|
+
async sendReaction(
|
|
185
|
+
options: Reaction.ReactionMessageOptions,
|
|
186
|
+
methodOptions?: MethodOptions
|
|
187
|
+
): Promise<Reaction.ReactionMessageResponse> {
|
|
188
|
+
const response = await this.api.post(Routes.Message.SendReaction, {
|
|
189
|
+
body: options,
|
|
190
|
+
...methodOptions,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return response as Reaction.ReactionMessageResponse;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Sends a template
|
|
198
|
+
* @param options - Template message options
|
|
199
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
200
|
+
*/
|
|
201
|
+
async sendTemplate(
|
|
202
|
+
options: Template.TemplateMessageOptions,
|
|
203
|
+
methodOptions?: MethodOptions
|
|
204
|
+
): Promise<Template.TemplateMessageResponse> {
|
|
205
|
+
const response = await this.api.post(Routes.Message.SendTemplate, {
|
|
206
|
+
body: options,
|
|
207
|
+
...methodOptions,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
return response as Template.TemplateMessageResponse;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Sends a status
|
|
215
|
+
* @param options - Status message options
|
|
216
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
217
|
+
*/
|
|
218
|
+
async sendStatus(
|
|
219
|
+
options: Status.StatusMessageOptions,
|
|
220
|
+
methodOptions?: MethodOptions
|
|
221
|
+
): Promise<Status.StatusMessageResponse> {
|
|
222
|
+
const response = await this.api.post(Routes.Message.SendStatus, {
|
|
223
|
+
body: options,
|
|
224
|
+
...methodOptions,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return response as Status.StatusMessageResponse;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Sends a list
|
|
232
|
+
* @param options - List message options
|
|
233
|
+
* @param methodOptions - Method-specific options (instance override)
|
|
234
|
+
*/
|
|
235
|
+
async sendList(
|
|
236
|
+
options: List.ListMessageOptions,
|
|
237
|
+
methodOptions?: MethodOptions
|
|
238
|
+
): Promise<List.ListMessageResponse> {
|
|
239
|
+
const response = await this.api.post(Routes.Message.SendList, {
|
|
240
|
+
body: options,
|
|
241
|
+
...methodOptions,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return response as List.ListMessageResponse;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { MediaMessageOptions, MediaMessageResponse } from "./media";
|
|
3
|
+
|
|
4
|
+
// Request interfaces
|
|
5
|
+
export interface AudioMessageOptions extends MediaMessageOptions {}
|
|
6
|
+
|
|
7
|
+
// Response interfaces
|
|
8
|
+
export interface AudioMessageResponse extends MediaMessageResponse {
|
|
9
|
+
message: MediaMessageResponse["message"] & {
|
|
10
|
+
audioMessage: MediaMessageResponse["message"]["audioMessage"];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
export interface BaseMessageOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Number (with country code) or JID to receive the message
|
|
5
|
+
*/
|
|
6
|
+
number: string;
|
|
7
|
+
/**
|
|
8
|
+
* Time in milliseconds before sending message
|
|
9
|
+
*/
|
|
10
|
+
delay?: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { BaseMessageOptions } from "./base";
|
|
3
|
+
|
|
4
|
+
// Response interface from API (no transformer)
|
|
5
|
+
export interface ContactMessageResponse {
|
|
6
|
+
key: {
|
|
7
|
+
remoteJid: string;
|
|
8
|
+
fromMe?: boolean;
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
message: {
|
|
12
|
+
contactMessage?: {
|
|
13
|
+
displayName: string;
|
|
14
|
+
vcard: string;
|
|
15
|
+
contextInfo?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
contactsArrayMessage?: {
|
|
18
|
+
contacts: {
|
|
19
|
+
displayName: string;
|
|
20
|
+
vcard: string;
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
messageTimestamp: string | number | Date;
|
|
25
|
+
status?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Request interfaces
|
|
29
|
+
export interface Contact {
|
|
30
|
+
/**
|
|
31
|
+
* Contact display name
|
|
32
|
+
*/
|
|
33
|
+
fullName?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Contact phone number
|
|
36
|
+
*/
|
|
37
|
+
phoneNumber: string;
|
|
38
|
+
/**
|
|
39
|
+
* Contact organization
|
|
40
|
+
*/
|
|
41
|
+
organization?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Contact email
|
|
44
|
+
*/
|
|
45
|
+
email?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Contact website url
|
|
48
|
+
*/
|
|
49
|
+
url?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type ContactMessageContact = Omit<Contact, "fullName"> & {
|
|
53
|
+
/**
|
|
54
|
+
* Contact display name
|
|
55
|
+
*/
|
|
56
|
+
fullName?: string;
|
|
57
|
+
/**
|
|
58
|
+
* WhatsApp user id (JID or WUID)
|
|
59
|
+
*/
|
|
60
|
+
wuid: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export interface ContactMessageOptions extends BaseMessageOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Contact list
|
|
66
|
+
*/
|
|
67
|
+
contact: [ContactMessageContact, ...ContactMessageContact[]];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// No additional response typing; API returns raw shape above
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { MediaMessageOptions, MediaMessageResponse } from "./media";
|
|
3
|
+
|
|
4
|
+
// Request interfaces
|
|
5
|
+
export interface DocumentMessageOptions extends MediaMessageOptions {}
|
|
6
|
+
|
|
7
|
+
// Response interfaces
|
|
8
|
+
export interface DocumentMessageResponse extends MediaMessageResponse {
|
|
9
|
+
message: MediaMessageResponse["message"] & {
|
|
10
|
+
documentMessage: MediaMessageResponse["message"]["documentMessage"];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { MediaMessageOptions, MediaMessageResponse } from "./media";
|
|
3
|
+
|
|
4
|
+
// Request interfaces
|
|
5
|
+
export interface ImageMessageOptions extends MediaMessageOptions {}
|
|
6
|
+
|
|
7
|
+
// Response interfaces
|
|
8
|
+
export interface ImageMessageResponse extends MediaMessageResponse {
|
|
9
|
+
message: MediaMessageResponse["message"] & {
|
|
10
|
+
imageMessage: MediaMessageResponse["message"]["imageMessage"];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type { AudioMessageOptions, AudioMessageResponse } from "./audio";
|
|
2
|
+
export type { BaseMessageOptions } from "./base";
|
|
3
|
+
export type {
|
|
4
|
+
ContactMessageOptions,
|
|
5
|
+
ContactMessageResponse,
|
|
6
|
+
ContactMessageContact,
|
|
7
|
+
} from "./contact";
|
|
8
|
+
export type {
|
|
9
|
+
DocumentMessageOptions,
|
|
10
|
+
DocumentMessageResponse,
|
|
11
|
+
} from "./document";
|
|
12
|
+
export type { ImageMessageOptions, ImageMessageResponse } from "./image";
|
|
13
|
+
export type { ListMessageOptions, ListMessageResponse } from "./list";
|
|
14
|
+
export type {
|
|
15
|
+
LocationMessageOptions,
|
|
16
|
+
LocationMessageResponse,
|
|
17
|
+
} from "./location";
|
|
18
|
+
export type { PollMessageOptions, PollMessageResponse } from "./poll";
|
|
19
|
+
export type {
|
|
20
|
+
ReactionMessageOptions,
|
|
21
|
+
ReactionMessageResponse,
|
|
22
|
+
} from "./reaction";
|
|
23
|
+
export type { StatusMessageOptions, StatusMessageResponse } from "./status";
|
|
24
|
+
export type { StickerMessageOptions, StickerMessageResponse } from "./sticker";
|
|
25
|
+
export type {
|
|
26
|
+
TemplateMessageOptions,
|
|
27
|
+
TemplateMessageResponse,
|
|
28
|
+
} from "./template";
|
|
29
|
+
export type { TextMessageOptions, TextMessageResponse } from "./text";
|
|
30
|
+
export type { VideoMessageOptions, VideoMessageResponse } from "./video";
|
|
31
|
+
export type { VoiceMessageOptions, VoiceMessageResponse } from "./voice";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { ChatId, MessageId } from "@/types/tags";
|
|
3
|
+
|
|
4
|
+
export interface Row {
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
rowId: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Section {
|
|
11
|
+
title: string;
|
|
12
|
+
rows: Row[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ListMessageOptions {
|
|
16
|
+
number: ChatId;
|
|
17
|
+
buttonText: string;
|
|
18
|
+
text: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
footer?: string;
|
|
21
|
+
sections: Section[];
|
|
22
|
+
options?: {
|
|
23
|
+
delay?: number;
|
|
24
|
+
messageId?: MessageId;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ListMessageResponse {
|
|
29
|
+
key: {
|
|
30
|
+
remoteJid: ChatId;
|
|
31
|
+
fromMe: boolean;
|
|
32
|
+
id: MessageId;
|
|
33
|
+
};
|
|
34
|
+
messageTimestamp: string;
|
|
35
|
+
status: string;
|
|
36
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { Jid, MessageId } from "@/types/tags";
|
|
3
|
+
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
|
|
4
|
+
import { BaseMessageOptions } from "./base";
|
|
5
|
+
|
|
6
|
+
// Raw response interface from API
|
|
7
|
+
export interface LocationMessageResponseRaw {
|
|
8
|
+
key: {
|
|
9
|
+
remoteJid: string;
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
message: {
|
|
13
|
+
locationMessage: {
|
|
14
|
+
degreesLatitude: number;
|
|
15
|
+
degreesLongitude: number;
|
|
16
|
+
name: string;
|
|
17
|
+
address: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
messageTimestamp: string | Date;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Request interfaces
|
|
24
|
+
export interface LocationMessageOptions extends BaseMessageOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Location name
|
|
27
|
+
*/
|
|
28
|
+
name: string;
|
|
29
|
+
/**
|
|
30
|
+
* Location address
|
|
31
|
+
*/
|
|
32
|
+
address: string;
|
|
33
|
+
/**
|
|
34
|
+
* Location latitude
|
|
35
|
+
*/
|
|
36
|
+
latitude: number;
|
|
37
|
+
/**
|
|
38
|
+
* Location longitude
|
|
39
|
+
*/
|
|
40
|
+
longitude: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Response interfaces
|
|
44
|
+
export interface LocationMessageResponse {
|
|
45
|
+
receiver: {
|
|
46
|
+
phoneNumber: string;
|
|
47
|
+
jid: Jid;
|
|
48
|
+
};
|
|
49
|
+
location: {
|
|
50
|
+
latitude: number;
|
|
51
|
+
longitude: number;
|
|
52
|
+
name: string;
|
|
53
|
+
address: string;
|
|
54
|
+
};
|
|
55
|
+
id: MessageId;
|
|
56
|
+
timestamp: Date;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Transform function
|
|
60
|
+
export const LocationMessageResponseTransform = (data: LocationMessageResponseRaw): LocationMessageResponse => ({
|
|
61
|
+
receiver: {
|
|
62
|
+
phoneNumber: phoneNumberFromJid(data.key.remoteJid),
|
|
63
|
+
jid: Jid(data.key.remoteJid),
|
|
64
|
+
},
|
|
65
|
+
location: {
|
|
66
|
+
latitude: data.message.locationMessage.degreesLatitude,
|
|
67
|
+
longitude: data.message.locationMessage.degreesLongitude,
|
|
68
|
+
name: data.message.locationMessage.name,
|
|
69
|
+
address: data.message.locationMessage.address,
|
|
70
|
+
},
|
|
71
|
+
id: MessageId(data.key.id),
|
|
72
|
+
timestamp: new Date(data.messageTimestamp),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Backward compatibility aliases
|
|
76
|
+
export const ResponseSchema = { parse: LocationMessageResponseTransform };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Media } from "@/schemas/common";
|
|
2
|
+
import { BaseMessageOptions } from "./base";
|
|
3
|
+
|
|
4
|
+
// Request interfaces
|
|
5
|
+
export interface MediaMessageOptions extends BaseMessageOptions {
|
|
6
|
+
mediatype: "audio" | "image" | "video" | "document";
|
|
7
|
+
mimetype?: string;
|
|
8
|
+
caption?: string;
|
|
9
|
+
media: Media;
|
|
10
|
+
fileName?: string;
|
|
11
|
+
linkPreview?: boolean;
|
|
12
|
+
mentionsEveryOne?: boolean;
|
|
13
|
+
mentioned?: string[];
|
|
14
|
+
quoted?: {
|
|
15
|
+
key: {
|
|
16
|
+
id: string;
|
|
17
|
+
};
|
|
18
|
+
message: {
|
|
19
|
+
conversation: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Response interfaces
|
|
25
|
+
export interface MediaMessageResponse {
|
|
26
|
+
key: {
|
|
27
|
+
remoteJid: string;
|
|
28
|
+
fromMe: boolean;
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
message: {
|
|
32
|
+
[T in
|
|
33
|
+
| "audioMessage"
|
|
34
|
+
| "imageMessage"
|
|
35
|
+
| "videoMessage"
|
|
36
|
+
| "documentMessage"]: {
|
|
37
|
+
url: string;
|
|
38
|
+
mimetype: string;
|
|
39
|
+
fileSha256: string;
|
|
40
|
+
fileLength: string;
|
|
41
|
+
seconds: number;
|
|
42
|
+
ptt: boolean;
|
|
43
|
+
mediaKey: string;
|
|
44
|
+
fileEncSha256: string;
|
|
45
|
+
directPath: string;
|
|
46
|
+
mediaKeyTimestamp: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
messageTimestamp: string;
|
|
50
|
+
status: "PENDING" | "SUCCESS" | "FAILED";
|
|
51
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import { Jid, MessageId } from "@/types/tags";
|
|
3
|
+
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
|
|
4
|
+
import { BaseMessageOptions } from "./base";
|
|
5
|
+
|
|
6
|
+
// Raw response interface from API
|
|
7
|
+
export interface PollMessageResponseRaw {
|
|
8
|
+
key: {
|
|
9
|
+
remoteJid: string;
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
message: {
|
|
13
|
+
pollCreationMessageV3: {
|
|
14
|
+
name: string;
|
|
15
|
+
options: { optionName: string }[];
|
|
16
|
+
selectableOptionsCount: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
messageTimestamp: string | Date;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Request interfaces
|
|
23
|
+
export interface PollMessageOptions extends BaseMessageOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Name of the poll
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether multiple options can be selected
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
multiple?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Poll options
|
|
35
|
+
*/
|
|
36
|
+
options: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PollMessageBody extends BaseMessageOptions {
|
|
40
|
+
name: string;
|
|
41
|
+
selectableCount: number;
|
|
42
|
+
values: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Response interfaces
|
|
46
|
+
export interface PollMessageResponse {
|
|
47
|
+
receiver: {
|
|
48
|
+
phoneNumber: string;
|
|
49
|
+
jid: Jid;
|
|
50
|
+
};
|
|
51
|
+
poll: {
|
|
52
|
+
name: string;
|
|
53
|
+
options: string[];
|
|
54
|
+
multiple: boolean;
|
|
55
|
+
};
|
|
56
|
+
id: MessageId;
|
|
57
|
+
timestamp: Date;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Transform functions
|
|
61
|
+
export const PollMessageBodyTransform = (
|
|
62
|
+
{ multiple, options, ...data }: PollMessageOptions
|
|
63
|
+
): PollMessageBody => ({
|
|
64
|
+
...data,
|
|
65
|
+
selectableCount: multiple ? options.length : 1,
|
|
66
|
+
values: options,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const PollMessageResponseTransform = (data: PollMessageResponseRaw): PollMessageResponse => ({
|
|
70
|
+
receiver: {
|
|
71
|
+
phoneNumber: phoneNumberFromJid(data.key.remoteJid),
|
|
72
|
+
jid: Jid(data.key.remoteJid),
|
|
73
|
+
},
|
|
74
|
+
poll: {
|
|
75
|
+
name: data.message.pollCreationMessageV3.name,
|
|
76
|
+
options: data.message.pollCreationMessageV3.options.map(
|
|
77
|
+
(option) => option.optionName,
|
|
78
|
+
),
|
|
79
|
+
multiple: data.message.pollCreationMessageV3.selectableOptionsCount > 1,
|
|
80
|
+
},
|
|
81
|
+
id: MessageId(data.key.id),
|
|
82
|
+
timestamp: new Date(data.messageTimestamp),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Backward compatibility aliases
|
|
86
|
+
export const BodySchema = { parse: PollMessageBodyTransform };
|
|
87
|
+
export const ResponseSchema = { parse: PollMessageResponseTransform };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
import type { ChatId, MessageId } from "@/types/tags";
|
|
3
|
+
|
|
4
|
+
export interface ReactionMessageOptions {
|
|
5
|
+
key: {
|
|
6
|
+
remoteJid: ChatId;
|
|
7
|
+
fromMe: boolean;
|
|
8
|
+
id: MessageId;
|
|
9
|
+
};
|
|
10
|
+
reaction: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ReactionMessageResponse {
|
|
14
|
+
key: {
|
|
15
|
+
remoteJid: ChatId;
|
|
16
|
+
fromMe: boolean;
|
|
17
|
+
id: MessageId;
|
|
18
|
+
};
|
|
19
|
+
messageTimestamp: string;
|
|
20
|
+
status: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Pure TypeScript interfaces for better IDE support and performance
|
|
2
|
+
export interface StatusMessageOptions {
|
|
3
|
+
message: string;
|
|
4
|
+
options?: {
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
font?: number; // 0-6 range
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface StatusMessageResponse {
|
|
11
|
+
key: {
|
|
12
|
+
remoteJid: string;
|
|
13
|
+
fromMe: boolean;
|
|
14
|
+
id: string;
|
|
15
|
+
};
|
|
16
|
+
messageTimestamp: string;
|
|
17
|
+
status: string;
|
|
18
|
+
}
|