Files
Cortex-Inara/cortex/tools/notify.py
Scott Idem fd0fb76c08 feat: add email_send orchestrator tool
Wraps the existing email_utils.send_email helper as an admin-only tool.
Accepts to, subject, body (plain text); newlines converted to <br> for HTML part.
Registered in _CALLABLES, _ALL_DECLARATIONS, and TOOL_ROLES (admin).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-29 21:35:29 -04:00

45 lines
1.4 KiB
Python

"""
Notification tools — proactively send messages to user channels.
nc_talk_send routes through notification.py → channels.json.
email_send uses the server SMTP config from .env (smtp_server, smtp_from_*).
"""
import asyncio
import logging
from persona import get_user
logger = logging.getLogger(__name__)
async def email_send(to: str, subject: str, body: str) -> str:
"""Send an email via the server's configured SMTP account."""
from email_utils import send_email
ok = await asyncio.to_thread(
send_email,
to_email=to,
subject=subject,
body_text=body,
body_html=body.replace("\n", "<br>"),
)
if ok:
return f"Email sent to {to}."
return "Failed to send email — check SMTP configuration in .env."
async def nc_talk_send(message: str) -> str:
"""Send a message to the user via their configured notification channel.
Channel is resolved from the user's channels.json (notification_channel key).
Falls back to Nextcloud Talk if configured. No-op if no channel is set.
"""
from notification import notify
username = get_user()
try:
await notify(username, message)
return f"Message sent to {username}'s notification channel."
except Exception as e:
logger.warning("nc_talk_send error for %s: %s", username, e)
return f"Failed to send notification: {e}"