wa-multi-mongodb 3.11.2 → 3.12.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/dist/Messaging/index.d.ts +2 -1
- package/dist/Messaging/index.d.ts.map +1 -1
- package/dist/Messaging/index.js +104 -0
- package/dist/Types/index.d.ts +14 -0
- package/dist/Types/index.d.ts.map +1 -1
- package/dist/cjs/Messaging/index.d.ts +2 -1
- package/dist/cjs/Messaging/index.d.ts.map +1 -1
- package/dist/cjs/Messaging/index.js +106 -1
- package/dist/cjs/Types/index.d.ts +14 -0
- package/dist/cjs/Types/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/readme.md +33 -11
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { proto } from "baileys";
|
|
2
|
-
import { SendMediaTypes, SendMessageTypes, SendReadTypes, SendTypingTypes, SendMessageWithMentionTypes } from "../Types/index.js";
|
|
2
|
+
import { SendButtonMessageTypes, SendMediaTypes, SendMessageTypes, SendReadTypes, SendTypingTypes, SendMessageWithMentionTypes } from "../Types/index.js";
|
|
3
3
|
export declare const sendTextMessage: ({ sessionId, to, text, isGroup, ...props }: SendMessageTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
4
|
+
export declare const sendButtonMessage: ({ sessionId, to, title, text, footer, image, aimode, buttons, isGroup, }: SendButtonMessageTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
4
5
|
/**
|
|
5
6
|
* Kirim pesan teks dengan mention
|
|
6
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Messaging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,SAAS,CAAC;AAGnD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,2BAA2B,EAC5B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","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|
@@ -26,6 +26,7 @@ import { createDelay, withTimeout } from "../Utils/create-delay.js";
|
|
|
26
26
|
import { isExist } from "../Utils/is-exist.js";
|
|
27
27
|
import mime from "mime";
|
|
28
28
|
import { WhatsappError } from "../Error/index.js";
|
|
29
|
+
import { sendButtons } from "gifted-btns";
|
|
29
30
|
export const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
31
|
var { sessionId, to, text = "", isGroup = false } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup"]);
|
|
31
32
|
const session = getSession(sessionId);
|
|
@@ -132,6 +133,109 @@ export const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, functio
|
|
|
132
133
|
});
|
|
133
134
|
return attemptSend();
|
|
134
135
|
});
|
|
136
|
+
export const sendButtonMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, to, title, text, footer, image, aimode = false, buttons, isGroup = false, }) {
|
|
137
|
+
const session = getSession(sessionId);
|
|
138
|
+
if (!session)
|
|
139
|
+
throw new WhatsappError(Messages.sessionNotFound(sessionId));
|
|
140
|
+
const toStr = to.toString();
|
|
141
|
+
const isGroupChat = toStr.includes('@g.us');
|
|
142
|
+
let jid;
|
|
143
|
+
if (isGroupChat) {
|
|
144
|
+
if (!toStr.endsWith('@g.us')) {
|
|
145
|
+
jid = toStr + '@g.us';
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
jid = toStr;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
jid = phoneToJid({ to, isGroup: isGroup || isGroupChat });
|
|
153
|
+
}
|
|
154
|
+
if (!isValidJid(jid)) {
|
|
155
|
+
throw new WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
|
|
156
|
+
}
|
|
157
|
+
if (!text || !text.trim()) {
|
|
158
|
+
throw new WhatsappError("Button message text is required");
|
|
159
|
+
}
|
|
160
|
+
if (!Array.isArray(buttons) || buttons.length === 0) {
|
|
161
|
+
throw new WhatsappError("Button message requires at least one button");
|
|
162
|
+
}
|
|
163
|
+
const hasInvalidButton = buttons.some((button) => {
|
|
164
|
+
return !button || !button.id || !button.id.trim() || !button.text || !button.text.trim();
|
|
165
|
+
});
|
|
166
|
+
if (hasInvalidButton) {
|
|
167
|
+
throw new WhatsappError("Each button requires non-empty id and text");
|
|
168
|
+
}
|
|
169
|
+
let retryCount = 0;
|
|
170
|
+
const maxRetries = 3;
|
|
171
|
+
const createPayload = () => {
|
|
172
|
+
const payload = {
|
|
173
|
+
text,
|
|
174
|
+
aimode,
|
|
175
|
+
buttons,
|
|
176
|
+
};
|
|
177
|
+
if (title)
|
|
178
|
+
payload.title = title;
|
|
179
|
+
if (footer)
|
|
180
|
+
payload.footer = footer;
|
|
181
|
+
if (image)
|
|
182
|
+
payload.image = image;
|
|
183
|
+
return payload;
|
|
184
|
+
};
|
|
185
|
+
const normalizeResult = (result) => {
|
|
186
|
+
if (result && typeof result === "object") {
|
|
187
|
+
result.toJSON = () => ({});
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
};
|
|
191
|
+
const attemptSend = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
+
var _a, _b, _c;
|
|
193
|
+
try {
|
|
194
|
+
const isDestinationGroup = jid.endsWith('@g.us');
|
|
195
|
+
yield createDelay(500);
|
|
196
|
+
const timeoutMs = isDestinationGroup ? 15000 : 30000;
|
|
197
|
+
const result = yield sendButtons(session, jid, createPayload());
|
|
198
|
+
return yield withTimeout(Promise.resolve(normalizeResult(result)), timeoutMs, `Pengiriman button message ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
console.error(`Error saat mengirim button message (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
|
|
202
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('MessageCounterError')) || ((_b = error === null || error === void 0 ? void 0 : error.stack) === null || _b === void 0 ? void 0 : _b.includes('MessageCounterError'))) {
|
|
203
|
+
console.warn('Terdeteksi MessageCounterError, kemungkinan grup dengan channel pengumuman');
|
|
204
|
+
if (retryCount < maxRetries) {
|
|
205
|
+
retryCount++;
|
|
206
|
+
yield createDelay(2000 * retryCount);
|
|
207
|
+
return attemptSend();
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.error('Batas maksimum percobaan ulang tercapai');
|
|
211
|
+
throw new WhatsappError(`Gagal mengirim button message ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection Closed')) {
|
|
215
|
+
try {
|
|
216
|
+
yield reconnect(sessionId);
|
|
217
|
+
yield createDelay(3000);
|
|
218
|
+
const reconnectResult = yield sendButtons(session, jid, createPayload());
|
|
219
|
+
return yield withTimeout(Promise.resolve(normalizeResult(reconnectResult)), 30000, `Pengiriman button message setelah reconnect melebihi batas waktu`);
|
|
220
|
+
}
|
|
221
|
+
catch (reconnectError) {
|
|
222
|
+
console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
|
|
223
|
+
throw new WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
yield createDelay(2000);
|
|
228
|
+
const retryResult = yield sendButtons(session, jid, createPayload());
|
|
229
|
+
return yield withTimeout(Promise.resolve(normalizeResult(retryResult)), 20000, `Percobaan kedua pengiriman button message melebihi batas waktu`);
|
|
230
|
+
}
|
|
231
|
+
catch (retryError) {
|
|
232
|
+
console.error(`Gagal pada percobaan kedua: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
|
|
233
|
+
throw new WhatsappError(`Gagal mengirim button message: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
return attemptSend();
|
|
238
|
+
});
|
|
135
239
|
/**
|
|
136
240
|
* Kirim pesan teks dengan mention
|
|
137
241
|
*
|
package/dist/Types/index.d.ts
CHANGED
|
@@ -17,6 +17,20 @@ export interface SendMessageTypes {
|
|
|
17
17
|
export interface SendMessageWithMentionTypes extends SendMessageTypes {
|
|
18
18
|
mentions?: string[];
|
|
19
19
|
}
|
|
20
|
+
export interface SendButtonMessageButton {
|
|
21
|
+
id: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SendButtonMessageTypes extends Omit<SendMessageTypes, "text"> {
|
|
25
|
+
title?: string;
|
|
26
|
+
text: string;
|
|
27
|
+
footer?: string;
|
|
28
|
+
image?: {
|
|
29
|
+
url: string;
|
|
30
|
+
} | Buffer | string;
|
|
31
|
+
aimode?: boolean;
|
|
32
|
+
buttons: SendButtonMessageButton[];
|
|
33
|
+
}
|
|
20
34
|
export interface SendMediaTypes extends SendMessageTypes {
|
|
21
35
|
media: string | Buffer;
|
|
22
36
|
type: "image" | "video" | "audio" | "pdf" | "xls" | "xlsx" | "doc" | "docx" | "zip" | "mp3";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,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AM,IAAI,CAAC;IAC5B,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAGvC,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;IACvD,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EACX,OAAO,GACP,SAAS,GACT,QAAQ,GACR,WAAW,GACX,MAAM,GACN,QAAQ,CAAC;CACZ,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { proto } from "baileys";
|
|
2
|
-
import { SendMediaTypes, SendMessageTypes, SendReadTypes, SendTypingTypes, SendMessageWithMentionTypes } from "../Types";
|
|
2
|
+
import { SendButtonMessageTypes, SendMediaTypes, SendMessageTypes, SendReadTypes, SendTypingTypes, SendMessageWithMentionTypes } from "../Types";
|
|
3
3
|
export declare const sendTextMessage: ({ sessionId, to, text, isGroup, ...props }: SendMessageTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
4
|
+
export declare const sendButtonMessage: ({ sessionId, to, title, text, footer, image, aimode, buttons, isGroup, }: SendButtonMessageTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
4
5
|
/**
|
|
5
6
|
* Kirim pesan teks dengan mention
|
|
6
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Messaging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,SAAS,CAAC;AAGnD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,2BAA2B,EAC5B,MAAM,UAAU,CAAC;
|
|
1
|
+
{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C"}
|
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.deleteMessage = exports.readMessage = exports.sendTyping = exports.sendSticker = exports.sendVoiceNote = exports.sendMedia = exports.sendTextMessageWithMention = exports.sendTextMessage = void 0;
|
|
26
|
+
exports.deleteMessage = exports.readMessage = exports.sendTyping = exports.sendSticker = exports.sendVoiceNote = exports.sendMedia = exports.sendTextMessageWithMention = exports.sendButtonMessage = exports.sendTextMessage = void 0;
|
|
27
27
|
const Defaults_1 = require("../Defaults");
|
|
28
28
|
const Socket_1 = require("../Socket");
|
|
29
29
|
const Utils_1 = require("../Utils");
|
|
@@ -32,6 +32,7 @@ const create_delay_1 = require("../Utils/create-delay");
|
|
|
32
32
|
const is_exist_1 = require("../Utils/is-exist");
|
|
33
33
|
const mime_1 = __importDefault(require("mime"));
|
|
34
34
|
const Error_1 = require("../Error");
|
|
35
|
+
const gifted_btns_1 = require("gifted-btns");
|
|
35
36
|
const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
37
|
var { sessionId, to, text = "", isGroup = false } = _a, props = __rest(_a, ["sessionId", "to", "text", "isGroup"]);
|
|
37
38
|
const session = (0, Socket_1.getSession)(sessionId);
|
|
@@ -139,6 +140,110 @@ const sendTextMessage = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
139
140
|
return attemptSend();
|
|
140
141
|
});
|
|
141
142
|
exports.sendTextMessage = sendTextMessage;
|
|
143
|
+
const sendButtonMessage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ sessionId, to, title, text, footer, image, aimode = false, buttons, isGroup = false, }) {
|
|
144
|
+
const session = (0, Socket_1.getSession)(sessionId);
|
|
145
|
+
if (!session)
|
|
146
|
+
throw new Error_1.WhatsappError(Defaults_1.Messages.sessionNotFound(sessionId));
|
|
147
|
+
const toStr = to.toString();
|
|
148
|
+
const isGroupChat = toStr.includes('@g.us');
|
|
149
|
+
let jid;
|
|
150
|
+
if (isGroupChat) {
|
|
151
|
+
if (!toStr.endsWith('@g.us')) {
|
|
152
|
+
jid = toStr + '@g.us';
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
jid = toStr;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
jid = (0, Utils_1.phoneToJid)({ to, isGroup: isGroup || isGroupChat });
|
|
160
|
+
}
|
|
161
|
+
if (!(0, Utils_2.isValidJid)(jid)) {
|
|
162
|
+
throw new Error_1.WhatsappError(`Invalid JID format: ${jid}. Supported formats: @s.whatsapp.net, @lid, @g.us`);
|
|
163
|
+
}
|
|
164
|
+
if (!text || !text.trim()) {
|
|
165
|
+
throw new Error_1.WhatsappError("Button message text is required");
|
|
166
|
+
}
|
|
167
|
+
if (!Array.isArray(buttons) || buttons.length === 0) {
|
|
168
|
+
throw new Error_1.WhatsappError("Button message requires at least one button");
|
|
169
|
+
}
|
|
170
|
+
const hasInvalidButton = buttons.some((button) => {
|
|
171
|
+
return !button || !button.id || !button.id.trim() || !button.text || !button.text.trim();
|
|
172
|
+
});
|
|
173
|
+
if (hasInvalidButton) {
|
|
174
|
+
throw new Error_1.WhatsappError("Each button requires non-empty id and text");
|
|
175
|
+
}
|
|
176
|
+
let retryCount = 0;
|
|
177
|
+
const maxRetries = 3;
|
|
178
|
+
const createPayload = () => {
|
|
179
|
+
const payload = {
|
|
180
|
+
text,
|
|
181
|
+
aimode,
|
|
182
|
+
buttons,
|
|
183
|
+
};
|
|
184
|
+
if (title)
|
|
185
|
+
payload.title = title;
|
|
186
|
+
if (footer)
|
|
187
|
+
payload.footer = footer;
|
|
188
|
+
if (image)
|
|
189
|
+
payload.image = image;
|
|
190
|
+
return payload;
|
|
191
|
+
};
|
|
192
|
+
const normalizeResult = (result) => {
|
|
193
|
+
if (result && typeof result === "object") {
|
|
194
|
+
result.toJSON = () => ({});
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
};
|
|
198
|
+
const attemptSend = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
+
var _a, _b, _c;
|
|
200
|
+
try {
|
|
201
|
+
const isDestinationGroup = jid.endsWith('@g.us');
|
|
202
|
+
yield (0, create_delay_1.createDelay)(500);
|
|
203
|
+
const timeoutMs = isDestinationGroup ? 15000 : 30000;
|
|
204
|
+
const result = yield (0, gifted_btns_1.sendButtons)(session, jid, createPayload());
|
|
205
|
+
return yield (0, create_delay_1.withTimeout)(Promise.resolve(normalizeResult(result)), timeoutMs, `Pengiriman button message ke ${jid} melebihi batas waktu ${timeoutMs / 1000} detik`);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
console.error(`Error saat mengirim button message (percobaan ${retryCount + 1}/${maxRetries}): ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
|
|
209
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('MessageCounterError')) || ((_b = error === null || error === void 0 ? void 0 : error.stack) === null || _b === void 0 ? void 0 : _b.includes('MessageCounterError'))) {
|
|
210
|
+
console.warn('Terdeteksi MessageCounterError, kemungkinan grup dengan channel pengumuman');
|
|
211
|
+
if (retryCount < maxRetries) {
|
|
212
|
+
retryCount++;
|
|
213
|
+
yield (0, create_delay_1.createDelay)(2000 * retryCount);
|
|
214
|
+
return attemptSend();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
console.error('Batas maksimum percobaan ulang tercapai');
|
|
218
|
+
throw new Error_1.WhatsappError(`Gagal mengirim button message ke grup dengan channel pengumuman setelah ${maxRetries} kali percobaan`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection Closed')) {
|
|
222
|
+
try {
|
|
223
|
+
yield (0, Socket_1.reconnect)(sessionId);
|
|
224
|
+
yield (0, create_delay_1.createDelay)(3000);
|
|
225
|
+
const reconnectResult = yield (0, gifted_btns_1.sendButtons)(session, jid, createPayload());
|
|
226
|
+
return yield (0, create_delay_1.withTimeout)(Promise.resolve(normalizeResult(reconnectResult)), 30000, `Pengiriman button message setelah reconnect melebihi batas waktu`);
|
|
227
|
+
}
|
|
228
|
+
catch (reconnectError) {
|
|
229
|
+
console.error(`Gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
|
|
230
|
+
throw new Error_1.WhatsappError(`Koneksi terputus dan gagal reconnect: ${(reconnectError === null || reconnectError === void 0 ? void 0 : reconnectError.message) || 'Unknown error'}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
yield (0, create_delay_1.createDelay)(2000);
|
|
235
|
+
const retryResult = yield (0, gifted_btns_1.sendButtons)(session, jid, createPayload());
|
|
236
|
+
return yield (0, create_delay_1.withTimeout)(Promise.resolve(normalizeResult(retryResult)), 20000, `Percobaan kedua pengiriman button message melebihi batas waktu`);
|
|
237
|
+
}
|
|
238
|
+
catch (retryError) {
|
|
239
|
+
console.error(`Gagal pada percobaan kedua: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
|
|
240
|
+
throw new Error_1.WhatsappError(`Gagal mengirim button message: ${(retryError === null || retryError === void 0 ? void 0 : retryError.message) || 'Unknown error'}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return attemptSend();
|
|
245
|
+
});
|
|
246
|
+
exports.sendButtonMessage = sendButtonMessage;
|
|
142
247
|
/**
|
|
143
248
|
* Kirim pesan teks dengan mention
|
|
144
249
|
*
|
|
@@ -17,6 +17,20 @@ export interface SendMessageTypes {
|
|
|
17
17
|
export interface SendMessageWithMentionTypes extends SendMessageTypes {
|
|
18
18
|
mentions?: string[];
|
|
19
19
|
}
|
|
20
|
+
export interface SendButtonMessageButton {
|
|
21
|
+
id: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SendButtonMessageTypes extends Omit<SendMessageTypes, "text"> {
|
|
25
|
+
title?: string;
|
|
26
|
+
text: string;
|
|
27
|
+
footer?: string;
|
|
28
|
+
image?: {
|
|
29
|
+
url: string;
|
|
30
|
+
} | Buffer | string;
|
|
31
|
+
aimode?: boolean;
|
|
32
|
+
buttons: SendButtonMessageButton[];
|
|
33
|
+
}
|
|
20
34
|
export interface SendMediaTypes extends SendMessageTypes {
|
|
21
35
|
media: string | Buffer;
|
|
22
36
|
type: "image" | "video" | "audio" | "pdf" | "xls" | "xlsx" | "doc" | "docx" | "zip" | "mp3";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC;CACnC;AAED,MAAM,WAAW,2BAA4B,SAAQ,gBAAgB;IACnE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM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AW,GACX,MAAM,GACN,QAAQ,CAAC;CACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wa-multi-mongodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"description": "Multi Session Whatsapp Library with MongoDB Integration",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"aws4": "^1.13.2",
|
|
36
36
|
"baileys": "^7.0.0-rc13",
|
|
37
37
|
"dotenv": "^16.5.0",
|
|
38
|
+
"gifted-btns": "^1.0.2",
|
|
38
39
|
"link-preview-js": "^3.0.14",
|
|
39
40
|
"mime": "^4.1.0",
|
|
40
41
|
"mongodb": "^5.7.0",
|
package/readme.md
CHANGED
|
@@ -368,15 +368,30 @@ await whatsapp.sendTextMessage({
|
|
|
368
368
|
});
|
|
369
369
|
|
|
370
370
|
// Send to a group (compatible with older versions)
|
|
371
|
-
await whatsapp.sendTextMessage({
|
|
372
|
-
sessionId: "mysession",
|
|
373
|
-
to: "120363152682073800", // group ID
|
|
374
|
-
text: "Hello group!",
|
|
375
|
-
isGroup: true // still works but optional in v3.9.0+
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
// Send
|
|
379
|
-
await whatsapp.
|
|
371
|
+
await whatsapp.sendTextMessage({
|
|
372
|
+
sessionId: "mysession",
|
|
373
|
+
to: "120363152682073800", // group ID
|
|
374
|
+
text: "Hello group!",
|
|
375
|
+
isGroup: true // still works but optional in v3.9.0+
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// Send button message
|
|
379
|
+
await whatsapp.sendButtonMessage({
|
|
380
|
+
sessionId: "mysession",
|
|
381
|
+
to: "6281234567890",
|
|
382
|
+
title: "Header Title", // optional
|
|
383
|
+
text: "Pick one option below",
|
|
384
|
+
footer: "Footer text", // optional
|
|
385
|
+
image: { url: "https://example.com/image.jpg" }, // optional, can be URL, buffer, or path
|
|
386
|
+
aimode: true, // optional, defaults to false
|
|
387
|
+
buttons: [
|
|
388
|
+
{ id: "quick_1", text: "Quick Reply" }
|
|
389
|
+
],
|
|
390
|
+
// isGroup parameter is optional (v3.9.0+)
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// Send media (unified function)
|
|
394
|
+
await whatsapp.sendMedia({
|
|
380
395
|
sessionId: "mysession",
|
|
381
396
|
to: "6281234567890",
|
|
382
397
|
type: "image", // options: image, video, pdf, doc, docx, xls, xlsx, zip, mp3
|
|
@@ -1151,8 +1166,15 @@ export default WhatsAppQRComponent;
|
|
|
1151
1166
|
|
|
1152
1167
|
## Changelog
|
|
1153
1168
|
|
|
1154
|
-
### v3.
|
|
1155
|
-
- **
|
|
1169
|
+
### v3.12.0 (latest)
|
|
1170
|
+
- **Button Message Support**: Added `sendButtonMessage()` for sending WhatsApp button messages
|
|
1171
|
+
- Supports title, body text, footer, image, AI mode, and quick reply buttons
|
|
1172
|
+
- Includes validation for required button text and non-empty button IDs
|
|
1173
|
+
- Works with private chats and groups using the existing automatic JID detection
|
|
1174
|
+
- Uses the same retry, reconnect, and timeout handling pattern as text messages
|
|
1175
|
+
|
|
1176
|
+
### v3.11.0
|
|
1177
|
+
- **New `downloadMediaMessage` Function**: Download incoming WhatsApp media messages directly as a `Buffer`
|
|
1156
1178
|
- Supports images, videos, documents, audio, stickers, and other Baileys-supported media messages
|
|
1157
1179
|
- Uses the active session for media reupload requests when WhatsApp media links have expired
|
|
1158
1180
|
- Useful for cloud uploads, custom storage, media processing, forwarding workflows, and API responses
|