feat(email): send UI notifications on email receive

linuztx committed Mar 16, 2026 at 10:28 UTC 2b6eb1960025ab8c069137ca4910063da7d2a2d9
1 file changed +25
plugins/_email_integration/helpers/handler.py
+25
@@ -12,6 +12,7 @@ import os
12 from agent import Agent, AgentContext, UserMessage
13 from helpers import guids, plugins, files, runtime
14 from helpers import message_queue as mq
15 +from helpers.notification import NotificationManager, NotificationType, NotificationPriority
16 from helpers.persist_chat import save_tmp_chat
17 from helpers.print_style import PrintStyle
18 from helpers.errors import format_error
@@ -241,6 +242,7 @@ async def _start_new_chat(agent: Agent, handler_cfg: dict, msg: InboundMessage):
242 ))
243
244 PrintStyle.success(f"Email: new chat {context.id} for '{msg.subject}' from {msg.sender}")
245 + _send_notification(msg, "new_chat", context.id)
246
247
248 async def _route_to_chat(
@@ -266,6 +268,7 @@ async def _route_to_chat(
268
269 save_tmp_chat(context)
270 PrintStyle.info(f"Email: continuing chat {context_id}")
271 + _send_notification(msg, "continue_chat", context_id)
272
273
274 # ------------------------------------------------------------------
@@ -404,3 +407,25 @@ def _get_handler_config(handler_name: str) -> dict | None:
407 if h.get("name") == handler_name:
408 return h
409 return None
410 +
411 +
412 +# ------------------------------------------------------------------
413 +# Notifications
414 +# ------------------------------------------------------------------
415 +
416 +def _send_notification(msg: InboundMessage, action: str, context_id: str):
417 + subject = msg.subject[:80] if msg.subject else "(no subject)"
418 + if action == "new_chat":
419 + title = "New email session"
420 + message = f"From {msg.sender}: {subject}"
421 + else:
422 + title = "Email follow-up"
423 + message = f"From {msg.sender}: {subject} → {context_id}"
424 + NotificationManager.send_notification(
425 + type=NotificationType.INFO,
426 + priority=NotificationPriority.HIGH,
427 + title=title,
428 + message=message,
429 + display_time=10,
430 + group="email",
431 + )