whatsapp-pi 1.0.4 → 1.0.6
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
CHANGED
|
@@ -85,6 +85,11 @@ export class SessionManager {
|
|
|
85
85
|
return this.ignoredNumbers;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
async removeIgnoredNumber(number: string) {
|
|
89
|
+
this.ignoredNumbers = this.ignoredNumbers.filter(c => c.number !== number);
|
|
90
|
+
await this.saveConfig();
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
async addNumber(number: any, name?: string) {
|
|
89
94
|
// Handle potential nested objects from legacy bugs
|
|
90
95
|
let cleanNumber = number;
|
|
@@ -86,8 +86,14 @@ export class WhatsAppService {
|
|
|
86
86
|
|
|
87
87
|
console.error(`Connection closed [${statusCode}]. Reconnecting: ${shouldReconnect}`);
|
|
88
88
|
|
|
89
|
-
if (
|
|
90
|
-
|
|
89
|
+
if (
|
|
90
|
+
errorMessage.includes('bad-request') ||
|
|
91
|
+
statusCode === 400 ||
|
|
92
|
+
statusCode === 401 ||
|
|
93
|
+
statusCode === DisconnectReason.loggedOut ||
|
|
94
|
+
statusCode === DisconnectReason.badSession
|
|
95
|
+
) {
|
|
96
|
+
console.error(`Session invalid or logged out [${statusCode}] - clearing session and forcing re-auth`);
|
|
91
97
|
await this.sessionManager.clearSession();
|
|
92
98
|
this.sessionManager.setStatus('logged-out');
|
|
93
99
|
this.onStatusUpdate?.('| WhatsApp: Logged out');
|
|
@@ -127,7 +133,7 @@ export class WhatsAppService {
|
|
|
127
133
|
public async handleIncomingMessages(m: any) {
|
|
128
134
|
if (this.sessionManager.getStatus() !== 'connected') return;
|
|
129
135
|
const msg = m.messages[0];
|
|
130
|
-
if (!msg || !msg.key.remoteJid) return;
|
|
136
|
+
if (!msg || !msg.key.remoteJid || msg.key.fromMe) return;
|
|
131
137
|
|
|
132
138
|
// Ignore messages sent by Pi (marked with π)
|
|
133
139
|
const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text || "";
|
package/src/ui/menu.handler.ts
CHANGED
|
@@ -35,7 +35,6 @@ export class MenuHandler {
|
|
|
35
35
|
switch (choice) {
|
|
36
36
|
case 'Connect WhatsApp':
|
|
37
37
|
this.whatsappService.setQRCodeCallback((qr) => {
|
|
38
|
-
ctx.ui.notify('Scan the QR code in the terminal', 'info');
|
|
39
38
|
qrcode.generate(qr, { small: true });
|
|
40
39
|
});
|
|
41
40
|
await this.whatsappService.start();
|
|
@@ -91,7 +90,7 @@ export class MenuHandler {
|
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
private async manageBlockList(ctx: ExtensionCommandContext) {
|
|
94
|
-
const list = this.sessionManager.
|
|
93
|
+
const list = this.sessionManager.getIgnoredNumbers();
|
|
95
94
|
|
|
96
95
|
if (list.length === 0) {
|
|
97
96
|
ctx.ui.notify('No blocked numbers', 'info');
|
|
@@ -115,19 +114,21 @@ export class MenuHandler {
|
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
private async manageBlockedNumber(ctx: ExtensionCommandContext, number: string) {
|
|
118
|
-
const action = await ctx.ui.select(`Manage ${number}`, ['
|
|
117
|
+
const action = await ctx.ui.select(`Manage ${number}`, ['Allow', 'Delete', 'Back']);
|
|
119
118
|
|
|
120
|
-
if (action === '
|
|
121
|
-
const ok = await ctx.ui.confirm('
|
|
119
|
+
if (action === 'Allow') {
|
|
120
|
+
const ok = await ctx.ui.confirm('Allow', `Move ${number} to Allowed Numbers?`);
|
|
122
121
|
if (ok) {
|
|
123
|
-
|
|
122
|
+
const list = this.sessionManager.getIgnoredNumbers();
|
|
123
|
+
const contact = list.find(c => c.number === number);
|
|
124
|
+
await this.sessionManager.addNumber(number, contact?.name);
|
|
124
125
|
ctx.ui.notify(`${number} moved to Allowed List`, 'info');
|
|
125
126
|
}
|
|
126
127
|
await this.manageBlockList(ctx);
|
|
127
128
|
} else if (action === 'Delete') {
|
|
128
129
|
const ok = await ctx.ui.confirm('Delete', `Remove ${number} from Block List?`);
|
|
129
130
|
if (ok) {
|
|
130
|
-
await this.sessionManager.
|
|
131
|
+
await this.sessionManager.removeIgnoredNumber(number);
|
|
131
132
|
ctx.ui.notify(`${number} removed from Block List`, 'info');
|
|
132
133
|
}
|
|
133
134
|
await this.manageBlockList(ctx);
|
package/whatsapp-pi.ts
CHANGED
|
@@ -144,16 +144,12 @@ export default function(pi: ExtensionAPI) {
|
|
|
144
144
|
// Handle commands
|
|
145
145
|
const cmd = text.trim().toLowerCase();
|
|
146
146
|
if (cmd === '/new') {
|
|
147
|
-
console.log(`[WhatsApp-Pi] Session reset requested by ${pushName}.
|
|
147
|
+
console.log(`[WhatsApp-Pi] Session reset requested by ${pushName}. Clearing context...`);
|
|
148
148
|
|
|
149
|
-
await whatsappService.sendMessage(remoteJid!, "Iniciando nova sessão... 🆕\nO contexto anterior foi limpo
|
|
149
|
+
await whatsappService.sendMessage(remoteJid!, "Iniciando nova sessão... 🆕\nO contexto anterior foi limpo.");
|
|
150
150
|
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
// Exit process. The OS/Service Manager should restart it.
|
|
154
|
-
// When it restarts, it starts a new session by default
|
|
155
|
-
process.exit(0);
|
|
156
|
-
}, 2000);
|
|
151
|
+
// Trigger built-in new command to clear context without exiting
|
|
152
|
+
pi.sendUserMessage("/new");
|
|
157
153
|
return;
|
|
158
154
|
}
|
|
159
155
|
|