feat(email): send attachments as WhatsApp documents, fix forward sender

- Add /send-document endpoint to WhatsApp bridge (base64 document send)
- save_email_as_note() now saves attachment files to disk alongside note
- email_digest: extract original sender for Fwd: emails so header shows
  the real author, not the forwarder; send attachment files after summary
- email_forward: send attachment files as documents after text parts
- Add extract_original_sender() and save_email_attachment_files() helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 07:50:40 +00:00
parent 417de65069
commit 51af0918a4
4 changed files with 145 additions and 11 deletions

View File

@@ -187,6 +187,29 @@ app.post('/send', async (req, res) => {
}
});
app.post('/send-document', async (req, res) => {
const { to, filename, mimetype, data_base64, caption } = req.body || {};
if (!to || !filename || !data_base64) {
return res.status(400).json({ ok: false, error: 'missing "to", "filename", or "data_base64"' });
}
if (!connected || !sock) {
return res.status(503).json({ ok: false, error: 'not connected to WhatsApp' });
}
try {
const buffer = Buffer.from(data_base64, 'base64');
const result = await sock.sendMessage(to, {
document: buffer,
fileName: filename,
mimetype: mimetype || 'application/octet-stream',
caption: caption || '',
});
res.json({ ok: true, id: result.key.id });
} catch (err) {
console.error('[whatsapp] Send document failed:', err.message);
res.status(500).json({ ok: false, error: err.message });
}
});
app.post('/react', async (req, res) => {
const { to, id, emoji, fromMe, participant } = req.body || {};