Instagram DM Auto-Reply 🐧
v2.js (Internal API) based. 0 browser snapshots, CDP cookie extraction → Instagram REST API direct calls.
Prerequisites
- OpenClaw browser running (port 18800)
- Instagram tab open and logged in
ws npm package (npm i -g ws or local)
Script List
| Script |
Purpose |
scripts/v2.js |
DM CLI (inbox, unread, check, read, reply) |
scripts/auto-reply.js |
Read dm-alert.json, security check, return reply metadata |
scripts/check-notify.js |
Check new DM notifications (for cron, state file based) |
scripts/dm-watcher.js |
Real-time DM detection daemon (15s polling) |
Core Workflows
1. Check DMs
node scripts/v2.js check # unread count (lightest)
node scripts/v2.js unread # unread DM list
node scripts/v2.js inbox # full DM list
2. Read Messages
node scripts/v2.js read "<username>" -l 5
3. Reply
node scripts/v2.js reply "<username>" "message content"
On API failure, returns JSON with method: "use_browser" + threadUrl → fallback to browser tool.
4. Notification Check (cron integration)
node scripts/check-notify.js
- If new DMs: outputs
📩 새 DM N건: ...
- If none: outputs
no_new
- Uses state file
dm-state.json to prevent duplicates
5. Auto-Reply Flow
node scripts/auto-reply.js
- Read
dm-alert.json (created by dm-watcher)
- Run security check on each DM
- Return results:
needs_reply / security_alert / skipped
- AI generates replies for
needs_reply DMs → send via v2.js reply
6. Real-time Detection Daemon
node scripts/dm-watcher.js # detection only
node scripts/dm-watcher.js --auto-reply # includes Discord notification
Polls v2.js check every 15s. On new DM detection, writes dm-alert.json + Discord DM notification.
Security Check (Injection Rejection)
auto-reply.js's SECURITY_PATTERNS detects:
- Prompt Injection: "ignore previous", "system prompt", "you are now", "act as", "pretend"
- Jailbreak Attempts: "override", "jailbreak", "DAN mode", "bypass"
- Sensitive Info Requests: "secret key", "private key", "seed phrase", "wallet address"
- Code Execution Attempts: "execute command", "run script", "eval(", "rm -rf", "sudo"
- Social Engineering: "simulation mode", zero-width characters
On threat detection → don't reply, return security_alert. Separate notification sent.
Cron Setup Example
# Check DMs every 5 minutes
- schedule: "*/5 * * * *"
command: "node /path/to/scripts/check-notify.js"
systemEvent: true
# Or dm-watcher daemon for continuous monitoring
- schedule: "@reboot"
command: "node /path/to/scripts/dm-watcher.js --auto-reply"
background: true
Token Efficiency
- inbox/check: exec 1 call (~500 tokens)
- reply: exec 1 call (~200 tokens)
- browser snapshots: 0
🐧 Built by 무펭이 — Mupengism ecosystem skill
1---2name: auto-reply3description: Instagram DM auto-reply system. DM monitoring, reading, replying, security check (injection rejection). Use when checking Instagram DMs, reading unread messages, replying to DMs, setting up DM monitoring cron jobs, or handling DM auto-reply workflows. Triggers on: Instagram DM, DM check, DM reply, DM auto-reply, dm-alert.4---5
6# Instagram DM Auto-Reply 🐧
7
8v2.js (Internal API) based. 0 browser snapshots, CDP cookie extraction → Instagram REST API direct calls.
9
10## Prerequisites
11
12- OpenClaw browser running (port 18800)
13- Instagram tab open and logged in
14- `ws` npm package (`npm i -g ws` or local)
15
16## Script List
17
18| Script | Purpose |
19|--------|---------|
20| `scripts/v2.js` | DM CLI (inbox, unread, check, read, reply) |
21| `scripts/auto-reply.js` | Read dm-alert.json, security check, return reply metadata |
22| `scripts/check-notify.js` | Check new DM notifications (for cron, state file based) |
23| `scripts/dm-watcher.js` | Real-time DM detection daemon (15s polling) |
24
25## Core Workflows
26
27### 1. Check DMs
28
29```bash
30node scripts/v2.js check # unread count (lightest)
31node scripts/v2.js unread # unread DM list
32node scripts/v2.js inbox # full DM list
33```
34
35### 2. Read Messages
36
37```bash
38node scripts/v2.js read "<username>" -l 5
39```
40
41### 3. Reply
42
43```bash
44node scripts/v2.js reply "<username>" "message content"
45```
46
47On API failure, returns JSON with `method: "use_browser"` + `threadUrl` → fallback to browser tool.
48
49### 4. Notification Check (cron integration)
50
51```bash
52node scripts/check-notify.js
53```
54- If new DMs: outputs `📩 새 DM N건: ...`
55- If none: outputs `no_new`
56- Uses state file `dm-state.json` to prevent duplicates
57
58### 5. Auto-Reply Flow
59
60```bash
61node scripts/auto-reply.js
62```
63
641. Read `dm-alert.json` (created by dm-watcher)
652. Run security check on each DM
663. Return results: `needs_reply` / `security_alert` / `skipped`
674. AI generates replies for `needs_reply` DMs → send via `v2.js reply`
68
69### 6. Real-time Detection Daemon
70
71```bash
72node scripts/dm-watcher.js # detection only
73node scripts/dm-watcher.js --auto-reply # includes Discord notification
74```
75
76Polls `v2.js check` every 15s. On new DM detection, writes `dm-alert.json` + Discord DM notification.
77
78## Security Check (Injection Rejection)
79
80`auto-reply.js`'s `SECURITY_PATTERNS` detects:
81
82- **Prompt Injection**: "ignore previous", "system prompt", "you are now", "act as", "pretend"
83- **Jailbreak Attempts**: "override", "jailbreak", "DAN mode", "bypass"
84- **Sensitive Info Requests**: "secret key", "private key", "seed phrase", "wallet address"
85- **Code Execution Attempts**: "execute command", "run script", "eval(", "rm -rf", "sudo"
86- **Social Engineering**: "simulation mode", zero-width characters
87
88On threat detection → don't reply, return `security_alert`. Separate notification sent.
89
90## Cron Setup Example
91
92```yaml
93# Check DMs every 5 minutes
94- schedule: "*/5 * * * *"
95 command: "node /path/to/scripts/check-notify.js"
96 systemEvent: true
97
98# Or dm-watcher daemon for continuous monitoring
99- schedule: "@reboot"
100 command: "node /path/to/scripts/dm-watcher.js --auto-reply"
101 background: true
102```
103
104## Token Efficiency
105
106- inbox/check: exec 1 call (~500 tokens)
107- reply: exec 1 call (~200 tokens)
108- browser snapshots: 0
109
110---
111> 🐧 Built by **무펭이** — [Mupengism](https://github.com/mupeng) ecosystem skill