Skip to content

Telegram v2: proactive push notifications (cron completions) - #11

Merged
TraX22 merged 1 commit into
mainfrom
feature/telegram-push-notifications
Aug 21, 2026
Merged

Telegram v2: proactive push notifications (cron completions)#11
TraX22 merged 1 commit into
mainfrom
feature/telegram-push-notifications

Conversation

@TraX22

@TraX22 TraX22 commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Telegram v2: proactive push notifications (cron completions)

The Telegram bot was reactive (you message it → it replies). This makes it proactive: when a scheduled task (cron) finishes, the bot pushes the result to your phone — closing the "HydraOps 24/7 on a home box pings me" loop.

Scope (per product decision): cron completions only, broadcast to the allowlist. Failures and app-launched tasks are out of scope for now.

How it works

  • Every worker already publishes agent.result_generated on success (previously unconsumed). The bot is now the first consumer: a pull-subscribe durable (telegram_bot_result_generated, explicit ack) mirroring the orchestrator, deduped via the processed_events table.
  • Cron origin isn't on the event or the tasks row — it lives in the originating task.created payload (userId:"cron"), read from the events table by taskId. No schema migration. Telegram- and app-originated tasks are skipped naturally.
  • Result text comes from tasks.resultMeta (short retry, since the event fires just before the DB flip), falling back to the event preview; the cron name is matched best-effort from cron_jobs by prompt + agent. Sent through the existing HTML code-frame formatter.

Config & UI

  • telegram_config gains notifications.cron (default true); GET/POST /system/integrations/telegram read/write it.
  • New bot deps @hydraops/{nats,events} + nats; the subscriber runs alongside the long-poll and only sends when enabled + token + toggle on + non-empty allowlist.
  • A "notify on scheduled task" toggle in the Herramientas → Telegram card, TelegramIntegration.notifications type, and i18n in all 5 locales.

Verified live (end-to-end)

  • Cron-origin task → notifies the allowlist once (deduped, confirmed in the log + on the phone).
  • Non-cron (app/system) task → does not notify.
  • Toggle OFF → silenced.
  • UI toggle renders correctly (screenshot-verified).

Out of scope (follow-ups): failure notifications (would need a new task.failed event in the 4 workers), app-task notifications, attachments/voice, single-owner target.

The bot now subscribes to the agent.result_generated NATS event (published by
every worker on success, previously unconsumed) and, for tasks that originated
from a cron, pushes the result to every allowlisted Telegram chat — closing the
'HydraOps 24/7 on a home box pings my phone' loop.

- New apps/telegram-bot/src/notifications.ts: a pull-subscribe consumer
  (durable telegram_bot_result_generated, explicit ack) mirroring the
  orchestrator, deduped via the processed_events table. Cron origin isn't on the
  event or the tasks row, so it's read from the originating task.created payload
  (userId:'cron') in the events table — no schema migration. Telegram- and
  app-originated tasks are skipped naturally. Full result text is read from
  tasks.resultMeta (short retry, since the event fires just before the DB flip),
  falling back to the event preview; the cron name is matched best-effort from
  cron_jobs by prompt + agent. Sends via the existing HTML formatter.
- Config: telegram_config gains notifications.cron (default true); GET/POST
  /system/integrations/telegram read/write it. New deps @hydraops/{nats,events}
  + nats on the bot; the subscriber runs alongside the long-poll and only sends
  when enabled + token + toggle on + a non-empty allowlist.
- UI: a 'notify on scheduled task' toggle in the Herramientas Telegram card,
  TelegramIntegration.notifications type, and i18n in all 5 locales.

Verified live end-to-end: a cron-origin task notifies the allowlist once
(deduped); a non-cron task does not; the toggle silences it.
@TraX22
TraX22 merged commit 103f0a8 into main Aug 21, 2026
3 checks passed
@TraX22
TraX22 deleted the feature/telegram-push-notifications branch August 21, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant