telert 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
telert-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 navig.me
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include LICENSE README.md
2
+ recursive-include telert *
3
+ prune packaging
telert-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: telert
3
+ Version: 0.1.1
4
+ Summary: CLI Telegram notifier: run commands or use as pipeline
5
+ Author-email: Mihir Khandekar <mihirkhandekar@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/navig-me/telert
8
+ Project-URL: Bug Tracker, https://github.com/navig-me/telert/issues
9
+ Keywords: telegram,notification,cli,terminal,alert
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Communications
21
+ Classifier: Topic :: System :: Monitoring
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: requests>=2.25
27
+ Provides-Extra: dev
28
+ Requires-Dist: build; extra == "dev"
29
+ Requires-Dist: twine; extra == "dev"
30
+ Requires-Dist: pytest; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+
34
+ # telert – Telegram Alerts for Your Terminal
35
+
36
+ **Version 0.1.1**
37
+
38
+ Telert is a tiny command‑line utility that shoots you a Telegram message the moment a command (or an entire shell pipeline) finishes.
39
+ It preserves **exit status**, captures **run‑time**, and can optionally include the first lines of _stdout_ / _stderr_.
40
+
41
+ [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/mihirk)
42
+
43
+ ---
44
+
45
+ ## ✨ Features
46
+
47
+ | Mode | What it does | Example |
48
+ |----------------|--------------|---------|
49
+ | **Run** | Wraps a command, times it, sends notification with exit code. | `telert run --label "RSYNC" -- rsync -a /src /dst` |
50
+ | **Filter** | Reads from stdin so you can _pipe_ output. | `long_job | telert "compile done"` |
51
+ | **Hook** | Generates a Bash snippet so **every** command > *N* seconds notifies automatically. | `eval "$(telert hook -l 30)"` |
52
+ | **Send** | Low‑level "send arbitrary text to myself" helper. | `telert send "server rebooted"` |
53
+
54
+ ---
55
+
56
+ ## 🚀 Quick install
57
+
58
+ ```bash
59
+ # Any OS (PyPI)
60
+ pip install telert
61
+
62
+ # Fedora / RHEL / Alma / Rocky
63
+ sudo dnf install telert # yum works too
64
+
65
+ # Debian / Ubuntu / Linux Mint
66
+ sudo apt install telert
67
+ ```
68
+
69
+ RPM/DEB repositories are published by GitHub Actions on every release tag.
70
+ If you prefer, you can also grab the single‑file wheel from Releases.
71
+
72
+ ---
73
+
74
+ ## 🤖 Bot set‑up (one‑time)
75
+
76
+ 1. Chat with **@BotFather → /newbot →** copy the *API token*.
77
+ 2. Send any throwaway message to the new bot **from the account/channel you want alerts in**.
78
+ 3. Fetch the chat‑ID:
79
+ ```bash
80
+ curl -s "https://api.telegram.org/bot<token>/getUpdates" | jq .
81
+ ```
82
+ Copy the integer in `result[0].message.chat.id` (for channels it starts with `-100`).
83
+ 4. Configure Telert:
84
+ ```bash
85
+ telert config --token <token> --chat-id <chat_id>
86
+ telert status # sends a ✅ test message
87
+ ```
88
+
89
+ Telert stores creds in `~/.config/telert/config.json`.
90
+
91
+ ---
92
+
93
+ ## 🛠 Usage
94
+
95
+ ### Run mode (recommended)
96
+ ```bash
97
+ # Notify regardless of outcome
98
+ $ telert run --label " nightly backup " -- rsync -a /src /dst
99
+ # custom message & only if the command fails
100
+ telert run --only-fail -m "backup failed" -- rsync -a /src /dst
101
+ ```
102
+
103
+ ### Filter mode (legacy piping)
104
+ ```bash
105
+ make big‑pdf | telert "LaTeX finished"
106
+ ```
107
+ > ⚠️ Exit status is **unknown** here – a shell can’t pass `$?` inside a pipe.
108
+ > If you need exit status, stick to **run** mode or explicit `; telert send "failed $?"`.
109
+
110
+ ### Shell hook
111
+ ```bash
112
+ echo 'eval "$(telert hook -l 20)"' >> ~/.bashrc # any cmd >20 s notifies
113
+ ```
114
+
115
+ ### Help
116
+ ```bash
117
+ telert --help # global help
118
+ telert run --help # sub‑command help
119
+ telert help # alias to the same
120
+ ```
121
+
122
+ ---
123
+
124
+ ## 🌿 Environment variables
125
+
126
+ | Variable | Effect |
127
+ |---------------------|---------------------------------------------|
128
+ | `TELERT_LONG` | Default threshold (seconds) for `hook`. |
129
+ | `TELERT_SILENT=1` | Suppress stdout/stderr echo in `run`. |
130
+
131
+ ---
132
+
133
+ ## 👩‍💻 Development
134
+ ```bash
135
+ git clone https://github.com/navig-me/telert
136
+ cd telert
137
+ python -m pip install -e .[dev]
138
+ ```
139
+
140
+ ### Releasing to PyPI
141
+
142
+ The project is automatically published to PyPI when a new GitHub release is created:
143
+
144
+ 1. Update version in both `pyproject.toml` and `telert/__init__.py`
145
+ 2. Commit the changes and push to main
146
+ 3. Create a new GitHub release with a tag like `v0.1.1`
147
+ 4. The GitHub Actions workflow will automatically build and publish to PyPI
148
+
149
+ To manually publish to PyPI if needed:
150
+
151
+ ```bash
152
+ # Install build tools
153
+ pip install build twine
154
+
155
+ # Build the package
156
+ python -m build
157
+
158
+ # Upload to PyPI
159
+ twine upload dist/*
160
+ ```
161
+
162
+ ---
163
+
164
+ ## 🤝 Contributing / License
165
+
166
+ PRs & issues welcome!
167
+ Licensed under the MIT License – see `LICENSE`.
telert-0.1.1/README.md ADDED
@@ -0,0 +1,135 @@
1
+
2
+ # telert – Telegram Alerts for Your Terminal
3
+
4
+ **Version 0.1.1**
5
+
6
+ Telert is a tiny command‑line utility that shoots you a Telegram message the moment a command (or an entire shell pipeline) finishes.
7
+ It preserves **exit status**, captures **run‑time**, and can optionally include the first lines of _stdout_ / _stderr_.
8
+
9
+ [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/mihirk)
10
+
11
+ ---
12
+
13
+ ## ✨ Features
14
+
15
+ | Mode | What it does | Example |
16
+ |----------------|--------------|---------|
17
+ | **Run** | Wraps a command, times it, sends notification with exit code. | `telert run --label "RSYNC" -- rsync -a /src /dst` |
18
+ | **Filter** | Reads from stdin so you can _pipe_ output. | `long_job | telert "compile done"` |
19
+ | **Hook** | Generates a Bash snippet so **every** command > *N* seconds notifies automatically. | `eval "$(telert hook -l 30)"` |
20
+ | **Send** | Low‑level "send arbitrary text to myself" helper. | `telert send "server rebooted"` |
21
+
22
+ ---
23
+
24
+ ## 🚀 Quick install
25
+
26
+ ```bash
27
+ # Any OS (PyPI)
28
+ pip install telert
29
+
30
+ # Fedora / RHEL / Alma / Rocky
31
+ sudo dnf install telert # yum works too
32
+
33
+ # Debian / Ubuntu / Linux Mint
34
+ sudo apt install telert
35
+ ```
36
+
37
+ RPM/DEB repositories are published by GitHub Actions on every release tag.
38
+ If you prefer, you can also grab the single‑file wheel from Releases.
39
+
40
+ ---
41
+
42
+ ## 🤖 Bot set‑up (one‑time)
43
+
44
+ 1. Chat with **@BotFather → /newbot →** copy the *API token*.
45
+ 2. Send any throwaway message to the new bot **from the account/channel you want alerts in**.
46
+ 3. Fetch the chat‑ID:
47
+ ```bash
48
+ curl -s "https://api.telegram.org/bot<token>/getUpdates" | jq .
49
+ ```
50
+ Copy the integer in `result[0].message.chat.id` (for channels it starts with `-100`).
51
+ 4. Configure Telert:
52
+ ```bash
53
+ telert config --token <token> --chat-id <chat_id>
54
+ telert status # sends a ✅ test message
55
+ ```
56
+
57
+ Telert stores creds in `~/.config/telert/config.json`.
58
+
59
+ ---
60
+
61
+ ## 🛠 Usage
62
+
63
+ ### Run mode (recommended)
64
+ ```bash
65
+ # Notify regardless of outcome
66
+ $ telert run --label " nightly backup " -- rsync -a /src /dst
67
+ # custom message & only if the command fails
68
+ telert run --only-fail -m "backup failed" -- rsync -a /src /dst
69
+ ```
70
+
71
+ ### Filter mode (legacy piping)
72
+ ```bash
73
+ make big‑pdf | telert "LaTeX finished"
74
+ ```
75
+ > ⚠️ Exit status is **unknown** here – a shell can’t pass `$?` inside a pipe.
76
+ > If you need exit status, stick to **run** mode or explicit `; telert send "failed $?"`.
77
+
78
+ ### Shell hook
79
+ ```bash
80
+ echo 'eval "$(telert hook -l 20)"' >> ~/.bashrc # any cmd >20 s notifies
81
+ ```
82
+
83
+ ### Help
84
+ ```bash
85
+ telert --help # global help
86
+ telert run --help # sub‑command help
87
+ telert help # alias to the same
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 🌿 Environment variables
93
+
94
+ | Variable | Effect |
95
+ |---------------------|---------------------------------------------|
96
+ | `TELERT_LONG` | Default threshold (seconds) for `hook`. |
97
+ | `TELERT_SILENT=1` | Suppress stdout/stderr echo in `run`. |
98
+
99
+ ---
100
+
101
+ ## 👩‍💻 Development
102
+ ```bash
103
+ git clone https://github.com/navig-me/telert
104
+ cd telert
105
+ python -m pip install -e .[dev]
106
+ ```
107
+
108
+ ### Releasing to PyPI
109
+
110
+ The project is automatically published to PyPI when a new GitHub release is created:
111
+
112
+ 1. Update version in both `pyproject.toml` and `telert/__init__.py`
113
+ 2. Commit the changes and push to main
114
+ 3. Create a new GitHub release with a tag like `v0.1.1`
115
+ 4. The GitHub Actions workflow will automatically build and publish to PyPI
116
+
117
+ To manually publish to PyPI if needed:
118
+
119
+ ```bash
120
+ # Install build tools
121
+ pip install build twine
122
+
123
+ # Build the package
124
+ python -m build
125
+
126
+ # Upload to PyPI
127
+ twine upload dist/*
128
+ ```
129
+
130
+ ---
131
+
132
+ ## 🤝 Contributing / License
133
+
134
+ PRs & issues welcome!
135
+ Licensed under the MIT License – see `LICENSE`.
@@ -0,0 +1,47 @@
1
+ [project]
2
+ name = "telert"
3
+ version = "0.1.1"
4
+ description = "CLI Telegram notifier: run commands or use as pipeline"
5
+ authors = [{name = "Mihir Khandekar", email = "mihirkhandekar@gmail.com"}]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ requires-python = ">=3.8"
9
+ dependencies = ["requests>=2.25"]
10
+ keywords = ["telegram", "notification", "cli", "terminal", "alert"]
11
+ classifiers = [
12
+ "Development Status :: 4 - Beta",
13
+ "Environment :: Console",
14
+ "Intended Audience :: Developers",
15
+ "Intended Audience :: System Administrators",
16
+ "Operating System :: OS Independent",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.8",
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Topic :: Communications",
23
+ "Topic :: System :: Monitoring",
24
+ "Topic :: Utilities"
25
+ ]
26
+
27
+ [project.urls]
28
+ "Homepage" = "https://github.com/navig-me/telert"
29
+ "Bug Tracker" = "https://github.com/navig-me/telert/issues"
30
+
31
+ [project.scripts]
32
+ telert = "telert.cli:main"
33
+
34
+ [project.optional-dependencies]
35
+ dev = [
36
+ "build",
37
+ "twine",
38
+ "pytest"
39
+ ]
40
+
41
+ [tool.setuptools]
42
+ packages = ["telert"]
43
+ include-package-data = false
44
+
45
+ [build-system]
46
+ requires = ["setuptools>=61", "wheel"]
47
+ build-backend = "setuptools.build_meta"
telert-0.1.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ __all__ = ["__version__"]
2
+ __version__ = "0.1.1"
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ telert – Send Telegram alerts from shell commands.
4
+ Supports two modes:
5
+ • **run** mode wraps a command, captures exit status & timing.
6
+ • **filter** mode reads stdin so you can pipe long jobs.
7
+
8
+ Run `telert --help` or `telert help` for full usage.
9
+ """
10
+ from __future__ import annotations
11
+ import argparse, json, pathlib, subprocess, sys, textwrap, time, requests, os
12
+
13
+ CFG_DIR = pathlib.Path(os.path.expanduser("~/.config/telert"))
14
+ CFG_FILE = CFG_DIR / "config.json"
15
+
16
+ # ───────────────────────────────── helpers ──────────────────────────────────
17
+
18
+ def _save(token: str, chat_id: str):
19
+ CFG_DIR.mkdir(parents=True, exist_ok=True)
20
+ CFG_FILE.write_text(json.dumps({"token": token.strip(), "chat_id": str(chat_id).strip()}))
21
+ print("✔ Configuration saved →", CFG_FILE)
22
+
23
+
24
+ def _load():
25
+ if not CFG_FILE.exists():
26
+ sys.exit("❌ telert is unconfigured – run `telert config …` first.")
27
+ return json.loads(CFG_FILE.read_text())
28
+
29
+
30
+ def _send(msg: str):
31
+ cfg = _load()
32
+ url = f"https://api.telegram.org/bot{cfg['token']}/sendMessage"
33
+ r = requests.post(url, json={"chat_id": cfg["chat_id"], "text": msg})
34
+ if r.status_code != 200:
35
+ sys.exit(f"❌ Telegram API error {r.status_code}: {r.text}")
36
+
37
+
38
+ def _human(sec: float) -> str:
39
+ m, s = divmod(int(sec), 60)
40
+ return f"{m} m {s} s" if m else f"{s} s"
41
+
42
+ # ────────────────────────────── sub‑commands ───────────────────────────────
43
+
44
+ def do_config(a):
45
+ _save(a.token, a.chat_id)
46
+
47
+ def do_status(_):
48
+ cfg = _load()
49
+ print("token :", cfg['token'][:8] + "…")
50
+ print("chat :", cfg['chat_id'])
51
+ _send("✅ telert status OK")
52
+ print("sent : test message")
53
+
54
+
55
+ def do_hook(a):
56
+ t = a.longer_than
57
+ print(textwrap.dedent(f"""
58
+ telert_preexec() {{ TELERT_CMD=\"$BASH_COMMAND\"; TELERT_START=$EPOCHSECONDS; }}
59
+ telert_precmd() {{ local st=$?; local d=$((EPOCHSECONDS-TELERT_START));
60
+ if (( d >= {t} )); then telert send \"$TELERT_CMD exited $st in $(printf '%dm%02ds' $((d/60)) $((d%60)))\"; fi; }}
61
+ trap telert_preexec DEBUG
62
+ PROMPT_COMMAND=telert_precmd:$PROMPT_COMMAND
63
+ """).strip())
64
+
65
+
66
+ def do_send(a):
67
+ _send(a.text)
68
+
69
+
70
+ def do_run(a):
71
+ start = time.time()
72
+ proc = subprocess.run(a.cmd, text=True, capture_output=True)
73
+ dur = _human(time.time() - start)
74
+ status = proc.returncode
75
+ label = a.label or " ".join(a.cmd)
76
+ if a.only_fail and status == 0:
77
+ sys.stdout.write(proc.stdout)
78
+ sys.stderr.write(proc.stderr)
79
+ sys.exit(status)
80
+
81
+ msg = a.message or f"{label} finished with exit {status} in {dur}"
82
+ if proc.stdout.strip():
83
+ msg += "
84
+
85
+ --- stdout ---
86
+ " + "
87
+ ".join(proc.stdout.splitlines()[:20])[:3900]
88
+ if proc.stderr.strip():
89
+ msg += "
90
+
91
+ --- stderr ---
92
+ " + "
93
+ ".join(proc.stderr.splitlines()[:20])[:3900]
94
+ _send(msg)
95
+
96
+ sys.stdout.write(proc.stdout)
97
+ sys.stderr.write(proc.stderr)
98
+ sys.exit(status)
99
+
100
+ # ───────────────────────────── pipeline filter ─────────────────────────────
101
+
102
+ def piped_mode():
103
+ data = sys.stdin.read()
104
+ msg = sys.argv[1] if len(sys.argv) > 1 else "Pipeline finished"
105
+ if len(sys.argv) > 2:
106
+ msg += f" (exit {sys.argv[2]})"
107
+ if data.strip():
108
+ msg += "
109
+
110
+ --- output ---
111
+ " + "
112
+ ".join(data.splitlines()[:20])[:3900]
113
+ _send(msg)
114
+
115
+ # ──────────────────────────────── entrypoint ───────────────────────────────
116
+
117
+ def main():
118
+ if not sys.stdin.isatty():
119
+ piped_mode()
120
+ return
121
+
122
+ p = argparse.ArgumentParser(
123
+ prog="telert",
124
+ description="Send Telegram alerts when commands finish (supports exit status).",
125
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
126
+ )
127
+ sp = p.add_subparsers(dest="cmd", required=True)
128
+
129
+ # config
130
+ c = sp.add_parser("config", help="store bot token & chat‑id")
131
+ c.add_argument("--token", required=True)
132
+ c.add_argument("--chat-id", required=True)
133
+ c.set_defaults(func=do_config)
134
+
135
+ # status
136
+ st = sp.add_parser("status", help="send test message & show config")
137
+ st.set_defaults(func=do_status)
138
+
139
+ # hook
140
+ hk = sp.add_parser("hook", help="emit Bash hook for all commands")
141
+ hk.add_argument("--longer-than", "-l", type=int, default=10)
142
+ hk.set_defaults(func=do_hook)
143
+
144
+ # send
145
+ sd = sp.add_parser("send", help="send arbitrary text")
146
+ sd.add_argument("text")
147
+ sd.set_defaults(func=do_send)
148
+
149
+ # run
150
+ rn = sp.add_parser("run", help="run a command & notify when done")
151
+ rn.add_argument("--label", "-L", help="friendly name")
152
+ rn.add_argument("--message", "-m", help="override default text")
153
+ rn.add_argument("--only-fail", action="store_true", help="notify only on non‑zero exit")
154
+ rn.add_argument("cmd", nargs=argparse.REMAINDER, help="command to execute -- required")
155
+ rn.set_defaults(func=do_run)
156
+
157
+ # help alias
158
+ hp = sp.add_parser("help", help="show global help")
159
+ hp.set_defaults(func=lambda _a: p.print_help())
160
+
161
+ args = p.parse_args()
162
+ if getattr(args, "cmd", None) == [] and getattr(args, "func", None) is do_run:
163
+ p.error("run: missing command – use telert run -- <cmd> …")
164
+ args.func(args)
165
+
166
+ if __name__ == "__main__":
167
+ main()
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: telert
3
+ Version: 0.1.1
4
+ Summary: CLI Telegram notifier: run commands or use as pipeline
5
+ Author-email: Mihir Khandekar <mihirkhandekar@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/navig-me/telert
8
+ Project-URL: Bug Tracker, https://github.com/navig-me/telert/issues
9
+ Keywords: telegram,notification,cli,terminal,alert
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Communications
21
+ Classifier: Topic :: System :: Monitoring
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: requests>=2.25
27
+ Provides-Extra: dev
28
+ Requires-Dist: build; extra == "dev"
29
+ Requires-Dist: twine; extra == "dev"
30
+ Requires-Dist: pytest; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+
34
+ # telert – Telegram Alerts for Your Terminal
35
+
36
+ **Version 0.1.1**
37
+
38
+ Telert is a tiny command‑line utility that shoots you a Telegram message the moment a command (or an entire shell pipeline) finishes.
39
+ It preserves **exit status**, captures **run‑time**, and can optionally include the first lines of _stdout_ / _stderr_.
40
+
41
+ [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/mihirk)
42
+
43
+ ---
44
+
45
+ ## ✨ Features
46
+
47
+ | Mode | What it does | Example |
48
+ |----------------|--------------|---------|
49
+ | **Run** | Wraps a command, times it, sends notification with exit code. | `telert run --label "RSYNC" -- rsync -a /src /dst` |
50
+ | **Filter** | Reads from stdin so you can _pipe_ output. | `long_job | telert "compile done"` |
51
+ | **Hook** | Generates a Bash snippet so **every** command > *N* seconds notifies automatically. | `eval "$(telert hook -l 30)"` |
52
+ | **Send** | Low‑level "send arbitrary text to myself" helper. | `telert send "server rebooted"` |
53
+
54
+ ---
55
+
56
+ ## 🚀 Quick install
57
+
58
+ ```bash
59
+ # Any OS (PyPI)
60
+ pip install telert
61
+
62
+ # Fedora / RHEL / Alma / Rocky
63
+ sudo dnf install telert # yum works too
64
+
65
+ # Debian / Ubuntu / Linux Mint
66
+ sudo apt install telert
67
+ ```
68
+
69
+ RPM/DEB repositories are published by GitHub Actions on every release tag.
70
+ If you prefer, you can also grab the single‑file wheel from Releases.
71
+
72
+ ---
73
+
74
+ ## 🤖 Bot set‑up (one‑time)
75
+
76
+ 1. Chat with **@BotFather → /newbot →** copy the *API token*.
77
+ 2. Send any throwaway message to the new bot **from the account/channel you want alerts in**.
78
+ 3. Fetch the chat‑ID:
79
+ ```bash
80
+ curl -s "https://api.telegram.org/bot<token>/getUpdates" | jq .
81
+ ```
82
+ Copy the integer in `result[0].message.chat.id` (for channels it starts with `-100`).
83
+ 4. Configure Telert:
84
+ ```bash
85
+ telert config --token <token> --chat-id <chat_id>
86
+ telert status # sends a ✅ test message
87
+ ```
88
+
89
+ Telert stores creds in `~/.config/telert/config.json`.
90
+
91
+ ---
92
+
93
+ ## 🛠 Usage
94
+
95
+ ### Run mode (recommended)
96
+ ```bash
97
+ # Notify regardless of outcome
98
+ $ telert run --label " nightly backup " -- rsync -a /src /dst
99
+ # custom message & only if the command fails
100
+ telert run --only-fail -m "backup failed" -- rsync -a /src /dst
101
+ ```
102
+
103
+ ### Filter mode (legacy piping)
104
+ ```bash
105
+ make big‑pdf | telert "LaTeX finished"
106
+ ```
107
+ > ⚠️ Exit status is **unknown** here – a shell can’t pass `$?` inside a pipe.
108
+ > If you need exit status, stick to **run** mode or explicit `; telert send "failed $?"`.
109
+
110
+ ### Shell hook
111
+ ```bash
112
+ echo 'eval "$(telert hook -l 20)"' >> ~/.bashrc # any cmd >20 s notifies
113
+ ```
114
+
115
+ ### Help
116
+ ```bash
117
+ telert --help # global help
118
+ telert run --help # sub‑command help
119
+ telert help # alias to the same
120
+ ```
121
+
122
+ ---
123
+
124
+ ## 🌿 Environment variables
125
+
126
+ | Variable | Effect |
127
+ |---------------------|---------------------------------------------|
128
+ | `TELERT_LONG` | Default threshold (seconds) for `hook`. |
129
+ | `TELERT_SILENT=1` | Suppress stdout/stderr echo in `run`. |
130
+
131
+ ---
132
+
133
+ ## 👩‍💻 Development
134
+ ```bash
135
+ git clone https://github.com/navig-me/telert
136
+ cd telert
137
+ python -m pip install -e .[dev]
138
+ ```
139
+
140
+ ### Releasing to PyPI
141
+
142
+ The project is automatically published to PyPI when a new GitHub release is created:
143
+
144
+ 1. Update version in both `pyproject.toml` and `telert/__init__.py`
145
+ 2. Commit the changes and push to main
146
+ 3. Create a new GitHub release with a tag like `v0.1.1`
147
+ 4. The GitHub Actions workflow will automatically build and publish to PyPI
148
+
149
+ To manually publish to PyPI if needed:
150
+
151
+ ```bash
152
+ # Install build tools
153
+ pip install build twine
154
+
155
+ # Build the package
156
+ python -m build
157
+
158
+ # Upload to PyPI
159
+ twine upload dist/*
160
+ ```
161
+
162
+ ---
163
+
164
+ ## 🤝 Contributing / License
165
+
166
+ PRs & issues welcome!
167
+ Licensed under the MIT License – see `LICENSE`.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ telert/__init__.py
6
+ telert/cli.py
7
+ telert.egg-info/PKG-INFO
8
+ telert.egg-info/SOURCES.txt
9
+ telert.egg-info/dependency_links.txt
10
+ telert.egg-info/entry_points.txt
11
+ telert.egg-info/requires.txt
12
+ telert.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ telert = telert.cli:main
@@ -0,0 +1,6 @@
1
+ requests>=2.25
2
+
3
+ [dev]
4
+ build
5
+ twine
6
+ pytest
@@ -0,0 +1 @@
1
+ telert