whatsapp-pi 1.0.10 → 1.0.12
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 +20 -2
- package/package.json +1 -1
- package/whatsapp-pi.ts +35 -37
package/README.md
CHANGED
|
@@ -62,8 +62,26 @@ pi -e whatsapp-pi.ts --verbose
|
|
|
62
62
|
## Commands
|
|
63
63
|
|
|
64
64
|
- `/whatsapp` - Open the WhatsApp management menu
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
|
|
66
|
+
### Main Menu Options
|
|
67
|
+
- **Connect WhatsApp** - Start WhatsApp connection (shows QR code for first-time setup)
|
|
68
|
+
- **Disconnect WhatsApp** - Stop WhatsApp connection
|
|
69
|
+
- **Logoff (Delete Session)** - Remove all credentials and session data
|
|
70
|
+
- **Reset Conversation** - Clear all conversation history
|
|
71
|
+
- **Allowed Numbers** - Manage contacts that can interact with Pi
|
|
72
|
+
- **Blocked Numbers** - View ignored numbers and manage them
|
|
73
|
+
|
|
74
|
+
### Allowed Numbers Management
|
|
75
|
+
- **Add Number** - Add a new contact to the allow list (format: +5511999999999)
|
|
76
|
+
- **Remove [Number]** - Remove a specific contact from the allow list
|
|
77
|
+
- **Clear All** - Remove all allowed numbers
|
|
78
|
+
- **Back** - Return to main menu
|
|
79
|
+
|
|
80
|
+
### Blocked Numbers Management
|
|
81
|
+
- **View List** - See all numbers that have been ignored (not in allow list)
|
|
82
|
+
- **Allow** - Move a blocked number to the allowed list
|
|
83
|
+
- **Delete** - Remove a number from the blocked list
|
|
84
|
+
- **Back** - Return to main menu
|
|
67
85
|
|
|
68
86
|
## Project Structure
|
|
69
87
|
|
package/package.json
CHANGED
package/whatsapp-pi.ts
CHANGED
|
@@ -7,25 +7,14 @@ import { AudioService } from './src/services/audio.service.js';
|
|
|
7
7
|
console.log("[WhatsApp-Pi] Extension file loaded by Pi...");
|
|
8
8
|
export default function (pi: ExtensionAPI) {
|
|
9
9
|
// Register verbose flag
|
|
10
|
-
pi.registerFlag("v", {
|
|
11
|
-
description: "Enable verbose mode (show Baileys trace logs)",
|
|
12
|
-
type: "boolean",
|
|
13
|
-
default: false
|
|
14
|
-
});
|
|
15
10
|
pi.registerFlag("verbose", {
|
|
16
11
|
description: "Enable verbose mode (show Baileys trace logs)",
|
|
17
12
|
type: "boolean",
|
|
18
13
|
default: false
|
|
19
14
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
description: "Auto-connect to WhatsApp on startup",
|
|
24
|
-
type: "boolean",
|
|
25
|
-
default: false
|
|
26
|
-
});
|
|
27
|
-
pi.registerFlag("whatsapp", {
|
|
28
|
-
description: "Auto-connect to WhatsApp on startup",
|
|
15
|
+
|
|
16
|
+
pi.registerFlag("whatsapp-pi-off", {
|
|
17
|
+
description: "Disable WhatsApp-Pi on startup",
|
|
29
18
|
type: "boolean",
|
|
30
19
|
default: false
|
|
31
20
|
});
|
|
@@ -34,17 +23,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
34
23
|
const whatsappService = new WhatsAppService(sessionManager);
|
|
35
24
|
const audioService = new AudioService();
|
|
36
25
|
const menuHandler = new MenuHandler(whatsappService, sessionManager);
|
|
37
|
-
let
|
|
26
|
+
let _ctx: ExtensionContext | undefined;
|
|
27
|
+
|
|
38
28
|
|
|
39
29
|
// Initial status setup
|
|
40
30
|
pi.on("session_start", async (_event, ctx) => {
|
|
31
|
+
_ctx = ctx;
|
|
41
32
|
// Check verbose mode
|
|
42
33
|
const isVerboseFlagSet = process.argv.includes("--verbose");
|
|
43
|
-
|
|
34
|
+
|
|
44
35
|
const isVerbose = isVerboseFlagSet;
|
|
45
|
-
|
|
36
|
+
|
|
46
37
|
whatsappService.setVerboseMode(isVerbose);
|
|
47
|
-
|
|
38
|
+
|
|
48
39
|
if (isVerbose) {
|
|
49
40
|
console.log('[WhatsApp-Pi] Verbose mode enabled - Baileys trace logs will be shown');
|
|
50
41
|
}
|
|
@@ -53,7 +44,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
53
44
|
ctx.ui.setStatus('whatsapp', status);
|
|
54
45
|
});
|
|
55
46
|
await sessionManager.ensureInitialized();
|
|
56
|
-
|
|
47
|
+
|
|
57
48
|
for (const entry of ctx.sessionManager.getEntries()) {
|
|
58
49
|
if (entry.type === "custom" && entry.customType === "whatsapp-state") {
|
|
59
50
|
const data = entry.data as any;
|
|
@@ -69,19 +60,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
69
60
|
}
|
|
70
61
|
|
|
71
62
|
// Check whatsapp flag
|
|
72
|
-
const
|
|
73
|
-
|
|
63
|
+
const isWhatsappPiOff = process.argv.includes("--whatsapp-pi-off");
|
|
64
|
+
|
|
74
65
|
// Auto-connect removed to avoid socket conflicts
|
|
75
66
|
if (await sessionManager.isRegistered()) {
|
|
76
|
-
const shouldConnect =
|
|
67
|
+
const shouldConnect = !isWhatsappPiOff;
|
|
77
68
|
|
|
78
69
|
if (shouldConnect) {
|
|
79
70
|
ctx.ui.setStatus('whatsapp', '| WhatsApp: Auto-connecting...');
|
|
80
|
-
|
|
71
|
+
|
|
81
72
|
// Retry logic (max 3 attempts, 3s delay)
|
|
82
73
|
let attempts = 0;
|
|
83
74
|
const maxAttempts = 4; // Initial + 3 retries
|
|
84
|
-
|
|
75
|
+
|
|
85
76
|
const tryConnect = async () => {
|
|
86
77
|
attempts++;
|
|
87
78
|
try {
|
|
@@ -102,8 +93,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
102
93
|
// We just ensure state is loaded, but do NOT call whatsappService.start()
|
|
103
94
|
await sessionManager.setStatus('disconnected');
|
|
104
95
|
}
|
|
105
|
-
} else
|
|
106
|
-
ctx.ui.notify('WhatsApp:
|
|
96
|
+
} else {
|
|
97
|
+
ctx.ui.notify('WhatsApp: Manual login required via /whatsapp.', 'info');
|
|
107
98
|
}
|
|
108
99
|
|
|
109
100
|
ctx.ui.notify('WhatsApp: Session reset via /new is now fully supported.', 'info');
|
|
@@ -117,7 +108,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
117
108
|
if (!msg.message) return;
|
|
118
109
|
|
|
119
110
|
let text = msg.message?.conversation || msg.message?.extendedTextMessage?.text || "";
|
|
120
|
-
|
|
111
|
+
|
|
121
112
|
const sender = msg.key.remoteJid?.split('@')[0] || "unknown";
|
|
122
113
|
const pushName = msg.pushName || "WhatsApp User";
|
|
123
114
|
|
|
@@ -147,14 +138,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
147
138
|
console.log(`[WhatsApp-Pi] ${pushName} (+${sender}): ${text}`);
|
|
148
139
|
|
|
149
140
|
// Handle commands
|
|
150
|
-
if (text.trim().toLowerCase().startsWith('/
|
|
151
|
-
console.log(`[WhatsApp-Pi] Session
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
await
|
|
156
|
-
}
|
|
157
|
-
|
|
141
|
+
if (text.trim().toLowerCase().startsWith('/compact')) {
|
|
142
|
+
console.log(`[WhatsApp-Pi] Session compact requested by ${pushName}.`);
|
|
143
|
+
|
|
144
|
+
if (_ctx) {
|
|
145
|
+
_ctx.compact();
|
|
146
|
+
await whatsappService.sendMessage(remoteJid!, "Sessão compactada com sucesso! ✅");
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (text.trim().toLowerCase().startsWith('/abort')) {
|
|
152
|
+
console.log(`[WhatsApp-Pi] Abort requested by ${pushName}.`);
|
|
153
|
+
if (_ctx) {
|
|
154
|
+
_ctx.abort();
|
|
155
|
+
await whatsappService.sendMessage(remoteJid!, "Abortado! ✅");
|
|
158
156
|
}
|
|
159
157
|
return;
|
|
160
158
|
}
|
|
@@ -167,9 +165,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
167
165
|
pi.registerCommand("whatsapp", {
|
|
168
166
|
description: "Manage WhatsApp integration",
|
|
169
167
|
handler: async (args, ctx) => {
|
|
170
|
-
|
|
168
|
+
_ctx = ctx;
|
|
171
169
|
await menuHandler.handleCommand(ctx);
|
|
172
|
-
|
|
170
|
+
|
|
173
171
|
// Persist state after changes
|
|
174
172
|
pi.appendEntry("whatsapp-state", {
|
|
175
173
|
status: sessionManager.getStatus(),
|