@hdriel/whatsapp-socket 1.2.8 → 1.2.9
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/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +232 -16
- package/dist/index.d.ts +232 -16
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Stream from 'node:stream';
|
|
2
|
+
import { WASocket, UserFacingSocketConfig, WAMessage, Contact, GroupMetadata } from '@fadzzzslebew/baileys';
|
|
2
3
|
import { StringValue } from 'ms';
|
|
3
4
|
import { Logger } from 'stack-trace-logger';
|
|
4
|
-
import Stream from 'node:stream';
|
|
5
5
|
|
|
6
6
|
type ButtonURL = {
|
|
7
7
|
label: string;
|
|
@@ -113,6 +113,7 @@ declare class WhatsappSocketBase {
|
|
|
113
113
|
autoConnect?: boolean;
|
|
114
114
|
}): Promise<void>;
|
|
115
115
|
isConnected(): boolean;
|
|
116
|
+
myJID(): string | null;
|
|
116
117
|
/**
|
|
117
118
|
* Delete a message for everyone (if within time limit) or just for yourself
|
|
118
119
|
* @param messageId - The message ID to delete
|
|
@@ -132,10 +133,197 @@ declare class WhatsappSocketBase {
|
|
|
132
133
|
chatJid: string;
|
|
133
134
|
}>, deleteForEveryone?: true): Promise<any[]>;
|
|
134
135
|
loadRecentMessages(chatJid: string, messageId: string): Promise<WAMessage | null>;
|
|
136
|
+
getContactByJid(remoteJid: string): Promise<Contact | undefined>;
|
|
137
|
+
getContacts(username?: string, byWords?: boolean): Promise<Contact[]>;
|
|
138
|
+
areRegisteredOnWhatsApp(phone: string | string[]): Promise<Array<{
|
|
139
|
+
phone: string;
|
|
140
|
+
exists: boolean;
|
|
141
|
+
jid?: string;
|
|
142
|
+
contact: Contact | undefined;
|
|
143
|
+
}>>;
|
|
135
144
|
}
|
|
136
145
|
|
|
146
|
+
type MenuMessageProps = {
|
|
147
|
+
title: string;
|
|
148
|
+
subtitle?: string;
|
|
149
|
+
buttonText: string;
|
|
150
|
+
sections: Array<{
|
|
151
|
+
title: string;
|
|
152
|
+
rows: Array<{
|
|
153
|
+
id: string;
|
|
154
|
+
title: string;
|
|
155
|
+
description?: string;
|
|
156
|
+
}>;
|
|
157
|
+
}>;
|
|
158
|
+
};
|
|
159
|
+
type AudioMessageProps = {
|
|
160
|
+
filename?: string;
|
|
161
|
+
replyToMessageId?: string;
|
|
162
|
+
mimetype?: string;
|
|
163
|
+
seconds?: number;
|
|
164
|
+
ptt?: boolean;
|
|
165
|
+
mentions?: string[];
|
|
166
|
+
};
|
|
167
|
+
type ButtonsMessageProps = {
|
|
168
|
+
title: string;
|
|
169
|
+
subtitle?: string;
|
|
170
|
+
buttons: CallToActionButtons;
|
|
171
|
+
};
|
|
172
|
+
type DocumentMessageProps = {
|
|
173
|
+
filename?: string;
|
|
174
|
+
caption?: string;
|
|
175
|
+
mimetype?: string;
|
|
176
|
+
mentions?: string[];
|
|
177
|
+
jpegThumbnail?: Buffer | string;
|
|
178
|
+
};
|
|
179
|
+
type ImageMessageProps = {
|
|
180
|
+
caption?: string;
|
|
181
|
+
filename?: string;
|
|
182
|
+
mentions?: string[];
|
|
183
|
+
};
|
|
184
|
+
type ReplyMessageProps = {
|
|
185
|
+
title: string;
|
|
186
|
+
subtitle?: string;
|
|
187
|
+
buttons: Array<string | {
|
|
188
|
+
id: number | string;
|
|
189
|
+
label: string;
|
|
190
|
+
}>;
|
|
191
|
+
};
|
|
192
|
+
type SurveyMessageProps = {
|
|
193
|
+
question: string;
|
|
194
|
+
options: string[];
|
|
195
|
+
allowMultipleAnswers?: boolean;
|
|
196
|
+
};
|
|
197
|
+
type TextMessageProps = {
|
|
198
|
+
text: string;
|
|
199
|
+
};
|
|
200
|
+
type VideoMessageProps = {
|
|
201
|
+
caption?: string;
|
|
202
|
+
sendAsGifPlayback?: boolean;
|
|
203
|
+
filename?: string;
|
|
204
|
+
mentions?: string[];
|
|
205
|
+
};
|
|
206
|
+
type LocationMessageProps = {
|
|
207
|
+
latitude: number;
|
|
208
|
+
longitude: number;
|
|
209
|
+
name?: string;
|
|
210
|
+
address?: string;
|
|
211
|
+
};
|
|
212
|
+
type StickerMessageProps = {
|
|
213
|
+
mentions?: string[];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
type ReplyMessage = Omit<ReplyMessageProps, 'buttons'> & {
|
|
217
|
+
buttons: Array<{
|
|
218
|
+
id: number | string;
|
|
219
|
+
label: string;
|
|
220
|
+
}>;
|
|
221
|
+
};
|
|
222
|
+
type Message = {
|
|
223
|
+
timeout?: StringValue | number;
|
|
224
|
+
forceExit?: boolean;
|
|
225
|
+
text: TextMessageProps;
|
|
226
|
+
} | {
|
|
227
|
+
timeout?: StringValue | number;
|
|
228
|
+
forceExit?: boolean;
|
|
229
|
+
menu: MenuMessageProps;
|
|
230
|
+
} | {
|
|
231
|
+
timeout?: StringValue | number;
|
|
232
|
+
forceExit?: boolean;
|
|
233
|
+
reply: ReplyMessage;
|
|
234
|
+
} | {
|
|
235
|
+
timeout?: StringValue | number;
|
|
236
|
+
forceExit?: boolean;
|
|
237
|
+
buttons: ButtonsMessageProps;
|
|
238
|
+
} | {
|
|
239
|
+
timeout?: StringValue | number;
|
|
240
|
+
forceExit?: boolean;
|
|
241
|
+
survey: SurveyMessageProps;
|
|
242
|
+
} | {
|
|
243
|
+
timeout?: StringValue | number;
|
|
244
|
+
forceExit?: boolean;
|
|
245
|
+
image: ImageMessageProps;
|
|
246
|
+
} | {
|
|
247
|
+
timeout?: StringValue | number;
|
|
248
|
+
forceExit?: boolean;
|
|
249
|
+
video: VideoMessageProps;
|
|
250
|
+
} | {
|
|
251
|
+
timeout?: StringValue | number;
|
|
252
|
+
forceExit?: boolean;
|
|
253
|
+
sticker: StickerMessageProps;
|
|
254
|
+
} | {
|
|
255
|
+
timeout?: StringValue | number;
|
|
256
|
+
forceExit?: boolean;
|
|
257
|
+
audio: AudioMessageProps;
|
|
258
|
+
} | {
|
|
259
|
+
timeout?: StringValue | number;
|
|
260
|
+
forceExit?: boolean;
|
|
261
|
+
document: DocumentMessageProps;
|
|
262
|
+
} | {
|
|
263
|
+
timeout?: StringValue | number;
|
|
264
|
+
forceExit?: boolean;
|
|
265
|
+
location: LocationMessageProps;
|
|
266
|
+
};
|
|
267
|
+
type ScenarioResponse = {
|
|
268
|
+
field?: string;
|
|
269
|
+
onSubmit?: (values: {
|
|
270
|
+
messageId: string;
|
|
271
|
+
options?: any;
|
|
272
|
+
data?: any;
|
|
273
|
+
remoteJid: string;
|
|
274
|
+
}) => void | Promise<void>;
|
|
275
|
+
next?: Scenario;
|
|
276
|
+
};
|
|
277
|
+
type MessageCB = (remoteJid: string, dataFlow: any) => Message | Promise<Message>;
|
|
278
|
+
type MessageItem = MessageCB | Message;
|
|
279
|
+
type Scenario = {
|
|
280
|
+
field?: string;
|
|
281
|
+
messages: MessageItem[];
|
|
282
|
+
response?: Record<string, // input or buttonId
|
|
283
|
+
// input or buttonId
|
|
284
|
+
ScenarioResponse | undefined>;
|
|
285
|
+
};
|
|
286
|
+
type FieldSchema = {
|
|
287
|
+
parseFieldData?: (input: string) => any;
|
|
288
|
+
validate?: (input: string) => boolean;
|
|
289
|
+
validationError?: string | ((input?: string) => string);
|
|
290
|
+
};
|
|
291
|
+
type BotSchema = {
|
|
292
|
+
name?: string;
|
|
293
|
+
description?: string;
|
|
294
|
+
exitCode?: string;
|
|
295
|
+
exitMsg?: Message;
|
|
296
|
+
unknownInputMsg?: Message;
|
|
297
|
+
idleTimeout?: StringValue | number;
|
|
298
|
+
timeoutMsg?: Message;
|
|
299
|
+
backCode?: string;
|
|
300
|
+
matches?: (string | RegExp | ((remoteJid: string, textMsg: string, fromMe?: boolean) => boolean | Promise<boolean>))[];
|
|
301
|
+
flow?: Scenario;
|
|
302
|
+
fields?: Record<string, FieldSchema>;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
type MessageType = 'text' | 'reply' | 'menu' | 'buttons' | 'image' | 'video' | 'audio' | 'location';
|
|
137
306
|
declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
307
|
+
protected timers: Record<string, Record<number, {
|
|
308
|
+
timeoutId: number;
|
|
309
|
+
date: Date;
|
|
310
|
+
data: Message;
|
|
311
|
+
messageType: MessageType;
|
|
312
|
+
}>>;
|
|
138
313
|
constructor(props: WhatsappSocketBaseProps);
|
|
314
|
+
protected sendMessageByType(remoteJid: string | null, messageType: MessageType, message: any): Promise<void>;
|
|
315
|
+
setTimer(remoteJid: string, messageType: MessageType, message: any, timeout: number, autoSelfNotificationFormat?: string | null): Promise<NodeJS.Timeout>;
|
|
316
|
+
getTimers(remoteJid: string): {
|
|
317
|
+
code: string;
|
|
318
|
+
message: {
|
|
319
|
+
timeoutId: number;
|
|
320
|
+
date: Date;
|
|
321
|
+
data: Message;
|
|
322
|
+
messageType: MessageType;
|
|
323
|
+
};
|
|
324
|
+
}[];
|
|
325
|
+
removeTimerId(remoteJid: string, timerId: number): void;
|
|
326
|
+
resetTimers(remoteJid?: string): void;
|
|
139
327
|
/**
|
|
140
328
|
* Delete a sent message
|
|
141
329
|
* @param messageId - The message ID to delete
|
|
@@ -143,13 +331,13 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
143
331
|
* @returns Promise with the result
|
|
144
332
|
*/
|
|
145
333
|
deleteMessageById(messageId: string, chatJid: string): Promise<any>;
|
|
146
|
-
sendTextMessage(to: string, text: string): Promise<any>;
|
|
147
|
-
sendButtonsMessage(to: string, { subtitle, title, buttons }: {
|
|
334
|
+
sendTextMessage(to: string | null, text: string): Promise<any>;
|
|
335
|
+
sendButtonsMessage(to: string | null, { subtitle, title, buttons }: {
|
|
148
336
|
title: string;
|
|
149
337
|
subtitle?: string;
|
|
150
338
|
buttons: CallToActionButtons;
|
|
151
339
|
}): Promise<any>;
|
|
152
|
-
sendMenuMessage(to: string, { title, subtitle, buttonText, sections, }: {
|
|
340
|
+
sendMenuMessage(to: string | null, { title, subtitle, buttonText, sections, }: {
|
|
153
341
|
title: string;
|
|
154
342
|
subtitle?: string;
|
|
155
343
|
buttonText: string;
|
|
@@ -162,7 +350,7 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
162
350
|
}>;
|
|
163
351
|
}>;
|
|
164
352
|
}): Promise<any>;
|
|
165
|
-
sendReplyButtonsMessage(to: string, { title, subtitle, buttons, }: {
|
|
353
|
+
sendReplyButtonsMessage(to: string | null, { title, subtitle, buttons, }: {
|
|
166
354
|
title: string;
|
|
167
355
|
subtitle?: string;
|
|
168
356
|
buttons: Array<string | {
|
|
@@ -170,28 +358,28 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
170
358
|
label: string;
|
|
171
359
|
}>;
|
|
172
360
|
}): Promise<any>;
|
|
173
|
-
sendLocationMessage(to: string, { latitude, longitude, name, address, }: {
|
|
361
|
+
sendLocationMessage(to: string | null, { latitude, longitude, name, address, }: {
|
|
174
362
|
latitude: number;
|
|
175
363
|
longitude: number;
|
|
176
364
|
name?: string;
|
|
177
365
|
address?: string;
|
|
178
366
|
}): Promise<any>;
|
|
179
|
-
sendSurveyMessage(to: string, { question, options, allowMultipleAnswers, }: {
|
|
367
|
+
sendSurveyMessage(to: string | null, { question, options, allowMultipleAnswers, }: {
|
|
180
368
|
question: string;
|
|
181
369
|
options: string[];
|
|
182
370
|
allowMultipleAnswers?: boolean;
|
|
183
371
|
}): Promise<any>;
|
|
184
|
-
sendReactionMessage(to: string, messageId: string, emoji: string): Promise<any>;
|
|
185
|
-
sendImageMessage(to: string, imageSrc: string | Buffer<any> | Stream, { caption, filename }?: {
|
|
372
|
+
sendReactionMessage(to: string | null, messageId: string, emoji: string): Promise<any>;
|
|
373
|
+
sendImageMessage(to: string | null, imageSrc: string | Buffer<any> | Stream, { caption, filename }?: {
|
|
186
374
|
caption?: string;
|
|
187
375
|
filename?: string;
|
|
188
376
|
}): Promise<any>;
|
|
189
|
-
sendVideoMessage(to: string, videoSrc: string | Buffer<any> | Stream, { caption, filename, sendAsGifPlayback, }?: {
|
|
377
|
+
sendVideoMessage(to: string | null, videoSrc: string | Buffer<any> | Stream, { caption, filename, sendAsGifPlayback, }?: {
|
|
190
378
|
caption?: string;
|
|
191
379
|
sendAsGifPlayback?: boolean;
|
|
192
380
|
filename?: string;
|
|
193
381
|
}): Promise<any>;
|
|
194
|
-
sendAudioMessage(to: string, audioSrc: string | Buffer<any> | Stream, { filename, replyToMessageId, mimetype, seconds, }?: {
|
|
382
|
+
sendAudioMessage(to: string | null, audioSrc: string | Buffer<any> | Stream, { filename, replyToMessageId, mimetype, seconds, }?: {
|
|
195
383
|
filename?: string;
|
|
196
384
|
replyToMessageId?: string;
|
|
197
385
|
mimetype?: string;
|
|
@@ -206,8 +394,8 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
206
394
|
* @param to
|
|
207
395
|
* @param imageSrc
|
|
208
396
|
*/
|
|
209
|
-
sendStickerMessage(to: string, imageSrc: string | Buffer<any> | Stream): Promise<any>;
|
|
210
|
-
sendFileMessage(to: string, fileSrc: string | Buffer<any> | Stream, { caption, mimetype, jpegThumbnailSrc, autoMessageClassification, filename, }: {
|
|
397
|
+
sendStickerMessage(to: string | null, imageSrc: string | Buffer<any> | Stream): Promise<any>;
|
|
398
|
+
sendFileMessage(to: string | null, fileSrc: string | Buffer<any> | Stream, { caption, mimetype, jpegThumbnailSrc, autoMessageClassification, filename, }: {
|
|
211
399
|
caption?: string;
|
|
212
400
|
mimetype?: string;
|
|
213
401
|
filename: string;
|
|
@@ -222,7 +410,7 @@ declare class WhatsappSocket extends WhatsappSocketPrivateMessages {
|
|
|
222
410
|
onAnyMessageReceived(cb: MessageReceivedCB): void;
|
|
223
411
|
offAnyMessageReceived(cb: MessageReceivedCB): void;
|
|
224
412
|
onPhoneMessageReceived(phone: string, cb: MessageReceivedCB): void;
|
|
225
|
-
offPhoneMessageReceived(phone: string, cb
|
|
413
|
+
offPhoneMessageReceived(phone: string, cb?: MessageReceivedCB): void;
|
|
226
414
|
}
|
|
227
415
|
|
|
228
416
|
declare class WhatsappSocketGroups extends WhatsappSocketBase {
|
|
@@ -445,4 +633,32 @@ declare class WhatsappSocketGroup extends WhatsappSocketGroupMessages {
|
|
|
445
633
|
offGroupMessageReceived(groupId: string, cb: MessageReceivedCB): void;
|
|
446
634
|
}
|
|
447
635
|
|
|
448
|
-
|
|
636
|
+
declare class WhatsappSocketBot {
|
|
637
|
+
protected schema: BotSchema;
|
|
638
|
+
protected phone?: string;
|
|
639
|
+
protected client?: WhatsappSocket;
|
|
640
|
+
private schemaRefs;
|
|
641
|
+
private remoteFlow;
|
|
642
|
+
private dataFlow;
|
|
643
|
+
private timeoutFlow;
|
|
644
|
+
private lastMessages;
|
|
645
|
+
constructor(schema: BotSchema, phone?: string);
|
|
646
|
+
updateSchemaRefs(flow: undefined | Scenario): void;
|
|
647
|
+
set socket(socket: WhatsappSocket);
|
|
648
|
+
get socket(): WhatsappSocket;
|
|
649
|
+
private sendMessageList;
|
|
650
|
+
private getFlow;
|
|
651
|
+
private setFlow;
|
|
652
|
+
private resetFlow;
|
|
653
|
+
private getDataFlow;
|
|
654
|
+
private getLastMessages;
|
|
655
|
+
private setDataFlow;
|
|
656
|
+
private resetDataFlow;
|
|
657
|
+
private setTimeoutFlow;
|
|
658
|
+
private resetTimeoutFlow;
|
|
659
|
+
private getResponseId;
|
|
660
|
+
private onMessageReceivedCB;
|
|
661
|
+
onMessageReceived(): void;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export { type BotSchema, WhatsappSocket, WhatsappSocketBot, WhatsappSocketGroup, type WhatsappSocketGroupProps, type WhatsappSocketProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Stream from 'node:stream';
|
|
2
|
+
import { WASocket, UserFacingSocketConfig, WAMessage, Contact, GroupMetadata } from '@fadzzzslebew/baileys';
|
|
2
3
|
import { StringValue } from 'ms';
|
|
3
4
|
import { Logger } from 'stack-trace-logger';
|
|
4
|
-
import Stream from 'node:stream';
|
|
5
5
|
|
|
6
6
|
type ButtonURL = {
|
|
7
7
|
label: string;
|
|
@@ -113,6 +113,7 @@ declare class WhatsappSocketBase {
|
|
|
113
113
|
autoConnect?: boolean;
|
|
114
114
|
}): Promise<void>;
|
|
115
115
|
isConnected(): boolean;
|
|
116
|
+
myJID(): string | null;
|
|
116
117
|
/**
|
|
117
118
|
* Delete a message for everyone (if within time limit) or just for yourself
|
|
118
119
|
* @param messageId - The message ID to delete
|
|
@@ -132,10 +133,197 @@ declare class WhatsappSocketBase {
|
|
|
132
133
|
chatJid: string;
|
|
133
134
|
}>, deleteForEveryone?: true): Promise<any[]>;
|
|
134
135
|
loadRecentMessages(chatJid: string, messageId: string): Promise<WAMessage | null>;
|
|
136
|
+
getContactByJid(remoteJid: string): Promise<Contact | undefined>;
|
|
137
|
+
getContacts(username?: string, byWords?: boolean): Promise<Contact[]>;
|
|
138
|
+
areRegisteredOnWhatsApp(phone: string | string[]): Promise<Array<{
|
|
139
|
+
phone: string;
|
|
140
|
+
exists: boolean;
|
|
141
|
+
jid?: string;
|
|
142
|
+
contact: Contact | undefined;
|
|
143
|
+
}>>;
|
|
135
144
|
}
|
|
136
145
|
|
|
146
|
+
type MenuMessageProps = {
|
|
147
|
+
title: string;
|
|
148
|
+
subtitle?: string;
|
|
149
|
+
buttonText: string;
|
|
150
|
+
sections: Array<{
|
|
151
|
+
title: string;
|
|
152
|
+
rows: Array<{
|
|
153
|
+
id: string;
|
|
154
|
+
title: string;
|
|
155
|
+
description?: string;
|
|
156
|
+
}>;
|
|
157
|
+
}>;
|
|
158
|
+
};
|
|
159
|
+
type AudioMessageProps = {
|
|
160
|
+
filename?: string;
|
|
161
|
+
replyToMessageId?: string;
|
|
162
|
+
mimetype?: string;
|
|
163
|
+
seconds?: number;
|
|
164
|
+
ptt?: boolean;
|
|
165
|
+
mentions?: string[];
|
|
166
|
+
};
|
|
167
|
+
type ButtonsMessageProps = {
|
|
168
|
+
title: string;
|
|
169
|
+
subtitle?: string;
|
|
170
|
+
buttons: CallToActionButtons;
|
|
171
|
+
};
|
|
172
|
+
type DocumentMessageProps = {
|
|
173
|
+
filename?: string;
|
|
174
|
+
caption?: string;
|
|
175
|
+
mimetype?: string;
|
|
176
|
+
mentions?: string[];
|
|
177
|
+
jpegThumbnail?: Buffer | string;
|
|
178
|
+
};
|
|
179
|
+
type ImageMessageProps = {
|
|
180
|
+
caption?: string;
|
|
181
|
+
filename?: string;
|
|
182
|
+
mentions?: string[];
|
|
183
|
+
};
|
|
184
|
+
type ReplyMessageProps = {
|
|
185
|
+
title: string;
|
|
186
|
+
subtitle?: string;
|
|
187
|
+
buttons: Array<string | {
|
|
188
|
+
id: number | string;
|
|
189
|
+
label: string;
|
|
190
|
+
}>;
|
|
191
|
+
};
|
|
192
|
+
type SurveyMessageProps = {
|
|
193
|
+
question: string;
|
|
194
|
+
options: string[];
|
|
195
|
+
allowMultipleAnswers?: boolean;
|
|
196
|
+
};
|
|
197
|
+
type TextMessageProps = {
|
|
198
|
+
text: string;
|
|
199
|
+
};
|
|
200
|
+
type VideoMessageProps = {
|
|
201
|
+
caption?: string;
|
|
202
|
+
sendAsGifPlayback?: boolean;
|
|
203
|
+
filename?: string;
|
|
204
|
+
mentions?: string[];
|
|
205
|
+
};
|
|
206
|
+
type LocationMessageProps = {
|
|
207
|
+
latitude: number;
|
|
208
|
+
longitude: number;
|
|
209
|
+
name?: string;
|
|
210
|
+
address?: string;
|
|
211
|
+
};
|
|
212
|
+
type StickerMessageProps = {
|
|
213
|
+
mentions?: string[];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
type ReplyMessage = Omit<ReplyMessageProps, 'buttons'> & {
|
|
217
|
+
buttons: Array<{
|
|
218
|
+
id: number | string;
|
|
219
|
+
label: string;
|
|
220
|
+
}>;
|
|
221
|
+
};
|
|
222
|
+
type Message = {
|
|
223
|
+
timeout?: StringValue | number;
|
|
224
|
+
forceExit?: boolean;
|
|
225
|
+
text: TextMessageProps;
|
|
226
|
+
} | {
|
|
227
|
+
timeout?: StringValue | number;
|
|
228
|
+
forceExit?: boolean;
|
|
229
|
+
menu: MenuMessageProps;
|
|
230
|
+
} | {
|
|
231
|
+
timeout?: StringValue | number;
|
|
232
|
+
forceExit?: boolean;
|
|
233
|
+
reply: ReplyMessage;
|
|
234
|
+
} | {
|
|
235
|
+
timeout?: StringValue | number;
|
|
236
|
+
forceExit?: boolean;
|
|
237
|
+
buttons: ButtonsMessageProps;
|
|
238
|
+
} | {
|
|
239
|
+
timeout?: StringValue | number;
|
|
240
|
+
forceExit?: boolean;
|
|
241
|
+
survey: SurveyMessageProps;
|
|
242
|
+
} | {
|
|
243
|
+
timeout?: StringValue | number;
|
|
244
|
+
forceExit?: boolean;
|
|
245
|
+
image: ImageMessageProps;
|
|
246
|
+
} | {
|
|
247
|
+
timeout?: StringValue | number;
|
|
248
|
+
forceExit?: boolean;
|
|
249
|
+
video: VideoMessageProps;
|
|
250
|
+
} | {
|
|
251
|
+
timeout?: StringValue | number;
|
|
252
|
+
forceExit?: boolean;
|
|
253
|
+
sticker: StickerMessageProps;
|
|
254
|
+
} | {
|
|
255
|
+
timeout?: StringValue | number;
|
|
256
|
+
forceExit?: boolean;
|
|
257
|
+
audio: AudioMessageProps;
|
|
258
|
+
} | {
|
|
259
|
+
timeout?: StringValue | number;
|
|
260
|
+
forceExit?: boolean;
|
|
261
|
+
document: DocumentMessageProps;
|
|
262
|
+
} | {
|
|
263
|
+
timeout?: StringValue | number;
|
|
264
|
+
forceExit?: boolean;
|
|
265
|
+
location: LocationMessageProps;
|
|
266
|
+
};
|
|
267
|
+
type ScenarioResponse = {
|
|
268
|
+
field?: string;
|
|
269
|
+
onSubmit?: (values: {
|
|
270
|
+
messageId: string;
|
|
271
|
+
options?: any;
|
|
272
|
+
data?: any;
|
|
273
|
+
remoteJid: string;
|
|
274
|
+
}) => void | Promise<void>;
|
|
275
|
+
next?: Scenario;
|
|
276
|
+
};
|
|
277
|
+
type MessageCB = (remoteJid: string, dataFlow: any) => Message | Promise<Message>;
|
|
278
|
+
type MessageItem = MessageCB | Message;
|
|
279
|
+
type Scenario = {
|
|
280
|
+
field?: string;
|
|
281
|
+
messages: MessageItem[];
|
|
282
|
+
response?: Record<string, // input or buttonId
|
|
283
|
+
// input or buttonId
|
|
284
|
+
ScenarioResponse | undefined>;
|
|
285
|
+
};
|
|
286
|
+
type FieldSchema = {
|
|
287
|
+
parseFieldData?: (input: string) => any;
|
|
288
|
+
validate?: (input: string) => boolean;
|
|
289
|
+
validationError?: string | ((input?: string) => string);
|
|
290
|
+
};
|
|
291
|
+
type BotSchema = {
|
|
292
|
+
name?: string;
|
|
293
|
+
description?: string;
|
|
294
|
+
exitCode?: string;
|
|
295
|
+
exitMsg?: Message;
|
|
296
|
+
unknownInputMsg?: Message;
|
|
297
|
+
idleTimeout?: StringValue | number;
|
|
298
|
+
timeoutMsg?: Message;
|
|
299
|
+
backCode?: string;
|
|
300
|
+
matches?: (string | RegExp | ((remoteJid: string, textMsg: string, fromMe?: boolean) => boolean | Promise<boolean>))[];
|
|
301
|
+
flow?: Scenario;
|
|
302
|
+
fields?: Record<string, FieldSchema>;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
type MessageType = 'text' | 'reply' | 'menu' | 'buttons' | 'image' | 'video' | 'audio' | 'location';
|
|
137
306
|
declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
307
|
+
protected timers: Record<string, Record<number, {
|
|
308
|
+
timeoutId: number;
|
|
309
|
+
date: Date;
|
|
310
|
+
data: Message;
|
|
311
|
+
messageType: MessageType;
|
|
312
|
+
}>>;
|
|
138
313
|
constructor(props: WhatsappSocketBaseProps);
|
|
314
|
+
protected sendMessageByType(remoteJid: string | null, messageType: MessageType, message: any): Promise<void>;
|
|
315
|
+
setTimer(remoteJid: string, messageType: MessageType, message: any, timeout: number, autoSelfNotificationFormat?: string | null): Promise<NodeJS.Timeout>;
|
|
316
|
+
getTimers(remoteJid: string): {
|
|
317
|
+
code: string;
|
|
318
|
+
message: {
|
|
319
|
+
timeoutId: number;
|
|
320
|
+
date: Date;
|
|
321
|
+
data: Message;
|
|
322
|
+
messageType: MessageType;
|
|
323
|
+
};
|
|
324
|
+
}[];
|
|
325
|
+
removeTimerId(remoteJid: string, timerId: number): void;
|
|
326
|
+
resetTimers(remoteJid?: string): void;
|
|
139
327
|
/**
|
|
140
328
|
* Delete a sent message
|
|
141
329
|
* @param messageId - The message ID to delete
|
|
@@ -143,13 +331,13 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
143
331
|
* @returns Promise with the result
|
|
144
332
|
*/
|
|
145
333
|
deleteMessageById(messageId: string, chatJid: string): Promise<any>;
|
|
146
|
-
sendTextMessage(to: string, text: string): Promise<any>;
|
|
147
|
-
sendButtonsMessage(to: string, { subtitle, title, buttons }: {
|
|
334
|
+
sendTextMessage(to: string | null, text: string): Promise<any>;
|
|
335
|
+
sendButtonsMessage(to: string | null, { subtitle, title, buttons }: {
|
|
148
336
|
title: string;
|
|
149
337
|
subtitle?: string;
|
|
150
338
|
buttons: CallToActionButtons;
|
|
151
339
|
}): Promise<any>;
|
|
152
|
-
sendMenuMessage(to: string, { title, subtitle, buttonText, sections, }: {
|
|
340
|
+
sendMenuMessage(to: string | null, { title, subtitle, buttonText, sections, }: {
|
|
153
341
|
title: string;
|
|
154
342
|
subtitle?: string;
|
|
155
343
|
buttonText: string;
|
|
@@ -162,7 +350,7 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
162
350
|
}>;
|
|
163
351
|
}>;
|
|
164
352
|
}): Promise<any>;
|
|
165
|
-
sendReplyButtonsMessage(to: string, { title, subtitle, buttons, }: {
|
|
353
|
+
sendReplyButtonsMessage(to: string | null, { title, subtitle, buttons, }: {
|
|
166
354
|
title: string;
|
|
167
355
|
subtitle?: string;
|
|
168
356
|
buttons: Array<string | {
|
|
@@ -170,28 +358,28 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
170
358
|
label: string;
|
|
171
359
|
}>;
|
|
172
360
|
}): Promise<any>;
|
|
173
|
-
sendLocationMessage(to: string, { latitude, longitude, name, address, }: {
|
|
361
|
+
sendLocationMessage(to: string | null, { latitude, longitude, name, address, }: {
|
|
174
362
|
latitude: number;
|
|
175
363
|
longitude: number;
|
|
176
364
|
name?: string;
|
|
177
365
|
address?: string;
|
|
178
366
|
}): Promise<any>;
|
|
179
|
-
sendSurveyMessage(to: string, { question, options, allowMultipleAnswers, }: {
|
|
367
|
+
sendSurveyMessage(to: string | null, { question, options, allowMultipleAnswers, }: {
|
|
180
368
|
question: string;
|
|
181
369
|
options: string[];
|
|
182
370
|
allowMultipleAnswers?: boolean;
|
|
183
371
|
}): Promise<any>;
|
|
184
|
-
sendReactionMessage(to: string, messageId: string, emoji: string): Promise<any>;
|
|
185
|
-
sendImageMessage(to: string, imageSrc: string | Buffer<any> | Stream, { caption, filename }?: {
|
|
372
|
+
sendReactionMessage(to: string | null, messageId: string, emoji: string): Promise<any>;
|
|
373
|
+
sendImageMessage(to: string | null, imageSrc: string | Buffer<any> | Stream, { caption, filename }?: {
|
|
186
374
|
caption?: string;
|
|
187
375
|
filename?: string;
|
|
188
376
|
}): Promise<any>;
|
|
189
|
-
sendVideoMessage(to: string, videoSrc: string | Buffer<any> | Stream, { caption, filename, sendAsGifPlayback, }?: {
|
|
377
|
+
sendVideoMessage(to: string | null, videoSrc: string | Buffer<any> | Stream, { caption, filename, sendAsGifPlayback, }?: {
|
|
190
378
|
caption?: string;
|
|
191
379
|
sendAsGifPlayback?: boolean;
|
|
192
380
|
filename?: string;
|
|
193
381
|
}): Promise<any>;
|
|
194
|
-
sendAudioMessage(to: string, audioSrc: string | Buffer<any> | Stream, { filename, replyToMessageId, mimetype, seconds, }?: {
|
|
382
|
+
sendAudioMessage(to: string | null, audioSrc: string | Buffer<any> | Stream, { filename, replyToMessageId, mimetype, seconds, }?: {
|
|
195
383
|
filename?: string;
|
|
196
384
|
replyToMessageId?: string;
|
|
197
385
|
mimetype?: string;
|
|
@@ -206,8 +394,8 @@ declare class WhatsappSocketPrivateMessages extends WhatsappSocketBase {
|
|
|
206
394
|
* @param to
|
|
207
395
|
* @param imageSrc
|
|
208
396
|
*/
|
|
209
|
-
sendStickerMessage(to: string, imageSrc: string | Buffer<any> | Stream): Promise<any>;
|
|
210
|
-
sendFileMessage(to: string, fileSrc: string | Buffer<any> | Stream, { caption, mimetype, jpegThumbnailSrc, autoMessageClassification, filename, }: {
|
|
397
|
+
sendStickerMessage(to: string | null, imageSrc: string | Buffer<any> | Stream): Promise<any>;
|
|
398
|
+
sendFileMessage(to: string | null, fileSrc: string | Buffer<any> | Stream, { caption, mimetype, jpegThumbnailSrc, autoMessageClassification, filename, }: {
|
|
211
399
|
caption?: string;
|
|
212
400
|
mimetype?: string;
|
|
213
401
|
filename: string;
|
|
@@ -222,7 +410,7 @@ declare class WhatsappSocket extends WhatsappSocketPrivateMessages {
|
|
|
222
410
|
onAnyMessageReceived(cb: MessageReceivedCB): void;
|
|
223
411
|
offAnyMessageReceived(cb: MessageReceivedCB): void;
|
|
224
412
|
onPhoneMessageReceived(phone: string, cb: MessageReceivedCB): void;
|
|
225
|
-
offPhoneMessageReceived(phone: string, cb
|
|
413
|
+
offPhoneMessageReceived(phone: string, cb?: MessageReceivedCB): void;
|
|
226
414
|
}
|
|
227
415
|
|
|
228
416
|
declare class WhatsappSocketGroups extends WhatsappSocketBase {
|
|
@@ -445,4 +633,32 @@ declare class WhatsappSocketGroup extends WhatsappSocketGroupMessages {
|
|
|
445
633
|
offGroupMessageReceived(groupId: string, cb: MessageReceivedCB): void;
|
|
446
634
|
}
|
|
447
635
|
|
|
448
|
-
|
|
636
|
+
declare class WhatsappSocketBot {
|
|
637
|
+
protected schema: BotSchema;
|
|
638
|
+
protected phone?: string;
|
|
639
|
+
protected client?: WhatsappSocket;
|
|
640
|
+
private schemaRefs;
|
|
641
|
+
private remoteFlow;
|
|
642
|
+
private dataFlow;
|
|
643
|
+
private timeoutFlow;
|
|
644
|
+
private lastMessages;
|
|
645
|
+
constructor(schema: BotSchema, phone?: string);
|
|
646
|
+
updateSchemaRefs(flow: undefined | Scenario): void;
|
|
647
|
+
set socket(socket: WhatsappSocket);
|
|
648
|
+
get socket(): WhatsappSocket;
|
|
649
|
+
private sendMessageList;
|
|
650
|
+
private getFlow;
|
|
651
|
+
private setFlow;
|
|
652
|
+
private resetFlow;
|
|
653
|
+
private getDataFlow;
|
|
654
|
+
private getLastMessages;
|
|
655
|
+
private setDataFlow;
|
|
656
|
+
private resetDataFlow;
|
|
657
|
+
private setTimeoutFlow;
|
|
658
|
+
private resetTimeoutFlow;
|
|
659
|
+
private getResponseId;
|
|
660
|
+
private onMessageReceivedCB;
|
|
661
|
+
onMessageReceived(): void;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export { type BotSchema, WhatsappSocket, WhatsappSocketBot, WhatsappSocketGroup, type WhatsappSocketGroupProps, type WhatsappSocketProps };
|