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:
@@ -464,6 +464,18 @@ def create_bot(config: Config) -> discord.Client:
|
||||
result = await asyncio.to_thread(fast_dispatch, "email", ["save"])
|
||||
await interaction.followup.send(result)
|
||||
|
||||
@email_group.command(name="digest", description="Procesează emailuri necitite și trimite rezumate pe WhatsApp")
|
||||
async def email_digest(interaction: discord.Interaction) -> None:
|
||||
await interaction.response.defer()
|
||||
result = await asyncio.to_thread(fast_dispatch, "email", ["digest"])
|
||||
await interaction.followup.send(result)
|
||||
|
||||
@email_group.command(name="forward", description="Forwardează emailuri necitite direct pe WhatsApp fără rezumat")
|
||||
async def email_forward(interaction: discord.Interaction) -> None:
|
||||
await interaction.response.defer()
|
||||
result = await asyncio.to_thread(fast_dispatch, "email", ["forward"])
|
||||
await interaction.followup.send(result)
|
||||
|
||||
tree.add_command(email_group)
|
||||
|
||||
# --- Calendar commands ---
|
||||
@@ -878,6 +890,10 @@ def create_bot(config: Config) -> discord.Client:
|
||||
|
||||
@client.event
|
||||
async def on_ready() -> None:
|
||||
# Sync to each guild instantly, then global (global can take up to 1h)
|
||||
for guild in client.guilds:
|
||||
tree.copy_global_to(guild=guild)
|
||||
await tree.sync(guild=guild)
|
||||
await tree.sync()
|
||||
scheduler = getattr(client, "scheduler", None)
|
||||
if scheduler is not None:
|
||||
|
||||
@@ -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