whatsapp-pi 1.0.3 → 1.0.5
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
CHANGED
|
@@ -65,32 +65,6 @@ pi -e whatsapp-pi.ts --verbose
|
|
|
65
65
|
- **Allow Numbers**: Manage contacts that can interact with Pi
|
|
66
66
|
- **Blocked Numbers**: View ignored numbers (not in allow list) and add them to allow list
|
|
67
67
|
|
|
68
|
-
## Important Configuration
|
|
69
|
-
|
|
70
|
-
### Using Your Own WhatsApp Number
|
|
71
|
-
|
|
72
|
-
If you're using your **own WhatsApp number** (not a separate bot number), you need to modify the message filtering in `src/services/whatsapp.service.ts`:
|
|
73
|
-
|
|
74
|
-
**Remove this line from `handleIncomingMessages()`:**
|
|
75
|
-
```typescript
|
|
76
|
-
// Ignore messages sent by the bot itself
|
|
77
|
-
if (msg.key.fromMe) return;
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**Why?** When using your own number:
|
|
81
|
-
- Pi sends messages from your account (marked with `π` symbol)
|
|
82
|
-
- The `fromMe` filter blocks ALL your outgoing messages, including Pi's responses
|
|
83
|
-
- The `π` symbol check is sufficient to prevent message loops
|
|
84
|
-
|
|
85
|
-
**Keep this check:**
|
|
86
|
-
```typescript
|
|
87
|
-
// Ignore messages sent by Pi (marked with π)
|
|
88
|
-
const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text || "";
|
|
89
|
-
if (text.endsWith('π')) return;
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
This ensures Pi doesn't process its own sent messages while still receiving messages from others.
|
|
93
|
-
|
|
94
68
|
## Project Structure
|
|
95
69
|
|
|
96
70
|
```
|
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;
|
|
@@ -127,10 +127,7 @@ export class WhatsAppService {
|
|
|
127
127
|
public async handleIncomingMessages(m: any) {
|
|
128
128
|
if (this.sessionManager.getStatus() !== 'connected') return;
|
|
129
129
|
const msg = m.messages[0];
|
|
130
|
-
if (!msg || !msg.key.remoteJid) return;
|
|
131
|
-
|
|
132
|
-
// KEEP IT COMMENTED
|
|
133
|
-
// if (msg.key.fromMe) return;
|
|
130
|
+
if (!msg || !msg.key.remoteJid || msg.key.fromMe) return;
|
|
134
131
|
|
|
135
132
|
// Ignore messages sent by Pi (marked with π)
|
|
136
133
|
const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text || "";
|
package/src/ui/menu.handler.ts
CHANGED
|
@@ -91,7 +91,7 @@ export class MenuHandler {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
private async manageBlockList(ctx: ExtensionCommandContext) {
|
|
94
|
-
const list = this.sessionManager.
|
|
94
|
+
const list = this.sessionManager.getIgnoredNumbers();
|
|
95
95
|
|
|
96
96
|
if (list.length === 0) {
|
|
97
97
|
ctx.ui.notify('No blocked numbers', 'info');
|
|
@@ -115,19 +115,21 @@ export class MenuHandler {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
private async manageBlockedNumber(ctx: ExtensionCommandContext, number: string) {
|
|
118
|
-
const action = await ctx.ui.select(`Manage ${number}`, ['
|
|
118
|
+
const action = await ctx.ui.select(`Manage ${number}`, ['Allow', 'Delete', 'Back']);
|
|
119
119
|
|
|
120
|
-
if (action === '
|
|
121
|
-
const ok = await ctx.ui.confirm('
|
|
120
|
+
if (action === 'Allow') {
|
|
121
|
+
const ok = await ctx.ui.confirm('Allow', `Move ${number} to Allowed Numbers?`);
|
|
122
122
|
if (ok) {
|
|
123
|
-
|
|
123
|
+
const list = this.sessionManager.getIgnoredNumbers();
|
|
124
|
+
const contact = list.find(c => c.number === number);
|
|
125
|
+
await this.sessionManager.addNumber(number, contact?.name);
|
|
124
126
|
ctx.ui.notify(`${number} moved to Allowed List`, 'info');
|
|
125
127
|
}
|
|
126
128
|
await this.manageBlockList(ctx);
|
|
127
129
|
} else if (action === 'Delete') {
|
|
128
130
|
const ok = await ctx.ui.confirm('Delete', `Remove ${number} from Block List?`);
|
|
129
131
|
if (ok) {
|
|
130
|
-
await this.sessionManager.
|
|
132
|
+
await this.sessionManager.removeIgnoredNumber(number);
|
|
131
133
|
ctx.ui.notify(`${number} removed from Block List`, 'info');
|
|
132
134
|
}
|
|
133
135
|
await this.manageBlockList(ctx);
|