@victory_is_h1m/custom-baileys 1.0.0 → 1.2.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { UserFacingSocketConfig, WASocket } from '@whiskeysockets/baileys';
2
- export * from '@whiskeysockets/baileys';
1
+ import { UserFacingSocketConfig, WASocket } from "@whiskeysockets/baileys";
2
+ export * from "@whiskeysockets/baileys";
3
3
  export interface CustomBotOptions {
4
4
  sessionDir?: string;
5
5
  phoneNumber?: string;
@@ -9,5 +9,23 @@ export interface CustomBotOptions {
9
9
  onReady?: (sock: WASocket) => void;
10
10
  socketConfig?: Partial<UserFacingSocketConfig>;
11
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
+ }
12
30
  export declare function createVictoryBaileys(options?: CustomBotOptions): Promise<any>;
13
31
  export default createVictoryBaileys;
package/dist/index.js CHANGED
@@ -1,26 +1,26 @@
1
- import makeWASocket, { Browsers, DisconnectReason, useMultiFileAuthState, fetchLatestBaileysVersion, } from '@whiskeysockets/baileys';
2
- export * from '@whiskeysockets/baileys';
1
+ import makeWASocket, { Browsers, DisconnectReason, useMultiFileAuthState, fetchLatestBaileysVersion, downloadMediaMessage, generateWAMessageFromContent, prepareWAMessageMedia, extractImageThumb, proto, } from "@whiskeysockets/baileys";
2
+ export * from "@whiskeysockets/baileys";
3
3
  export async function createVictoryBaileys(options = {}) {
4
- const { sessionDir = './auth_session', phoneNumber, customPairingCode = 'VICT-ORYY', autoReconnect = true, onPairingCode, onReady, socketConfig = {}, } = options;
4
+ const { sessionDir = "./auth_session", phoneNumber, customPairingCode = "VICT-ORYY", autoReconnect = true, onPairingCode, onReady, socketConfig = {}, } = options;
5
5
  const { state, saveCreds } = await useMultiFileAuthState(sessionDir);
6
6
  const { version } = await fetchLatestBaileysVersion();
7
7
  let pairingRequested = false;
8
8
  const sock = makeWASocket({
9
9
  version,
10
10
  auth: state,
11
- browser: Browsers.ubuntu('Chrome'),
11
+ browser: Browsers.ubuntu("Chrome"),
12
12
  syncFullHistory: true,
13
13
  markOnlineOnConnect: true,
14
14
  ...socketConfig,
15
15
  });
16
- sock.ev.on('creds.update', saveCreds);
17
- sock.ev.on('connection.update', async (update) => {
16
+ sock.ev.on("creds.update", saveCreds);
17
+ sock.ev.on("connection.update", async (update) => {
18
18
  const { connection, lastDisconnect, qr } = update;
19
- if ((qr || connection === 'connecting') && !state.creds.registered && phoneNumber && !pairingRequested) {
19
+ if ((qr || connection === "connecting") && !state.creds.registered && phoneNumber && !pairingRequested) {
20
20
  pairingRequested = true;
21
21
  try {
22
- const cleanNumber = phoneNumber.replace(/\D/g, '');
23
- const cleanCode = customPairingCode.replace(/[^A-Za-z0-9]/g, '').toUpperCase();
22
+ const cleanNumber = phoneNumber.replace(/\D/g, "");
23
+ const cleanCode = customPairingCode.replace(/[^A-Za-z0-9]/g, "").toUpperCase();
24
24
  await new Promise((res) => setTimeout(res, 1500));
25
25
  const code = await sock.requestPairingCode(cleanNumber, cleanCode);
26
26
  const formatted = `${code.slice(0, 4)}-${code.slice(4)}`;
@@ -31,17 +31,15 @@ export async function createVictoryBaileys(options = {}) {
31
31
  }
32
32
  catch (err) {
33
33
  pairingRequested = false;
34
- console.error('[VICTORY-BAILEYS] Pairing code error:', err);
34
+ console.error("[VICTORY-BAILEYS] Pairing code error:", err);
35
35
  }
36
36
  }
37
- if (connection === 'open') {
38
- console.log('[VICTORY-BAILEYS] Connected to WhatsApp!');
39
- if (onReady)
40
- onReady(sock);
37
+ if (connection === "open") {
38
+ console.log("[VICTORY-BAILEYS] Connected to WhatsApp!");
41
39
  if (onReady)
42
40
  onReady(sock);
43
41
  }
44
- if (connection === 'close') {
42
+ if (connection === "close") {
45
43
  const statusCode = lastDisconnect?.error?.output?.statusCode;
46
44
  if (autoReconnect && statusCode !== DisconnectReason.loggedOut) {
47
45
  createVictoryBaileys(options);
@@ -50,22 +48,114 @@ export async function createVictoryBaileys(options = {}) {
50
48
  });
51
49
  const helpers = {
52
50
  sendText: (jid, text, mentions, quoted) => sock.sendMessage(jid, { text, mentions }, { quoted }),
53
- sendImage: (jid, source, caption) => sock.sendMessage(jid, { image: typeof source === 'string' ? { url: source } : source, caption }),
54
- sendVideo: (jid, source, caption, gifPlayback = false) => sock.sendMessage(jid, { video: typeof source === 'string' ? { url: source } : source, caption, gifPlayback }),
55
- sendAudio: (jid, source, ptt = false) => sock.sendMessage(jid, { audio: typeof source === 'string' ? { url: source } : source, ptt, mimetype: 'audio/mp4' }),
56
- sendDocument: (jid, source, fileName, mimetype) => sock.sendMessage(jid, { document: typeof source === 'string' ? { url: source } : source, fileName, mimetype }),
57
- sendSticker: (jid, source) => sock.sendMessage(jid, { sticker: typeof source === 'string' ? { url: source } : source }),
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
+ // True Embedded Audio Sticker (stickerMessage.audioMessage Proto)
114
+ sendAudioSticker: async (jid, stickerWebpBuffer, opusAudioBuffer, isAnimated = false, quoted) => {
115
+ const [stickerMedia, audioMedia] = await Promise.all([
116
+ prepareWAMessageMedia({ sticker: stickerWebpBuffer }, { upload: sock.waUploadToServer }),
117
+ prepareWAMessageMedia({ audio: opusAudioBuffer, mimetype: "audio/ogg; codecs=opus", ptt: true }, { upload: sock.waUploadToServer }),
118
+ ]);
119
+ const stickerMsg = stickerMedia.stickerMessage;
120
+ const audioMsg = audioMedia.audioMessage;
121
+ if (!stickerMsg)
122
+ throw new Error("Failed to upload sticker media");
123
+ if (isAnimated) {
124
+ stickerMsg.isAnimated = true;
125
+ try {
126
+ const thumb = await extractImageThumb(stickerWebpBuffer, 64);
127
+ if (thumb?.buffer)
128
+ stickerMsg.pngThumbnail = thumb.buffer;
129
+ }
130
+ catch { }
131
+ }
132
+ stickerMsg.stickerSentTs = Date.now();
133
+ if (audioMsg) {
134
+ audioMsg.mimetype = "audio/ogg; codecs=opus";
135
+ audioMsg.ptt = true;
136
+ stickerMsg.audioMessage = audioMsg;
137
+ }
138
+ const msg = generateWAMessageFromContent(jid, { stickerMessage: stickerMsg }, { quoted, userJid: sock.user?.id || jid });
139
+ await sock.relayMessage(jid, msg.message, { messageId: msg.key.id });
140
+ return msg;
141
+ },
142
+ sendImage: (jid, source, caption, viewOnce = false) => sock.sendMessage(jid, { image: typeof source === "string" ? { url: source } : source, caption, viewOnce }),
143
+ sendVideo: (jid, source, caption, viewOnce = false, gifPlayback = false) => sock.sendMessage(jid, { video: typeof source === "string" ? { url: source } : source, caption, viewOnce, gifPlayback }),
144
+ sendAudio: (jid, source, ptt = false) => sock.sendMessage(jid, { audio: typeof source === "string" ? { url: source } : source, ptt, mimetype: "audio/mp4" }),
145
+ sendDocument: (jid, source, fileName, mimetype) => sock.sendMessage(jid, { document: typeof source === "string" ? { url: source } : source, fileName, mimetype }),
146
+ sendSticker: (jid, source, isAnimated = false) => sock.sendMessage(jid, { sticker: typeof source === "string" ? { url: source } : source, isAnimated }),
58
147
  sendPoll: (jid, name, values, selectableCount = 1) => sock.sendMessage(jid, { poll: { name, values, selectableCount } }),
59
148
  react: (jid, key, emoji) => sock.sendMessage(jid, { react: { text: emoji, key } }),
60
- sendLocation: (jid, degreesLatitude, degreesLongitude) => sock.sendMessage(jid, { location: { degreesLatitude, degreesLongitude } }),
61
149
  editMessage: (jid, key, newText) => sock.sendMessage(jid, { text: newText, edit: key }),
62
150
  deleteMessage: (jid, key) => sock.sendMessage(jid, { delete: key }),
63
- postStatus: (content, statusJidList) => sock.sendMessage('status@broadcast', content, { statusJidList }),
151
+ postStatus: (content, statusJidList) => sock.sendMessage("status@broadcast", content, { statusJidList }),
152
+ sendChannelMessage: (newsletterJid, content) => sock.sendMessage(newsletterJid, content),
153
+ followChannel: (newsletterJid) => sock.newsletterFollow?.(newsletterJid),
154
+ reactChannel: (newsletterJid, serverId, reaction) => sock.newsletterReactMessage?.(newsletterJid, serverId, reaction),
64
155
  createGroup: (subject, participants) => sock.groupCreate(subject, participants),
65
156
  groupAction: (groupJid, participants, action) => sock.groupParticipantsUpdate(groupJid, participants, action),
66
- setGroupSettings: (groupJid, setting) => sock.groupSettingUpdate(groupJid, setting),
67
- setTyping: (jid, isTyping = true) => sock.sendPresenceUpdate(isTyping ? 'composing' : 'paused', jid),
68
- updateBio: (status) => sock.updateProfileStatus(status),
157
+ rejectCall: (callId, callFrom) => sock.rejectCall(callId, callFrom),
158
+ setTyping: (jid, isTyping = true) => sock.sendPresenceUpdate(isTyping ? "composing" : "paused", jid),
69
159
  sendRaw: (jid, content, opts) => sock.sendMessage(jid, content, opts),
70
160
  };
71
161
  return { sock, ...helpers };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@victory_is_h1m/custom-baileys",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {