savage-buttons 0.0.0-stage → 2.0.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Spencer Beck (Savage Tech)
4
+ Original work Copyright (c) 2026 Briton Kiplangat (Silent Wolf) / WOLF TECH
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+ <img src="https://files.catbox.moe/si5ztc.jpg" alt="Savage Buttons Logo" width="250" />
3
+ <h1>Savage Buttons</h1>
4
+ <p>A pure, transparent interactive-buttons helper for <strong>Savage Baileys</strong>.</p>
5
+ <p>Created and maintained by <strong>Spencer (Savage Tech)</strong></p>
6
+
7
+ [![npm version](https://img.shields.io/npm/v/savage-buttons.svg)](https://www.npmjs.com/package/savage-buttons)
8
+ [![License](https://img.shields.io/npm/l/savage-buttons.svg)](https://github.com/tysavage163/Spencer-Btns/blob/main/LICENSE)
9
+ </div>
2
10
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
11
+ ---
12
+
13
+ ## What this package does — and does not do
14
+
15
+ **Does:**
16
+
17
+ - Provides a tiny helper (`sendButtons`, `btn.*`) that builds WhatsApp native-flow interactive button messages specifically for `savage-baileys`.
18
+ - Supports URL, reply, copy, call, and list buttons out of the box.
19
+ - Uses only the public `sendMessage` API from `savage-baileys` under the hood.
20
+
21
+ **Does NOT:**
22
+
23
+ - ❌ No `eval`, no `Function()` constructor, no dynamic code loading
24
+ - ❌ No string-table obfuscation — the entire `index.js` is plain readable JavaScript
25
+ - ❌ No tamper-checks, no environment sniffing
26
+ - ❌ No calls to any vendor backend or third-party API
27
+ - ❌ No telemetry, no analytics, no usage reporting
28
+ - ❌ No hidden `setTimeout` / `setInterval`
29
+ - ❌ No foreign dependencies (nothing except `savage-baileys`)
30
+
31
+ Every line is auditable in under five minutes. If you ever find a line that contradicts this README, open an issue at [https://github.com/tysavage163/Spencer-Btns/issues](https://github.com/tysavage163/Spencer-Btns/issues) — it will be treated as urgent.
32
+
33
+ ---
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ npm install savage-buttons savage-baileys
package/index.cjs ADDED
@@ -0,0 +1,114 @@
1
+ const { generateWAMessageFromContent, prepareWAMessageMedia } = require('savage-baileys');
2
+
3
+ const btn = {
4
+ url(display_text, url, merchant_url) {
5
+ return {
6
+ name: 'cta_url',
7
+ buttonParamsJson: JSON.stringify({ display_text, url, merchant_url: merchant_url || url })
8
+ };
9
+ },
10
+ copy(display_text, copy_code) {
11
+ return {
12
+ name: 'cta_copy',
13
+ buttonParamsJson: JSON.stringify({ display_text, copy_code })
14
+ };
15
+ },
16
+ call(display_text, phone_number) {
17
+ return {
18
+ name: 'cta_call',
19
+ buttonParamsJson: JSON.stringify({ display_text, phone_number })
20
+ };
21
+ },
22
+ reply(display_text, id) {
23
+ return {
24
+ name: 'quick_reply',
25
+ buttonParamsJson: JSON.stringify({ display_text, id })
26
+ };
27
+ },
28
+ list(list_button_text, sections) {
29
+ return {
30
+ name: 'single_select',
31
+ buttonParamsJson: JSON.stringify({ title: list_button_text, sections })
32
+ };
33
+ }
34
+ };
35
+
36
+ async function sendButtons(sock, jid, options = {}) {
37
+ const { text = '', footer = '', title, subtitle, buttons, interactiveButtons, contextInfo, quoted, image } = options;
38
+ const resolvedButtons = buttons || interactiveButtons || [];
39
+
40
+ if (!Array.isArray(resolvedButtons) || resolvedButtons.length === 0) {
41
+ throw new Error('savage-buttons: sendButtons requires at least one button');
42
+ }
43
+
44
+ for (const b of resolvedButtons) {
45
+ if (!b || typeof b.name !== 'string' || typeof b.buttonParamsJson !== 'string') {
46
+ throw new Error('savage-buttons: each button needs { name, buttonParamsJson }');
47
+ }
48
+ }
49
+
50
+ let header = { title: title || '', subtitle: subtitle || '', hasMediaAttachment: false };
51
+
52
+ if (image) {
53
+ const media = await prepareWAMessageMedia(
54
+ { image: typeof image === 'string' ? { url: image } : image },
55
+ { upload: sock.waUploadToServer }
56
+ );
57
+ header = {
58
+ title: title || '',
59
+ subtitle: subtitle || '',
60
+ hasMediaAttachment: true,
61
+ imageMessage: media.imageMessage
62
+ };
63
+ }
64
+
65
+ const bodyAndHeader = {
66
+ header,
67
+ ...(text ? { body: { text } } : {}),
68
+ ...(footer ? { footer: { text: footer } } : {})
69
+ };
70
+
71
+ if (contextInfo && typeof contextInfo === 'object') {
72
+ bodyAndHeader.contextInfo = contextInfo;
73
+ }
74
+
75
+ const interactiveMessage = {
76
+ ...bodyAndHeader,
77
+ nativeFlowMessage: {
78
+ buttons: resolvedButtons,
79
+ messageParamsJson: ''
80
+ }
81
+ };
82
+
83
+ const messageContent = { interactiveMessage };
84
+
85
+ const interactiveStanzaNodes = [
86
+ {
87
+ tag: 'biz',
88
+ attrs: {},
89
+ content: [
90
+ {
91
+ tag: 'interactive',
92
+ attrs: { type: 'native_flow', v: '1' },
93
+ content: [
94
+ { tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }
95
+ ]
96
+ }
97
+ ]
98
+ }
99
+ ];
100
+
101
+ const fullMessage = generateWAMessageFromContent(jid, messageContent, {
102
+ quoted,
103
+ userJid: sock.user?.id
104
+ });
105
+
106
+ await sock.relayMessage(jid, fullMessage.message, {
107
+ messageId: fullMessage.key.id,
108
+ additionalNodes: interactiveStanzaNodes
109
+ });
110
+
111
+ return fullMessage;
112
+ }
113
+
114
+ module.exports = { sendButtons, sendInteractiveMessage: sendButtons, btn };
package/index.js ADDED
@@ -0,0 +1,104 @@
1
+ import { generateWAMessageFromContent, proto } from 'savage-baileys';
2
+
3
+ /**
4
+ * Button Builder Helpers
5
+ * Creates the correct protobuf structures for different button types.
6
+ */
7
+ export const btn = {
8
+ // Quick Reply Button
9
+ reply: (text, id = `reply_${Date.now()}`) => ({
10
+ name: "quick_reply",
11
+ buttonParamsJson: JSON.stringify({
12
+ display_text: text,
13
+ id: id
14
+ })
15
+ }),
16
+
17
+ // URL Button
18
+ url: (text, url, useWebview = false) => ({
19
+ name: "cta_url",
20
+ buttonParamsJson: JSON.stringify({
21
+ display_text: text,
22
+ url: url,
23
+ merchant_url: url,
24
+ use_webview: useWebview
25
+ })
26
+ }),
27
+
28
+ // Call Button
29
+ call: (text, phoneNumber) => ({
30
+ name: "cta_call",
31
+ buttonParamsJson: JSON.stringify({
32
+ display_text: text,
33
+ phone_number: phoneNumber
34
+ })
35
+ }),
36
+
37
+ // Copy to Clipboard Button
38
+ copy: (text, copyCode) => ({
39
+ name: "cta_copy",
40
+ buttonParamsJson: JSON.stringify({
41
+ display_text: text,
42
+ id: `copy_${Date.now()}`,
43
+ copy_code: copyCode
44
+ })
45
+ }),
46
+
47
+ // Single Select List
48
+ list: (text, sections) => ({
49
+ name: "single_select",
50
+ buttonParamsJson: JSON.stringify({
51
+ title: text,
52
+ sections: sections
53
+ })
54
+ })
55
+ };
56
+
57
+ /**
58
+ * Send Interactive Buttons
59
+ *
60
+ * @param {Object} sock - The savage-baileys socket connection
61
+ * @param {String} jid - The WhatsApp JID to send the message to
62
+ * @param {String} text - The main body text of the message
63
+ * @param {String} footer - The footer text
64
+ * @param {Array} buttons - Array of button objects created using the `btn` helper
65
+ * @param {Object} quoted - Optional quoted message to reply to
66
+ */
67
+ export async function sendButtons(sock, jid, text, footer, buttons, quoted = null) {
68
+ if (!sock || !jid) throw new Error("Socket and JID are required.");
69
+ if (!buttons || !Array.isArray(buttons)) throw new Error("Buttons must be an array.");
70
+
71
+ // Construct the native flow message content
72
+ const interactiveMessage = {
73
+ body: { text: text },
74
+ footer: { text: footer },
75
+ nativeFlowMessage: {
76
+ buttons: buttons,
77
+ messageParamsJson: JSON.stringify({
78
+ from: "api",
79
+ templateId: "savage-tech-buttons"
80
+ })
81
+ }
82
+ };
83
+
84
+ // Generate the full WhatsApp message structure
85
+ const msg = generateWAMessageFromContent(jid, {
86
+ viewOnceMessage: {
87
+ message: {
88
+ interactiveMessage: interactiveMessage
89
+ }
90
+ }
91
+ }, { userJid: sock.user.id, quoted: quoted });
92
+
93
+ // Send the message using savage-baileys
94
+ await sock.relayMessage(jid, msg.message, {
95
+ messageId: msg.key.id
96
+ });
97
+
98
+ return msg;
99
+ }
100
+
101
+ export default {
102
+ btn,
103
+ sendButtons
104
+ };
package/index.mjs ADDED
@@ -0,0 +1,116 @@
1
+ import baileys from 'savage-baileys';
2
+ const { generateWAMessageFromContent, prepareWAMessageMedia } = baileys;
3
+
4
+ export const btn = {
5
+ url(display_text, url, merchant_url) {
6
+ return {
7
+ name: 'cta_url',
8
+ buttonParamsJson: JSON.stringify({ display_text, url, merchant_url: merchant_url || url })
9
+ };
10
+ },
11
+ copy(display_text, copy_code) {
12
+ return {
13
+ name: 'cta_copy',
14
+ buttonParamsJson: JSON.stringify({ display_text, copy_code })
15
+ };
16
+ },
17
+ call(display_text, phone_number) {
18
+ return {
19
+ name: 'cta_call',
20
+ buttonParamsJson: JSON.stringify({ display_text, phone_number })
21
+ };
22
+ },
23
+ reply(display_text, id) {
24
+ return {
25
+ name: 'quick_reply',
26
+ buttonParamsJson: JSON.stringify({ display_text, id })
27
+ };
28
+ },
29
+ list(list_button_text, sections) {
30
+ return {
31
+ name: 'single_select',
32
+ buttonParamsJson: JSON.stringify({ title: list_button_text, sections })
33
+ };
34
+ }
35
+ };
36
+
37
+ export async function sendButtons(sock, jid, options = {}) {
38
+ const { text = '', footer = '', title, subtitle, buttons, interactiveButtons, contextInfo, quoted, image } = options;
39
+ const resolvedButtons = buttons || interactiveButtons || [];
40
+
41
+ if (!Array.isArray(resolvedButtons) || resolvedButtons.length === 0) {
42
+ throw new Error('savage-buttons: sendButtons requires at least one button');
43
+ }
44
+
45
+ for (const b of resolvedButtons) {
46
+ if (!b || typeof b.name !== 'string' || typeof b.buttonParamsJson !== 'string') {
47
+ throw new Error('savage-buttons: each button needs { name, buttonParamsJson }');
48
+ }
49
+ }
50
+
51
+ let header = { title: title || '', subtitle: subtitle || '', hasMediaAttachment: false };
52
+
53
+ if (image) {
54
+ const media = await prepareWAMessageMedia(
55
+ { image: typeof image === 'string' ? { url: image } : image },
56
+ { upload: sock.waUploadToServer }
57
+ );
58
+ header = {
59
+ title: title || '',
60
+ subtitle: subtitle || '',
61
+ hasMediaAttachment: true,
62
+ imageMessage: media.imageMessage
63
+ };
64
+ }
65
+
66
+ const bodyAndHeader = {
67
+ header,
68
+ ...(text ? { body: { text } } : {}),
69
+ ...(footer ? { footer: { text: footer } } : {})
70
+ };
71
+
72
+ if (contextInfo && typeof contextInfo === 'object') {
73
+ bodyAndHeader.contextInfo = contextInfo;
74
+ }
75
+
76
+ const interactiveMessage = {
77
+ ...bodyAndHeader,
78
+ nativeFlowMessage: {
79
+ buttons: resolvedButtons,
80
+ messageParamsJson: ''
81
+ }
82
+ };
83
+
84
+ const messageContent = { interactiveMessage };
85
+
86
+ const interactiveStanzaNodes = [
87
+ {
88
+ tag: 'biz',
89
+ attrs: {},
90
+ content: [
91
+ {
92
+ tag: 'interactive',
93
+ attrs: { type: 'native_flow', v: '1' },
94
+ content: [
95
+ { tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }
96
+ ]
97
+ }
98
+ ]
99
+ }
100
+ ];
101
+
102
+ const fullMessage = generateWAMessageFromContent(jid, messageContent, {
103
+ quoted,
104
+ userJid: sock.user?.id
105
+ });
106
+
107
+ await sock.relayMessage(jid, fullMessage.message, {
108
+ messageId: fullMessage.key.id,
109
+ additionalNodes: interactiveStanzaNodes
110
+ });
111
+
112
+ return fullMessage;
113
+ }
114
+
115
+ export const sendInteractiveMessage = sendButtons;
116
+ export default { sendButtons, sendInteractiveMessage, btn };
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "savage-buttons",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.1",
4
+ "description": "Pure, transparent interactive-buttons helper for Savage Baileys",
5
+ "icon": "https://files.catbox.moe/si5ztc.jpg",
6
+ "type": "commonjs",
7
+ "main": "./index.cjs",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./index.mjs",
11
+ "require": "./index.cjs"
12
+ }
13
+ },
14
+ "keywords": [
15
+ "whatsapp",
16
+ "baileys",
17
+ "savage-baileys",
18
+ "savage-buttons",
19
+ "buttons",
20
+ "interactive-message",
21
+ "savage-tech"
22
+ ],
23
+ "author": "Spencer <Savage Tech>",
24
+ "license": "MIT",
25
+ "homepage": "https://github.com/tysavage163/Spencer-Btns",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/tysavage163/Spencer-Btns.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/tysavage163/Spencer-Btns/issues"
32
+ },
33
+ "engines": {
34
+ "node": ">=20"
35
+ },
36
+ "dependencies": {
37
+ "savage-baileys": "^2.0.0"
38
+ },
39
+ "peerDependencies": {
40
+ "savage-baileys": "^2.0.0"
41
+ }
42
+ }