@victory_is_h1m/custom-baileys 0.0.0-stage → 1.1.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 +12 -2
- package/dist/index.d.ts +31 -0
- package/dist/index.js +139 -0
- package/package.json +24 -4
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @victory_is_h1m/custom-baileys
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Custom WhatsApp Web API wrapper built on `@whiskeysockets/baileys` with built-in custom pairing code support (`VICT-ORYY`), auto-reconnect, and helper methods.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
```javascript
|
|
7
|
+
import createVictoryBaileys from '@victory_is_h1m/custom-baileys';
|
|
8
|
+
|
|
9
|
+
const bot = await createVictoryBaileys({
|
|
10
|
+
phoneNumber: '2348162843527',
|
|
11
|
+
customPairingCode: 'VICT-ORYY',
|
|
12
|
+
});
|
|
13
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UserFacingSocketConfig, WASocket } from "@whiskeysockets/baileys";
|
|
2
|
+
export * from "@whiskeysockets/baileys";
|
|
3
|
+
export interface CustomBotOptions {
|
|
4
|
+
sessionDir?: string;
|
|
5
|
+
phoneNumber?: string;
|
|
6
|
+
customPairingCode?: string;
|
|
7
|
+
autoReconnect?: boolean;
|
|
8
|
+
onPairingCode?: (formattedCode: string, rawCode: string) => void;
|
|
9
|
+
onReady?: (sock: WASocket) => void;
|
|
10
|
+
socketConfig?: Partial<UserFacingSocketConfig>;
|
|
11
|
+
}
|
|
12
|
+
export interface NativeButton {
|
|
13
|
+
type: "reply" | "url" | "copy" | "call" | "list";
|
|
14
|
+
displayText: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
copyCode?: string;
|
|
18
|
+
phoneNumber?: string;
|
|
19
|
+
sections?: any[];
|
|
20
|
+
}
|
|
21
|
+
export interface LinkCardOptions {
|
|
22
|
+
text: string;
|
|
23
|
+
title: string;
|
|
24
|
+
body?: string;
|
|
25
|
+
sourceUrl: string;
|
|
26
|
+
thumbnailUrl?: string;
|
|
27
|
+
thumbnailBuffer?: Buffer;
|
|
28
|
+
largeThumbnail?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function createVictoryBaileys(options?: CustomBotOptions): Promise<any>;
|
|
31
|
+
export default createVictoryBaileys;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import makeWASocket, { Browsers, DisconnectReason, useMultiFileAuthState, fetchLatestBaileysVersion, downloadMediaMessage, generateWAMessageFromContent, prepareWAMessageMedia, proto, } from "@whiskeysockets/baileys";
|
|
2
|
+
export * from "@whiskeysockets/baileys";
|
|
3
|
+
export async function createVictoryBaileys(options = {}) {
|
|
4
|
+
const { sessionDir = "./auth_session", phoneNumber, customPairingCode = "VICT-ORYY", autoReconnect = true, onPairingCode, onReady, socketConfig = {}, } = options;
|
|
5
|
+
const { state, saveCreds } = await useMultiFileAuthState(sessionDir);
|
|
6
|
+
const { version } = await fetchLatestBaileysVersion();
|
|
7
|
+
let pairingRequested = false;
|
|
8
|
+
const sock = makeWASocket({
|
|
9
|
+
version,
|
|
10
|
+
auth: state,
|
|
11
|
+
browser: Browsers.ubuntu("Chrome"),
|
|
12
|
+
syncFullHistory: true,
|
|
13
|
+
markOnlineOnConnect: true,
|
|
14
|
+
...socketConfig,
|
|
15
|
+
});
|
|
16
|
+
sock.ev.on("creds.update", saveCreds);
|
|
17
|
+
sock.ev.on("connection.update", async (update) => {
|
|
18
|
+
const { connection, lastDisconnect, qr } = update;
|
|
19
|
+
if ((qr || connection === "connecting") && !state.creds.registered && phoneNumber && !pairingRequested) {
|
|
20
|
+
pairingRequested = true;
|
|
21
|
+
try {
|
|
22
|
+
const cleanNumber = phoneNumber.replace(/\D/g, "");
|
|
23
|
+
const cleanCode = customPairingCode.replace(/[^A-Za-z0-9]/g, "").toUpperCase();
|
|
24
|
+
await new Promise((res) => setTimeout(res, 1500));
|
|
25
|
+
const code = await sock.requestPairingCode(cleanNumber, cleanCode);
|
|
26
|
+
const formatted = `${code.slice(0, 4)}-${code.slice(4)}`;
|
|
27
|
+
if (onPairingCode)
|
|
28
|
+
onPairingCode(formatted, code);
|
|
29
|
+
else
|
|
30
|
+
console.log(`\n[VICTORY-BAILEYS] Pairing Code: ${formatted}\n`);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
pairingRequested = false;
|
|
34
|
+
console.error("[VICTORY-BAILEYS] Pairing code error:", err);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (connection === "open") {
|
|
38
|
+
console.log("[VICTORY-BAILEYS] Connected to WhatsApp!");
|
|
39
|
+
if (onReady)
|
|
40
|
+
onReady(sock);
|
|
41
|
+
}
|
|
42
|
+
if (connection === "close") {
|
|
43
|
+
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
44
|
+
if (autoReconnect && statusCode !== DisconnectReason.loggedOut) {
|
|
45
|
+
createVictoryBaileys(options);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const helpers = {
|
|
50
|
+
sendText: (jid, text, mentions, quoted) => sock.sendMessage(jid, { text, mentions }, { quoted }),
|
|
51
|
+
sendLinkCard: (jid, card, quoted) => sock.sendMessage(jid, {
|
|
52
|
+
text: card.text,
|
|
53
|
+
contextInfo: {
|
|
54
|
+
externalAdReply: {
|
|
55
|
+
title: card.title,
|
|
56
|
+
body: card.body || "",
|
|
57
|
+
mediaType: 1,
|
|
58
|
+
renderLargerThumbnail: card.largeThumbnail !== false,
|
|
59
|
+
sourceUrl: card.sourceUrl,
|
|
60
|
+
thumbnailUrl: card.thumbnailUrl,
|
|
61
|
+
thumbnail: card.thumbnailBuffer,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}, { quoted }),
|
|
65
|
+
downloadViewOnce: async (msg) => {
|
|
66
|
+
const raw = msg.message;
|
|
67
|
+
const target = raw?.extendedTextMessage?.contextInfo?.quotedMessage || raw;
|
|
68
|
+
const unwrapped = target?.viewOnceMessageV2?.message || target?.viewOnceMessageV2Extension?.message || target?.viewOnceMessage?.message || target;
|
|
69
|
+
if (!unwrapped)
|
|
70
|
+
return null;
|
|
71
|
+
const type = unwrapped.imageMessage ? "image" : unwrapped.videoMessage ? "video" : unwrapped.audioMessage ? "audio" : null;
|
|
72
|
+
if (!type)
|
|
73
|
+
return null;
|
|
74
|
+
const caption = unwrapped.imageMessage?.caption || unwrapped.videoMessage?.caption || undefined;
|
|
75
|
+
const buffer = (await downloadMediaMessage({ key: msg.key, message: unwrapped }, "buffer", {}, { logger: sock.logger, reuploadRequest: sock.updateMediaMessage }));
|
|
76
|
+
return { buffer, type, caption };
|
|
77
|
+
},
|
|
78
|
+
sendButtons: async (jid, opts, quoted) => {
|
|
79
|
+
let headerMedia = { title: opts.title || "", hasMediaAttachment: false };
|
|
80
|
+
if (opts.imageUrl) {
|
|
81
|
+
const media = await prepareWAMessageMedia({ image: { url: opts.imageUrl } }, { upload: sock.waUploadToServer });
|
|
82
|
+
headerMedia = { ...media, title: opts.title || "", hasMediaAttachment: true };
|
|
83
|
+
}
|
|
84
|
+
const nativeButtons = opts.buttons.map((btn, idx) => {
|
|
85
|
+
if (btn.type === "url")
|
|
86
|
+
return { name: "cta_url", buttonParamsJson: JSON.stringify({ display_text: btn.displayText, url: btn.url, merchant_url: btn.url }) };
|
|
87
|
+
if (btn.type === "copy")
|
|
88
|
+
return { name: "cta_copy", buttonParamsJson: JSON.stringify({ display_text: btn.displayText, id: btn.id || `copy_${idx}`, copy_code: btn.copyCode }) };
|
|
89
|
+
if (btn.type === "call")
|
|
90
|
+
return { name: "cta_call", buttonParamsJson: JSON.stringify({ display_text: btn.displayText, phone_number: btn.phoneNumber }) };
|
|
91
|
+
if (btn.type === "list")
|
|
92
|
+
return { name: "single_select", buttonParamsJson: JSON.stringify({ title: btn.displayText, sections: btn.sections || [] }) };
|
|
93
|
+
return { name: "quick_reply", buttonParamsJson: JSON.stringify({ display_text: btn.displayText, id: btn.id || `btn_${idx}` }) };
|
|
94
|
+
});
|
|
95
|
+
const content = generateWAMessageFromContent(jid, {
|
|
96
|
+
viewOnceMessage: {
|
|
97
|
+
message: {
|
|
98
|
+
interactiveMessage: proto.Message.InteractiveMessage.create({
|
|
99
|
+
header: proto.Message.InteractiveMessage.Header.create(headerMedia),
|
|
100
|
+
body: proto.Message.InteractiveMessage.Body.create({ text: opts.body }),
|
|
101
|
+
footer: proto.Message.InteractiveMessage.Footer.create({ text: opts.footer || "" }),
|
|
102
|
+
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({ buttons: nativeButtons }),
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
}, { userJid: sock.user?.id || jid, quoted });
|
|
107
|
+
await sock.relayMessage(jid, content.message, {
|
|
108
|
+
messageId: content.key.id,
|
|
109
|
+
additionalNodes: [{ tag: "biz", attrs: {}, content: [{ tag: "interactive", attrs: { type: "native_flow", v: "1" }, content: [{ tag: "native_flow", attrs: { name: "quick_reply" } }] }] }],
|
|
110
|
+
});
|
|
111
|
+
return content;
|
|
112
|
+
},
|
|
113
|
+
sendAudioSticker: async (jid, stickerSource, audioSource, isAnimated = true, quoted) => {
|
|
114
|
+
const stickerMsg = await sock.sendMessage(jid, { sticker: typeof stickerSource === "string" ? { url: stickerSource } : stickerSource, isAnimated }, { quoted });
|
|
115
|
+
await sock.sendMessage(jid, { audio: typeof audioSource === "string" ? { url: audioSource } : audioSource, ptt: true, mimetype: "audio/ogg; codecs=opus" }, { quoted: stickerMsg });
|
|
116
|
+
return stickerMsg;
|
|
117
|
+
},
|
|
118
|
+
sendImage: (jid, source, caption, viewOnce = false) => sock.sendMessage(jid, { image: typeof source === "string" ? { url: source } : source, caption, viewOnce }),
|
|
119
|
+
sendVideo: (jid, source, caption, viewOnce = false, gifPlayback = false) => sock.sendMessage(jid, { video: typeof source === "string" ? { url: source } : source, caption, viewOnce, gifPlayback }),
|
|
120
|
+
sendAudio: (jid, source, ptt = false) => sock.sendMessage(jid, { audio: typeof source === "string" ? { url: source } : source, ptt, mimetype: "audio/mp4" }),
|
|
121
|
+
sendDocument: (jid, source, fileName, mimetype) => sock.sendMessage(jid, { document: typeof source === "string" ? { url: source } : source, fileName, mimetype }),
|
|
122
|
+
sendSticker: (jid, source, isAnimated = false) => sock.sendMessage(jid, { sticker: typeof source === "string" ? { url: source } : source, isAnimated }),
|
|
123
|
+
sendPoll: (jid, name, values, selectableCount = 1) => sock.sendMessage(jid, { poll: { name, values, selectableCount } }),
|
|
124
|
+
react: (jid, key, emoji) => sock.sendMessage(jid, { react: { text: emoji, key } }),
|
|
125
|
+
editMessage: (jid, key, newText) => sock.sendMessage(jid, { text: newText, edit: key }),
|
|
126
|
+
deleteMessage: (jid, key) => sock.sendMessage(jid, { delete: key }),
|
|
127
|
+
postStatus: (content, statusJidList) => sock.sendMessage("status@broadcast", content, { statusJidList }),
|
|
128
|
+
sendChannelMessage: (newsletterJid, content) => sock.sendMessage(newsletterJid, content),
|
|
129
|
+
followChannel: (newsletterJid) => sock.newsletterFollow?.(newsletterJid),
|
|
130
|
+
reactChannel: (newsletterJid, serverId, reaction) => sock.newsletterReactMessage?.(newsletterJid, serverId, reaction),
|
|
131
|
+
createGroup: (subject, participants) => sock.groupCreate(subject, participants),
|
|
132
|
+
groupAction: (groupJid, participants, action) => sock.groupParticipantsUpdate(groupJid, participants, action),
|
|
133
|
+
rejectCall: (callId, callFrom) => sock.rejectCall(callId, callFrom),
|
|
134
|
+
setTyping: (jid, isTyping = true) => sock.sendPresenceUpdate(isTyping ? "composing" : "paused", jid),
|
|
135
|
+
sendRaw: (jid, content, opts) => sock.sendMessage(jid, content, opts),
|
|
136
|
+
};
|
|
137
|
+
return { sock, ...helpers };
|
|
138
|
+
}
|
|
139
|
+
export default createVictoryBaileys;
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@victory_is_h1m/custom-baileys",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@hapi/boom": "^10.0.1",
|
|
16
|
+
"@whiskeysockets/baileys": "^7.0.0-rc14"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^26.6.10",
|
|
20
|
+
"typescript": "^5.9.3"
|
|
21
|
+
},
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
]
|
|
26
|
+
}
|