Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ project uses [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added

- `daily-report-jalali` example: a daily website check with a Persian Telegram
report, Tehran-local Jalali date and Persian digits.

## [0.1.0] - 2026-10-08

First public release.
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,19 @@ All in [`examples/workflows`](examples/workflows) — run `flowpilot -p examples
| [`github-release-watcher`](examples/workflows/github-release-watcher.yaml) | cron | Announces each new GitHub release exactly once (persistent state) |
| [`uptime-monitor`](examples/workflows/uptime-monitor.yaml) | interval | Alerts only when a site goes **down** or **recovers** |
| [`crypto-digest`](examples/workflows/crypto-digest.yaml) | cron 09:00 Asia/Tehran | Crypto prices (CoinGecko) + USD exchange rates, with the Jalali date |
| [`daily-report-jalali`](examples/workflows/daily-report-jalali.yaml) | cron 09:00 Asia/Tehran | Website HTTP check → Persian Telegram report with the Jalali date |
| [`rss-to-telegram`](examples/workflows/rss-to-telegram.yaml) | feed | One channel post per new feed entry, cleaned by a custom plugin step |
| [`nightly-backup`](examples/workflows/nightly-backup.yaml) | cron | `tar.gz` backup with 7-day retention, uploaded to Telegram, alert on failure |
| [`contact-form`](examples/workflows/contact-form.yaml) | webhook + secret | Website contact form → Telegram |
| [`disk_space.py`](examples/workflows/disk_space.py) | cron | A workflow **written in Python** with its own custom step |

To try `daily-report-jalali`, copy `examples/.env.example` to `examples/.env` and set
`TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID`. Edit `vars.url` in the workflow to
choose the website, then run `flowpilot -p examples run daily-report-jalali`.
Use `flowpilot -p examples serve` to enable its daily 09:00 `Asia/Tehran` schedule.
The report includes HTTP errors such as 503; network failures or timeouts fail
the run. The Jalali date uses Tehran time and Persian digits.

## 🏗 Architecture

```mermaid
Expand Down
34 changes: 34 additions & 0 deletions examples/workflows/daily-report-jalali.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: daily-report-jalali
description: Check a website daily and send a Persian report with the Jalali date to Telegram.
tags: [monitoring, telegram, jalali]
trigger:
type: cron
cron: "0 9 * * *"
timezone: Asia/Tehran

vars:
url: https://example.com

steps:
- id: check
type: http
with:
url: "{{ vars.url }}"
timeout: 15
fail_on_error: false

- id: report
type: transform
with:
template: |
<b>گزارش روزانه وضعیت وب‌سایت</b>
تاریخ: {{ now('Asia/Tehran') | jalali('%d %B %Y', true) }}
نشانی: {{ vars.url | e }}
وضعیت: {{ 'در دسترس' if steps.check.output.ok else 'خطای HTTP' }}
کد HTTP: {{ steps.check.output.status | fa_digits }}
زمان پاسخ: {{ steps.check.output.elapsed_ms | fa_digits }} میلی‌ثانیه

- id: send
type: telegram
with:
text: "{{ steps.report.output }}"
63 changes: 63 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Run the Jalali report example with a fixed clock and mocked HTTP/Telegram APIs."""

from __future__ import annotations

import json
from datetime import datetime
from pathlib import Path
from zoneinfo import ZoneInfo

import httpx
import pytest
import respx

from flowpilot.loader import load_yaml_file
from flowpilot.templating import ENV

EXAMPLE = Path(__file__).resolve().parent.parent / "examples/workflows/daily-report-jalali.yaml"


@pytest.mark.parametrize(
("status", "expected_status", "expected_code"),
[(200, "در دسترس", "۲۰۰"), (503, "خطای HTTP", "۵۰۳")],
)
@respx.mock
async def test_daily_report_jalali(engine, monkeypatch, status, expected_status, expected_code):
monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "TEST_TOKEN")
monkeypatch.setenv("TELEGRAM_CHAT_ID", "42")
engine.settings.telegram_api_base = "https://telegram.test"
clock_zones = []

def fixed_now(tz):
clock_zones.append(tz)
return datetime(2026, 3, 21, 9, tzinfo=ZoneInfo(tz))

monkeypatch.setitem(ENV.globals, "now", fixed_now)
wf = load_yaml_file(EXAMPLE, engine.registry)
assert wf.trigger.type == "cron"
assert wf.trigger.cron == "0 9 * * *"
assert wf.trigger.timezone == "Asia/Tehran"
wf.vars["url"] = "https://example.com/?a=1&b=2"
engine.workflows[wf.name] = wf
check = respx.get(wf.vars["url"]).mock(return_value=httpx.Response(status))
telegram = respx.post("https://telegram.test/botTEST_TOKEN/sendMessage").mock(
return_value=httpx.Response(200, json={"ok": True, "result": {"message_id": 7}})
)

result = await engine.run(wf.name)

assert result.status == "success"
assert check.call_count == telegram.call_count == 1
assert clock_zones == ["Asia/Tehran"]
message = json.loads(telegram.calls[0].request.content)
assert message["chat_id"] == "42"
assert message["parse_mode"] == "HTML"
assert "۰۱ فروردین ۱۴۰۵" in message["text"]
assert expected_status in message["text"]
assert f"کد HTTP: {expected_code}" in message["text"]
assert "https://example.com/?a=1&amp;b=2" in message["text"]
elapsed = str(result.steps["check"]["output"]["elapsed_ms"]).translate(
str.maketrans("0123456789", "۰۱۲۳۴۵۶۷۸۹")
)
assert f"زمان پاسخ: {elapsed} میلی‌ثانیه" in message["text"]
assert result.steps["send"]["output"]["message_ids"] == [7]