Skip to content

Commit 4b6ae98

Browse files
glifocatclaude
andauthored
fix(whatsapp): write pairing code to file for immediate access (qwibitai#745)
The pairing code was only emitted to stdout, which is buffered by the calling process and not visible until the auth command exits (~120s). By also writing to store/pairing-code.txt the moment the code is ready, callers can poll that file and display the code to the user within seconds instead of after the 60s expiry window. Update the add-whatsapp skill instructions to use the background + file-poll pattern instead of waiting on buffered stdout. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3935ac6 commit 4b6ae98

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

.claude/skills/add-whatsapp/SKILL.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,33 @@ Tell the user to run `npm run auth` in another terminal, then:
115115
116116
For pairing code:
117117

118+
Tell the user to have WhatsApp open on **Settings > Linked Devices > Link a Device**, ready to tap **"Link with phone number instead"** — the code expires in ~60 seconds and must be entered immediately.
119+
120+
Run the auth process in the background and poll `store/pairing-code.txt` for the code:
121+
118122
```bash
119-
npx tsx setup/index.ts --step whatsapp-auth -- --method pairing-code --phone <their-phone-number>
123+
rm -f store/pairing-code.txt && npx tsx setup/index.ts --step whatsapp-auth -- --method pairing-code --phone <their-phone-number> > /tmp/wa-auth.log 2>&1 &
120124
```
121125

122-
(Bash timeout: 150000ms). Display PAIRING_CODE from output.
126+
Then immediately poll for the code (do NOT wait for the background command to finish):
123127

124-
Tell the user:
128+
```bash
129+
for i in $(seq 1 20); do [ -f store/pairing-code.txt ] && cat store/pairing-code.txt && break; sleep 1; done
130+
```
131+
132+
Display the code to the user the moment it appears. Tell them:
125133

126-
> A pairing code will appear. **Enter it within 60 seconds**codes expire quickly.
134+
> **Enter this code now**it expires in ~60 seconds.
127135
>
128136
> 1. Open WhatsApp > **Settings** > **Linked Devices** > **Link a Device**
129137
> 2. Tap **Link with phone number instead**
130138
> 3. Enter the code immediately
131-
>
132-
> If the code expires, re-run the command — a new code will be generated.
139+
140+
After the user enters the code, poll for authentication to complete:
141+
142+
```bash
143+
for i in $(seq 1 60); do grep -q 'AUTH_STATUS: authenticated' /tmp/wa-auth.log 2>/dev/null && echo "authenticated" && break; grep -q 'AUTH_STATUS: failed' /tmp/wa-auth.log 2>/dev/null && echo "failed" && break; sleep 2; done
144+
```
133145

134146
**If failed:** qr_timeout → re-run. logged_out → delete `store/auth/` and re-run. 515 → re-run. timeout → ask user, offer retry.
135147

.claude/skills/add-whatsapp/add/setup/whatsapp-auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ async function handlePairingCode(
306306
process.exit(3);
307307
}
308308

309+
// Write to file immediately so callers can read it without waiting for stdout
310+
try {
311+
fs.writeFileSync(
312+
path.join(projectRoot, 'store', 'pairing-code.txt'),
313+
pairingCode,
314+
);
315+
} catch {
316+
/* non-fatal */
317+
}
318+
309319
// Emit pairing code immediately so the caller can display it to the user
310320
emitAuthStatus('pairing-code', 'pairing_code_ready', 'waiting', {
311321
PAIRING_CODE: pairingCode,

0 commit comments

Comments
 (0)