feat(email): add digest and forward commands to WhatsApp
Digest summarizes unread emails via Claude CLI; forward sends raw content (split to 4096 chars). Wired as /email digest and /email forward slash commands, plus instant per-guild sync on ready. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -106,7 +106,7 @@ def cmd_test(args: list[str]) -> str:
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def cmd_email(args: list[str]) -> str:
|
||||
"""Dispatch: /email, /email send ..., /email save."""
|
||||
"""Dispatch: /email, /email send ..., /email save, /email digest."""
|
||||
if not args:
|
||||
return _email_check()
|
||||
sub = args[0].lower()
|
||||
@@ -114,7 +114,11 @@ def cmd_email(args: list[str]) -> str:
|
||||
return _email_send(args[1:])
|
||||
if sub == "save":
|
||||
return _email_save()
|
||||
return f"Unknown email sub-command: {sub}. Use: /email, /email send, /email save"
|
||||
if sub == "digest":
|
||||
return _email_digest()
|
||||
if sub == "forward":
|
||||
return _email_forward()
|
||||
return f"Unknown email sub-command: {sub}. Use: /email, /email send, /email save, /email digest, /email forward"
|
||||
|
||||
|
||||
def _email_check() -> str:
|
||||
@@ -185,6 +189,62 @@ def _email_send(args: list[str]) -> str:
|
||||
return f"Email send error: {e}"
|
||||
|
||||
|
||||
def _email_digest() -> str:
|
||||
"""Run email digest: save unread emails, generate summaries, send on WhatsApp."""
|
||||
script = TOOLS_DIR / "email_digest.py"
|
||||
if not script.exists():
|
||||
return "email_digest.py not found."
|
||||
|
||||
import sys as _sys
|
||||
|
||||
def _run():
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[_sys.executable, str(script)],
|
||||
timeout=120,
|
||||
cwd=str(PROJECT_ROOT),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
log.error("Email digest failed: %s", result.stderr.strip()[:300])
|
||||
else:
|
||||
log.info("Email digest: %s", result.stdout.strip()[:300])
|
||||
except Exception as e:
|
||||
log.error("Email digest error: %s", e)
|
||||
|
||||
threading.Thread(target=_run, daemon=True).start()
|
||||
return "Procesez emailurile... rezumatele vin pe WhatsApp."
|
||||
|
||||
|
||||
def _email_forward() -> str:
|
||||
"""Forward unread emails directly to WhatsApp without summarizing."""
|
||||
script = TOOLS_DIR / "email_forward.py"
|
||||
if not script.exists():
|
||||
return "email_forward.py not found."
|
||||
|
||||
import sys as _sys
|
||||
|
||||
def _run():
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[_sys.executable, str(script)],
|
||||
timeout=60,
|
||||
cwd=str(PROJECT_ROOT),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
log.error("Email forward failed: %s", result.stderr.strip()[:300])
|
||||
else:
|
||||
log.info("Email forward: %s", result.stdout.strip()[:300])
|
||||
except Exception as e:
|
||||
log.error("Email forward error: %s", e)
|
||||
|
||||
threading.Thread(target=_run, daemon=True).start()
|
||||
return "Forwardez emailurile pe WhatsApp..."
|
||||
|
||||
|
||||
def _email_save() -> str:
|
||||
"""Save unread emails as KB notes."""
|
||||
script = TOOLS_DIR / "email_process.py"
|
||||
@@ -593,6 +653,8 @@ Email:
|
||||
/email — Check unread emails
|
||||
/email send <to> <subject> :: <body> — Send email
|
||||
/email save — Save unread emails to KB
|
||||
/email digest — Rezumate emailuri necitite → WhatsApp
|
||||
/email forward — Forward emailuri necitite direct → WhatsApp (fără rezumat)
|
||||
|
||||
Calendar:
|
||||
/calendar — Today + tomorrow events
|
||||
|
||||
Reference in New Issue
Block a user