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.
Files changed (3) hide show
  1. package/README.md +20 -2
  2. package/package.json +1 -1
  3. 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
- - **Allow Numbers**: Manage contacts that can interact with Pi
66
- - **Blocked Numbers**: View ignored numbers (not in allow list) and add them to allow list
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-pi",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "type": "module",
5
5
  "description": "WhatsApp integration extension for Pi",
6
6
  "main": "whatsapp-pi.ts",
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
- // Register whatsapp flags
22
- pi.registerFlag("w", {
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 lastCommandCtx: ExtensionCommandContext | undefined;
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 isConnectFlagSet = process.argv.includes("--whatsapp");
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 = isConnectFlagSet;
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 if (isConnectFlagSet) {
106
- ctx.ui.notify('WhatsApp: Auto-connect skipped. Manual login required.', 'info');
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('/new')) {
151
- 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.");
154
- if (lastCommandCtx) {
155
- await lastCommandCtx.newSession();
156
- } else {
157
- pi.sendUserMessage("Use /whatsapp in Pi TUI to activate /new in whatsapp", { deliverAs: "followUp" });
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
- lastCommandCtx = ctx;
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(),