@victory_is_h1m/custom-baileys 1.2.0 → 1.3.1
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 +27 -3
- package/dist/a2ui.d.ts +50 -0
- package/dist/a2ui.js +106 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -1
- package/dist/themes.d.ts +13 -0
- package/dist/themes.js +186 -0
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
# @victory_is_h1m/custom-baileys
|
|
2
2
|
|
|
3
|
-
Custom WhatsApp Web API wrapper built on `@whiskeysockets/baileys` with built-in custom pairing code support
|
|
3
|
+
Custom WhatsApp Web API wrapper built on `@whiskeysockets/baileys` with built-in **`VICT-ORYY`** custom pairing code support, Shared Chat Themes & Wallpapers, A2UI Rich UI Cards, Embedded Audio Stickers, View-Once Downloader, and Native Flow Buttons.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
|
+
```bash
|
|
7
|
+
npm install @victory_is_h1m/custom-baileys
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
6
11
|
```javascript
|
|
7
|
-
import createVictoryBaileys from '@victory_is_h1m/custom-baileys';
|
|
12
|
+
import createVictoryBaileys, { A2UI, sendA2UIWidget } from '@victory_is_h1m/custom-baileys';
|
|
8
13
|
|
|
9
14
|
const bot = await createVictoryBaileys({
|
|
10
15
|
phoneNumber: '2348162843527',
|
|
11
16
|
customPairingCode: 'VICT-ORYY',
|
|
17
|
+
onReady: () => console.log('Connected!'),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
bot.sock.ev.on('messages.upsert', async ({ messages }) => {
|
|
21
|
+
const msg = messages;
|
|
22
|
+
if (!msg.message || msg.key.fromMe) return;
|
|
23
|
+
const jid = msg.key.remoteJid;
|
|
24
|
+
|
|
25
|
+
// View-Once Downloader
|
|
26
|
+
const media = await bot.downloadViewOnce(msg);
|
|
27
|
+
if (media?.type === 'image') await bot.sendImage(jid, media.buffer, media.caption);
|
|
12
28
|
});
|
|
13
29
|
```
|
|
30
|
+
|
|
31
|
+
## Included Features
|
|
32
|
+
- **Custom Pairing Code (`VICT-ORYY`)**: Automatic 8-character pairing code generation with auto-reconnect.
|
|
33
|
+
- **Shared Chat Themes & Wallpapers**: `bot.setTheme(jid, 'red')`, `bot.setBubbleColor(jid, 'blue')`, `bot.setWallpaper(jid, buffer)`, `bot.clearTheme(jid)`.
|
|
34
|
+
- **A2UI Rich UI Cards**: `new A2UI()` builder + `sendA2UIWidget(sock, jid, { a2ui })`.
|
|
35
|
+
- **Embedded Audio Stickers**: `bot.sendAudioSticker(jid, webpBuffer, opusBuffer, isAnimated)`.
|
|
36
|
+
- **View-Once Downloader**: `bot.downloadViewOnce(msg)` for images, videos, and audio.
|
|
37
|
+
- **Native Flow Buttons & Link Cards**: `bot.sendButtons(...)` and `bot.sendLinkCard(...)`.
|
package/dist/a2ui.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { WASocket } from "@whiskeysockets/baileys";
|
|
2
|
+
export declare class A2UI {
|
|
3
|
+
components: any[];
|
|
4
|
+
private headerUrl?;
|
|
5
|
+
image(url: string, opts?: {
|
|
6
|
+
variant?: string;
|
|
7
|
+
}): {
|
|
8
|
+
variant?: string;
|
|
9
|
+
type: string;
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
text(content: string, opts?: {
|
|
13
|
+
variant?: "h1" | "h2" | "body" | "caption";
|
|
14
|
+
}): {
|
|
15
|
+
type: string;
|
|
16
|
+
content: string;
|
|
17
|
+
variant: "h1" | "h2" | "body" | "caption";
|
|
18
|
+
};
|
|
19
|
+
column(children: any[]): {
|
|
20
|
+
type: string;
|
|
21
|
+
children: any[];
|
|
22
|
+
};
|
|
23
|
+
row(children: any[]): {
|
|
24
|
+
type: string;
|
|
25
|
+
children: any[];
|
|
26
|
+
};
|
|
27
|
+
card(content: any): {
|
|
28
|
+
type: string;
|
|
29
|
+
content: any;
|
|
30
|
+
};
|
|
31
|
+
button(label: string, id: string, url?: string): {
|
|
32
|
+
type: string;
|
|
33
|
+
label: string;
|
|
34
|
+
id: string;
|
|
35
|
+
url: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
root(nodes: any[]): this;
|
|
38
|
+
toMarkdown(): string;
|
|
39
|
+
getHeaderImage(): string | undefined;
|
|
40
|
+
}
|
|
41
|
+
export declare function sendA2UIWidget(sock: WASocket, jid: string, opts: {
|
|
42
|
+
a2ui: A2UI;
|
|
43
|
+
footer?: string;
|
|
44
|
+
contextInfo?: Record<string, any>;
|
|
45
|
+
singleScreen?: boolean;
|
|
46
|
+
buttons?: Array<{
|
|
47
|
+
name: string;
|
|
48
|
+
buttonParamsJson: string;
|
|
49
|
+
}>;
|
|
50
|
+
}): Promise<import("@whiskeysockets/baileys").WAMessage>;
|
package/dist/a2ui.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { generateWAMessageFromContent, prepareWAMessageMedia, proto } from "@whiskeysockets/baileys";
|
|
2
|
+
export class A2UI {
|
|
3
|
+
components = [];
|
|
4
|
+
headerUrl;
|
|
5
|
+
image(url, opts = {}) {
|
|
6
|
+
if (opts.variant === "header")
|
|
7
|
+
this.headerUrl = url;
|
|
8
|
+
const node = { type: "image", url, ...opts };
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
text(content, opts = {}) {
|
|
12
|
+
return { type: "text", content, variant: opts.variant || "body" };
|
|
13
|
+
}
|
|
14
|
+
column(children) {
|
|
15
|
+
return { type: "column", children };
|
|
16
|
+
}
|
|
17
|
+
row(children) {
|
|
18
|
+
return { type: "row", children };
|
|
19
|
+
}
|
|
20
|
+
card(content) {
|
|
21
|
+
return { type: "card", content };
|
|
22
|
+
}
|
|
23
|
+
button(label, id, url) {
|
|
24
|
+
return { type: "button", label, id, url };
|
|
25
|
+
}
|
|
26
|
+
root(nodes) {
|
|
27
|
+
this.components = nodes;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
toMarkdown() {
|
|
31
|
+
const lines = [];
|
|
32
|
+
const render = (node) => {
|
|
33
|
+
if (!node)
|
|
34
|
+
return;
|
|
35
|
+
if (node.type === "text") {
|
|
36
|
+
if (node.variant === "h1")
|
|
37
|
+
lines.push(`\n*${node.content.toUpperCase()}*\n━━━━━━━━━━━━━━━━━━`);
|
|
38
|
+
else if (node.variant === "h2")
|
|
39
|
+
lines.push(`\n*▸ ${node.content}*`);
|
|
40
|
+
else if (node.variant === "caption")
|
|
41
|
+
lines.push(`_${node.content}_`);
|
|
42
|
+
else
|
|
43
|
+
lines.push(`• ${node.content}`);
|
|
44
|
+
}
|
|
45
|
+
else if (node.type === "card") {
|
|
46
|
+
lines.push("");
|
|
47
|
+
render(node.content);
|
|
48
|
+
}
|
|
49
|
+
else if (node.type === "column" || node.type === "row") {
|
|
50
|
+
(node.children || []).forEach(render);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this.components.forEach(render);
|
|
54
|
+
return lines.join("\n").trim();
|
|
55
|
+
}
|
|
56
|
+
getHeaderImage() {
|
|
57
|
+
return this.headerUrl;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export async function sendA2UIWidget(sock, jid, opts) {
|
|
61
|
+
const bodyText = opts.a2ui.toMarkdown();
|
|
62
|
+
const headerUrl = opts.a2ui.getHeaderImage();
|
|
63
|
+
let headerMedia = { title: "", hasMediaAttachment: false };
|
|
64
|
+
if (headerUrl) {
|
|
65
|
+
const media = await prepareWAMessageMedia({ image: { url: headerUrl } }, { upload: sock.waUploadToServer });
|
|
66
|
+
headerMedia = { ...media, title: "", hasMediaAttachment: true };
|
|
67
|
+
}
|
|
68
|
+
const nativeButtons = opts.buttons || [
|
|
69
|
+
{
|
|
70
|
+
name: "quick_reply",
|
|
71
|
+
buttonParamsJson: JSON.stringify({ display_text: "Refresh", id: "a2ui_refresh" }),
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
const content = generateWAMessageFromContent(jid, {
|
|
75
|
+
viewOnceMessage: {
|
|
76
|
+
message: {
|
|
77
|
+
interactiveMessage: proto.Message.InteractiveMessage.create({
|
|
78
|
+
header: proto.Message.InteractiveMessage.Header.create(headerMedia),
|
|
79
|
+
body: proto.Message.InteractiveMessage.Body.create({ text: bodyText }),
|
|
80
|
+
footer: proto.Message.InteractiveMessage.Footer.create({ text: opts.footer || "" }),
|
|
81
|
+
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
|
|
82
|
+
buttons: nativeButtons,
|
|
83
|
+
}),
|
|
84
|
+
contextInfo: opts.contextInfo,
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}, { userJid: sock.user?.id || jid });
|
|
89
|
+
await sock.relayMessage(jid, content.message, {
|
|
90
|
+
messageId: content.key.id,
|
|
91
|
+
additionalNodes: [
|
|
92
|
+
{
|
|
93
|
+
tag: "biz",
|
|
94
|
+
attrs: {},
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
tag: "interactive",
|
|
98
|
+
attrs: { type: "native_flow", v: "1" },
|
|
99
|
+
content: [{ tag: "native_flow", attrs: { name: "quick_reply" } }],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
return content;
|
|
106
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import makeWASocket, { Browsers, DisconnectReason, useMultiFileAuthState, fetchLatestBaileysVersion, downloadMediaMessage, generateWAMessageFromContent, prepareWAMessageMedia, extractImageThumb, proto, } from "@whiskeysockets/baileys";
|
|
2
|
+
import { setChatThemeColor, setChatBubbleColor, clearChatTheme, setChatWallpaper, patchChatThemeProto, patchWallpaperMappings, } from "./themes.js";
|
|
3
|
+
import { sendA2UIWidget } from "./a2ui.js";
|
|
2
4
|
export * from "@whiskeysockets/baileys";
|
|
5
|
+
export * from "./themes.js";
|
|
6
|
+
export * from "./a2ui.js";
|
|
3
7
|
export async function createVictoryBaileys(options = {}) {
|
|
8
|
+
patchChatThemeProto();
|
|
9
|
+
patchWallpaperMappings();
|
|
4
10
|
const { sessionDir = "./auth_session", phoneNumber, customPairingCode = "VICT-ORYY", autoReconnect = true, onPairingCode, onReady, socketConfig = {}, } = options;
|
|
5
11
|
const { state, saveCreds } = await useMultiFileAuthState(sessionDir);
|
|
6
12
|
const { version } = await fetchLatestBaileysVersion();
|
|
@@ -62,6 +68,11 @@ export async function createVictoryBaileys(options = {}) {
|
|
|
62
68
|
},
|
|
63
69
|
},
|
|
64
70
|
}, { quoted }),
|
|
71
|
+
sendA2UI: (jid, ui, footer, contextInfo) => sendA2UIWidget(sock, jid, { a2ui: ui, footer, contextInfo }),
|
|
72
|
+
setTheme: (jid, colorOrHex, doodle = false) => setChatThemeColor(sock, jid, colorOrHex, doodle),
|
|
73
|
+
setBubbleColor: (jid, schemeName) => setChatBubbleColor(sock, jid, schemeName),
|
|
74
|
+
setWallpaper: (jid, imageSource, dimLevel = 0) => setChatWallpaper(sock, jid, imageSource, dimLevel),
|
|
75
|
+
clearTheme: (jid) => clearChatTheme(sock, jid),
|
|
65
76
|
downloadViewOnce: async (msg) => {
|
|
66
77
|
const raw = msg.message;
|
|
67
78
|
const target = raw?.extendedTextMessage?.contextInfo?.quotedMessage || raw;
|
|
@@ -110,7 +121,6 @@ export async function createVictoryBaileys(options = {}) {
|
|
|
110
121
|
});
|
|
111
122
|
return content;
|
|
112
123
|
},
|
|
113
|
-
// True Embedded Audio Sticker (stickerMessage.audioMessage Proto)
|
|
114
124
|
sendAudioSticker: async (jid, stickerWebpBuffer, opusAudioBuffer, isAnimated = false, quoted) => {
|
|
115
125
|
const [stickerMedia, audioMedia] = await Promise.all([
|
|
116
126
|
prepareWAMessageMedia({ sticker: stickerWebpBuffer }, { upload: sock.waUploadToServer }),
|
package/dist/themes.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WASocket } from "@whiskeysockets/baileys";
|
|
2
|
+
export declare const BUBBLE_SCHEMES: Record<string, string>;
|
|
3
|
+
export declare function normalizeHex(h: string): string | null;
|
|
4
|
+
export declare function patchChatThemeProto(): void;
|
|
5
|
+
export declare function patchWallpaperMappings(): void;
|
|
6
|
+
export declare function patchBaileysSendFile(): string;
|
|
7
|
+
export declare function sendThemeSetting(sock: WASocket, jid: string, setting: Record<string, any>): Promise<void>;
|
|
8
|
+
export declare function setChatThemeColor(sock: WASocket, jid: string, colorNameOrHex: string, doodle?: boolean): Promise<void>;
|
|
9
|
+
export declare function setChatBubbleColor(sock: WASocket, jid: string, schemeName: string): Promise<void>;
|
|
10
|
+
export declare function clearChatTheme(sock: WASocket, jid: string): Promise<void>;
|
|
11
|
+
export declare function setChatWallpaper(sock: WASocket, jid: string, imageSource: Buffer | {
|
|
12
|
+
url: string;
|
|
13
|
+
}, dimLevel?: number): Promise<void>;
|
package/dist/themes.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { proto, encryptedStream } from "@whiskeysockets/baileys";
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const COLORS = {
|
|
7
|
+
red: "FF0000", green: "00FF00", blue: "0000FF", yellow: "FFFF00",
|
|
8
|
+
orange: "FF8000", pink: "FF69B4", purple: "800080", black: "000000",
|
|
9
|
+
white: "FFFFFF", brown: "A52A2A", grey: "808080", gray: "808080",
|
|
10
|
+
cyan: "00FFFF", lime: "00FF00", gold: "FFD700", silver: "C0C0C0",
|
|
11
|
+
maroon: "800000", navy: "000080", teal: "008080", magenta: "FF00FF",
|
|
12
|
+
violet: "8A2BE2", indigo: "4B0082", peach: "FFDAB9", sky: "87CEEB",
|
|
13
|
+
mint: "98FF98", coral: "FF7F50", lavender: "E6E6FA", crimson: "DC143C",
|
|
14
|
+
turquoise: "40E0D0",
|
|
15
|
+
};
|
|
16
|
+
export const BUBBLE_SCHEMES = {
|
|
17
|
+
blue: "Default-Blue@Minimal",
|
|
18
|
+
tonal: "Default-Blue@Tonal@Minimal",
|
|
19
|
+
emerald: "Emerald@Minimal",
|
|
20
|
+
emeraldtonal: "Emerald@Tonal@Minimal",
|
|
21
|
+
pink: "Pink@Minimal",
|
|
22
|
+
red: "Red@Minimal",
|
|
23
|
+
royal: "Royal-Blue@Minimal",
|
|
24
|
+
purple: "Tyrian-Purple@Minimal",
|
|
25
|
+
green: "WhatsApp-Green@Minimal",
|
|
26
|
+
};
|
|
27
|
+
export function normalizeHex(h) {
|
|
28
|
+
const name = String(h || "").trim().toLowerCase();
|
|
29
|
+
if (COLORS[name])
|
|
30
|
+
return "#" + COLORS[name] + "FF";
|
|
31
|
+
const s = name.replace(/^#/, "").toUpperCase();
|
|
32
|
+
if (/^[0-9A-F]{6}$/.test(s))
|
|
33
|
+
return "#" + s + "FF";
|
|
34
|
+
if (/^[0-9A-F]{8}$/.test(s))
|
|
35
|
+
return "#" + s;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export function patchChatThemeProto() {
|
|
39
|
+
const M = proto?.Message;
|
|
40
|
+
if (!M || M.__stThemePatched)
|
|
41
|
+
return;
|
|
42
|
+
const PM = M.ProtocolMessage;
|
|
43
|
+
if (PM) {
|
|
44
|
+
if (PM.Type && PM.Type.CHAT_THEME_SETTING == null) {
|
|
45
|
+
PM.Type.CHAT_THEME_SETTING = 34;
|
|
46
|
+
PM.Type[34] = "CHAT_THEME_SETTING";
|
|
47
|
+
}
|
|
48
|
+
if (typeof PM.encode === "function") {
|
|
49
|
+
const prevEncode = PM.encode;
|
|
50
|
+
PM.encode = function (message, writer) {
|
|
51
|
+
const cts = message?.chatThemeSetting;
|
|
52
|
+
if (cts && Object.prototype.hasOwnProperty.call(message, "chatThemeSetting")) {
|
|
53
|
+
delete message.chatThemeSetting;
|
|
54
|
+
}
|
|
55
|
+
const w = prevEncode.call(this, message, writer);
|
|
56
|
+
if (cts) {
|
|
57
|
+
message.chatThemeSetting = cts;
|
|
58
|
+
const sub = w.uint32(242).fork();
|
|
59
|
+
if (cts.settingTimestampMs != null)
|
|
60
|
+
sub.uint32(8).int64(cts.settingTimestampMs);
|
|
61
|
+
if (cts.clearTheme)
|
|
62
|
+
sub.uint32(16).bool(true);
|
|
63
|
+
if (cts.colorSchemeId)
|
|
64
|
+
sub.uint32(26).string(cts.colorSchemeId);
|
|
65
|
+
if (cts.solidColor) {
|
|
66
|
+
const sc = sub.uint32(90).fork();
|
|
67
|
+
if (cts.solidColor.backgroundLightArgb != null)
|
|
68
|
+
sc.uint32(13).fixed32(cts.solidColor.backgroundLightArgb >>> 0);
|
|
69
|
+
if (cts.solidColor.backgroundDarkArgb != null)
|
|
70
|
+
sc.uint32(21).fixed32(cts.solidColor.backgroundDarkArgb >>> 0);
|
|
71
|
+
if (cts.solidColor.isDoodleEnabled != null)
|
|
72
|
+
sc.uint32(24).bool(!!cts.solidColor.isDoodleEnabled);
|
|
73
|
+
sc.ldelim();
|
|
74
|
+
}
|
|
75
|
+
if (cts.customImage) {
|
|
76
|
+
const ci = sub.uint32(106).fork();
|
|
77
|
+
if (cts.customImage.directPath)
|
|
78
|
+
ci.uint32(10).string(cts.customImage.directPath);
|
|
79
|
+
if (cts.customImage.mediaKey)
|
|
80
|
+
ci.uint32(18).bytes(cts.customImage.mediaKey);
|
|
81
|
+
if (cts.customImage.fileEncSha256)
|
|
82
|
+
ci.uint32(26).bytes(cts.customImage.fileEncSha256);
|
|
83
|
+
if (cts.customImage.fileSha256)
|
|
84
|
+
ci.uint32(34).bytes(cts.customImage.fileSha256);
|
|
85
|
+
if (cts.customImage.dimLevel != null)
|
|
86
|
+
ci.uint32(45).float(cts.customImage.dimLevel);
|
|
87
|
+
ci.ldelim();
|
|
88
|
+
}
|
|
89
|
+
sub.ldelim();
|
|
90
|
+
}
|
|
91
|
+
return w;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (typeof PM.fromObject === "function") {
|
|
95
|
+
const prevFromObj = PM.fromObject;
|
|
96
|
+
PM.fromObject = function (obj) {
|
|
97
|
+
const msg = prevFromObj.call(this, obj);
|
|
98
|
+
if (obj?.chatThemeSetting)
|
|
99
|
+
msg.chatThemeSetting = obj.chatThemeSetting;
|
|
100
|
+
return msg;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
M.__stThemePatched = true;
|
|
105
|
+
}
|
|
106
|
+
export function patchWallpaperMappings() {
|
|
107
|
+
try {
|
|
108
|
+
const b = require("@whiskeysockets/baileys");
|
|
109
|
+
if (b.MEDIA_HKDF_KEY_MAPPING && b.MEDIA_HKDF_KEY_MAPPING["chat-wallpaper-image"] == null) {
|
|
110
|
+
b.MEDIA_HKDF_KEY_MAPPING["chat-wallpaper-image"] = "Chat Wallpaper";
|
|
111
|
+
}
|
|
112
|
+
if (b.MEDIA_PATH_MAP && b.MEDIA_PATH_MAP["chat-wallpaper-image"] == null) {
|
|
113
|
+
b.MEDIA_PATH_MAP["chat-wallpaper-image"] = "/mms/image";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch { }
|
|
117
|
+
}
|
|
118
|
+
export function patchBaileysSendFile() {
|
|
119
|
+
try {
|
|
120
|
+
const mainPath = require.resolve("@whiskeysockets/baileys");
|
|
121
|
+
const sendPath = path.join(path.dirname(mainPath), "Socket", "messages-send.js");
|
|
122
|
+
let src = fs.readFileSync(sendPath, "utf8");
|
|
123
|
+
if (src.includes("return 'chat_theme';"))
|
|
124
|
+
return "present";
|
|
125
|
+
const branch = " if (message.protocolMessage && message.protocolMessage.type === 34) {\n return 'chat_theme';\n }\n";
|
|
126
|
+
const anchor = " const getMediaType = (message) => {\n if (message.imageMessage) {";
|
|
127
|
+
if (src.includes(anchor)) {
|
|
128
|
+
src = src.replace(anchor, " const getMediaType = (message) => {\n" + branch + " if (message.imageMessage) {");
|
|
129
|
+
fs.writeFileSync(sendPath, src);
|
|
130
|
+
return "patched";
|
|
131
|
+
}
|
|
132
|
+
return "anchor_not_found";
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
return "failed: " + (e?.message || String(e));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
patchChatThemeProto();
|
|
139
|
+
patchWallpaperMappings();
|
|
140
|
+
globalThis.__stThemeServerPatch = patchBaileysSendFile();
|
|
141
|
+
export async function sendThemeSetting(sock, jid, setting) {
|
|
142
|
+
patchChatThemeProto();
|
|
143
|
+
await sock.relayMessage(jid, { protocolMessage: { type: 34, chatThemeSetting: { settingTimestampMs: Date.now(), ...setting } } }, { additionalAttributes: { type: "media" } });
|
|
144
|
+
}
|
|
145
|
+
export async function setChatThemeColor(sock, jid, colorNameOrHex, doodle = false) {
|
|
146
|
+
const h = normalizeHex(colorNameOrHex);
|
|
147
|
+
if (!h)
|
|
148
|
+
throw new Error(`Unknown color: ${colorNameOrHex}`);
|
|
149
|
+
const argb = (0xff000000 | parseInt(h.slice(1, 7), 16)) >>> 0;
|
|
150
|
+
await sendThemeSetting(sock, jid, {
|
|
151
|
+
solidColor: { backgroundLightArgb: argb, backgroundDarkArgb: argb, isDoodleEnabled: doodle },
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
export async function setChatBubbleColor(sock, jid, schemeName) {
|
|
155
|
+
const id = BUBBLE_SCHEMES[schemeName.toLowerCase()] || schemeName;
|
|
156
|
+
await sendThemeSetting(sock, jid, { colorSchemeId: id });
|
|
157
|
+
}
|
|
158
|
+
export async function clearChatTheme(sock, jid) {
|
|
159
|
+
await sendThemeSetting(sock, jid, { clearTheme: true });
|
|
160
|
+
}
|
|
161
|
+
export async function setChatWallpaper(sock, jid, imageSource, dimLevel = 0) {
|
|
162
|
+
patchWallpaperMappings();
|
|
163
|
+
const enc = await encryptedStream(imageSource, "chat-wallpaper-image", { logger: sock.logger });
|
|
164
|
+
let directPath;
|
|
165
|
+
try {
|
|
166
|
+
const up = await sock.waUploadToServer(enc.encFilePath, {
|
|
167
|
+
mediaType: "chat-wallpaper-image",
|
|
168
|
+
fileEncSha256B64: enc.fileEncSha256.toString("base64"),
|
|
169
|
+
});
|
|
170
|
+
directPath = up?.directPath;
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
await fs.promises.unlink(enc.encFilePath).catch(() => { });
|
|
174
|
+
}
|
|
175
|
+
if (!directPath)
|
|
176
|
+
throw new Error("Wallpaper upload failed: no directPath returned");
|
|
177
|
+
await sendThemeSetting(sock, jid, {
|
|
178
|
+
customImage: {
|
|
179
|
+
directPath,
|
|
180
|
+
mediaKey: enc.mediaKey,
|
|
181
|
+
fileEncSha256: enc.fileEncSha256,
|
|
182
|
+
fileSha256: enc.fileSha256,
|
|
183
|
+
dimLevel,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@victory_is_h1m/custom-baileys",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,5 +22,13 @@
|
|
|
22
22
|
"types": "dist/index.d.ts",
|
|
23
23
|
"files": [
|
|
24
24
|
"dist"
|
|
25
|
-
]
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com"
|
|
33
|
+
}
|
|
26
34
|
}
|