chore: auto-commit from dashboard
This commit is contained in:
@@ -17,6 +17,7 @@ let sock = null;
|
||||
let connected = false;
|
||||
let phoneNumber = null;
|
||||
let currentQR = null;
|
||||
let currentPairingCode = null;
|
||||
let reconnectAttempts = 0;
|
||||
let messageQueue = [];
|
||||
let shuttingDown = false;
|
||||
@@ -122,6 +123,34 @@ app.get('/status', (_req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/pair', async (req, res) => {
|
||||
if (connected) {
|
||||
return res.json({ error: 'already connected' });
|
||||
}
|
||||
const { phone } = req.body || {};
|
||||
if (!phone) {
|
||||
return res.status(400).json({ error: 'missing "phone" in body' });
|
||||
}
|
||||
if (!sock) {
|
||||
return res.status(503).json({ error: 'socket not ready yet, try again in a few seconds' });
|
||||
}
|
||||
try {
|
||||
const code = await sock.requestPairingCode(phone.replace(/\D/g, ''));
|
||||
currentPairingCode = code;
|
||||
console.log(`[whatsapp] Pairing code for ${phone}: ${code}`);
|
||||
res.json({ ok: true, code });
|
||||
} catch (err) {
|
||||
console.error('[whatsapp] Pairing code error:', err.message);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/pair-code', (_req, res) => {
|
||||
if (connected) return res.json({ error: 'already connected' });
|
||||
if (!currentPairingCode) return res.json({ error: 'no pairing code yet — POST /pair first' });
|
||||
res.json({ code: currentPairingCode });
|
||||
});
|
||||
|
||||
app.get('/qr', (_req, res) => {
|
||||
if (connected) {
|
||||
return res.json({ error: 'already connected' });
|
||||
|
||||
Reference in New Issue
Block a user