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-reply-23description: "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."4author: 무펭이 🐧5metadata:6 source: https://skillmd.com/skills/johnalbertini14-glitch/auto-reply-27---89# Instagram DM Auto-Reply 🐧1011v2.js (Internal API) based. 0 browser snapshots, CDP cookie extraction → Instagram REST API direct calls.1213## Prerequisites1415- OpenClaw browser running (port 18800)16- Instagram tab open and logged in17- `ws` npm package (`npm i -g ws` or local)1819## Script List2021| Script | Purpose |22|--------|---------|23| `scripts/v2.js` | DM CLI (inbox, unread, check, read, reply) |24| `scripts/auto-reply.js` | Read dm-alert.json, security check, return reply metadata |25| `scripts/check-notify.js` | Check new DM notifications (for cron, state file based) |26| `scripts/dm-watcher.js` | Real-time DM detection daemon (15s polling) |2728## Core Workflows2930### 1. Check DMs3132```bash33node scripts/v2.js check # unread count (lightest)34node scripts/v2.js unread # unread DM list35node scripts/v2.js inbox # full DM list36```3738### 2. Read Messages3940```bash41node scripts/v2.js read "<username>" -l 542```4344### 3. Reply4546```bash47node scripts/v2.js reply "<username>" "message content"48```4950On API failure, returns JSON with `method: "use_browser"` + `threadUrl` → fallback to browser tool.5152### 4. Notification Check (cron integration)5354```bash55node scripts/check-notify.js56```57- If new DMs: outputs `📩 새 DM N건: ...`58- If none: outputs `no_new`59- Uses state file `dm-state.json` to prevent duplicates6061### 5. Auto-Reply Flow6263```bash64node scripts/auto-reply.js65```66671. Read `dm-alert.json` (created by dm-watcher)682. Run security check on each DM693. Return results: `needs_reply` / `security_alert` / `skipped`704. AI generates replies for `needs_reply` DMs → send via `v2.js reply`7172### 6. Real-time Detection Daemon7374```bash75node scripts/dm-watcher.js # detection only76node scripts/dm-watcher.js --auto-reply # includes Discord notification77```7879Polls `v2.js check` every 15s. On new DM detection, writes `dm-alert.json` + Discord DM notification.8081## Security Check (Injection Rejection)8283`auto-reply.js`'s `SECURITY_PATTERNS` detects:8485- **Prompt Injection**: "ignore previous", "system prompt", "you are now", "act as", "pretend"86- **Jailbreak Attempts**: "override", "jailbreak", "DAN mode", "bypass"87- **Sensitive Info Requests**: "secret key", "private key", "seed phrase", "wallet address"88- **Code Execution Attempts**: "execute command", "run script", "eval(", "rm -rf", "sudo"89- **Social Engineering**: "simulation mode", zero-width characters9091On threat detection → don't reply, return `security_alert`. Separate notification sent.9293## Cron Setup Example9495```yaml96# Check DMs every 5 minutes97- schedule: "*/5 * * * *"98 command: "node /path/to/scripts/check-notify.js"99 systemEvent: true100101# Or dm-watcher daemon for continuous monitoring102- schedule: "@reboot"103 command: "node /path/to/scripts/dm-watcher.js --auto-reply"104 background: true105```106107## Token Efficiency108109- inbox/check: exec 1 call (~500 tokens)110- reply: exec 1 call (~200 tokens)111- browser snapshots: 0112113---114> 🐧 Built by **무펭이** — [Mupengism](https://github.com/mupeng) ecosystem skill