Telegram v2: proactive push notifications (cron completions) - #11
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
agent.result_generatedon 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 theprocessed_eventstable.tasksrow — it lives in the originatingtask.createdpayload (userId:"cron"), read from theeventstable by taskId. No schema migration. Telegram- and app-originated tasks are skipped naturally.tasks.resultMeta(short retry, since the event fires just before the DB flip), falling back to the eventpreview; the cron name is matched best-effort fromcron_jobsby prompt + agent. Sent through the existing HTML code-frame formatter.Config & UI
telegram_configgainsnotifications.cron(default true);GET/POST /system/integrations/telegramread/write it.@hydraops/{nats,events}+nats; the subscriber runs alongside the long-poll and only sends when enabled + token + toggle on + non-empty allowlist.TelegramIntegration.notificationstype, and i18n in all 5 locales.Verified live (end-to-end)
Out of scope (follow-ups): failure notifications (would need a new
task.failedevent in the 4 workers), app-task notifications, attachments/voice, single-owner target.