whatsapp-pi 1.0.10 → 1.0.11
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/package.json +1 -1
- package/whatsapp-pi.ts +19 -30
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
|
});
|
|
@@ -40,11 +29,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
40
29
|
pi.on("session_start", async (_event, ctx) => {
|
|
41
30
|
// Check verbose mode
|
|
42
31
|
const isVerboseFlagSet = process.argv.includes("--verbose");
|
|
43
|
-
|
|
32
|
+
|
|
44
33
|
const isVerbose = isVerboseFlagSet;
|
|
45
|
-
|
|
34
|
+
|
|
46
35
|
whatsappService.setVerboseMode(isVerbose);
|
|
47
|
-
|
|
36
|
+
|
|
48
37
|
if (isVerbose) {
|
|
49
38
|
console.log('[WhatsApp-Pi] Verbose mode enabled - Baileys trace logs will be shown');
|
|
50
39
|
}
|
|
@@ -53,7 +42,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
53
42
|
ctx.ui.setStatus('whatsapp', status);
|
|
54
43
|
});
|
|
55
44
|
await sessionManager.ensureInitialized();
|
|
56
|
-
|
|
45
|
+
|
|
57
46
|
for (const entry of ctx.sessionManager.getEntries()) {
|
|
58
47
|
if (entry.type === "custom" && entry.customType === "whatsapp-state") {
|
|
59
48
|
const data = entry.data as any;
|
|
@@ -69,19 +58,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
69
58
|
}
|
|
70
59
|
|
|
71
60
|
// Check whatsapp flag
|
|
72
|
-
const
|
|
73
|
-
|
|
61
|
+
const isWhatsappPiOff = process.argv.includes("--whatsapp-pi-off");
|
|
62
|
+
|
|
74
63
|
// Auto-connect removed to avoid socket conflicts
|
|
75
64
|
if (await sessionManager.isRegistered()) {
|
|
76
|
-
const shouldConnect =
|
|
65
|
+
const shouldConnect = !isWhatsappPiOff;
|
|
77
66
|
|
|
78
67
|
if (shouldConnect) {
|
|
79
68
|
ctx.ui.setStatus('whatsapp', '| WhatsApp: Auto-connecting...');
|
|
80
|
-
|
|
69
|
+
|
|
81
70
|
// Retry logic (max 3 attempts, 3s delay)
|
|
82
71
|
let attempts = 0;
|
|
83
72
|
const maxAttempts = 4; // Initial + 3 retries
|
|
84
|
-
|
|
73
|
+
|
|
85
74
|
const tryConnect = async () => {
|
|
86
75
|
attempts++;
|
|
87
76
|
try {
|
|
@@ -102,8 +91,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
102
91
|
// We just ensure state is loaded, but do NOT call whatsappService.start()
|
|
103
92
|
await sessionManager.setStatus('disconnected');
|
|
104
93
|
}
|
|
105
|
-
} else
|
|
106
|
-
ctx.ui.notify('WhatsApp:
|
|
94
|
+
} else {
|
|
95
|
+
ctx.ui.notify('WhatsApp: Manual login required via /whatsapp.', 'info');
|
|
107
96
|
}
|
|
108
97
|
|
|
109
98
|
ctx.ui.notify('WhatsApp: Session reset via /new is now fully supported.', 'info');
|
|
@@ -117,7 +106,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
117
106
|
if (!msg.message) return;
|
|
118
107
|
|
|
119
108
|
let text = msg.message?.conversation || msg.message?.extendedTextMessage?.text || "";
|
|
120
|
-
|
|
109
|
+
|
|
121
110
|
const sender = msg.key.remoteJid?.split('@')[0] || "unknown";
|
|
122
111
|
const pushName = msg.pushName || "WhatsApp User";
|
|
123
112
|
|
|
@@ -149,12 +138,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
149
138
|
// Handle commands
|
|
150
139
|
if (text.trim().toLowerCase().startsWith('/new')) {
|
|
151
140
|
console.log(`[WhatsApp-Pi] Session reset requested by ${pushName}. Clearing context...`);
|
|
152
|
-
|
|
153
|
-
await whatsappService.sendMessage(remoteJid!, "Iniciando nova sessão... 🆕\nO contexto anterior foi limpo.");
|
|
141
|
+
|
|
154
142
|
if (lastCommandCtx) {
|
|
155
143
|
await lastCommandCtx.newSession();
|
|
144
|
+
await whatsappService.sendMessage(remoteJid!, "Sessão iniciada com sucesso! ✅");
|
|
156
145
|
} else {
|
|
157
|
-
pi.sendUserMessage("Use /whatsapp
|
|
146
|
+
pi.sendUserMessage("Use /whatsapp no Pi TUI para ativar o comando /new no whatsapp.", { deliverAs: "followUp" });
|
|
158
147
|
}
|
|
159
148
|
return;
|
|
160
149
|
}
|
|
@@ -169,7 +158,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
169
158
|
handler: async (args, ctx) => {
|
|
170
159
|
lastCommandCtx = ctx;
|
|
171
160
|
await menuHandler.handleCommand(ctx);
|
|
172
|
-
|
|
161
|
+
|
|
173
162
|
// Persist state after changes
|
|
174
163
|
pi.appendEntry("whatsapp-state", {
|
|
175
164
|
status: sessionManager.getStatus(),
|