Package: cli2telegram
cli2telegramSmall utility to send Telegram messages from the CLI.This can f.ex. be used toquickly send arbitrary messages to a Telegram chat of your choiceuse it as a replacement for the "mail" program on linuxuse Telegram as a notification backend for the ZFS Event Daemon (zed)FeaturesRead messages from argument or STDIN(Optional) Configuration fileRetry sending messages for a specified amount of timeHandling of long messagesRun as a daemon and echo messages into a linux pipeExamplescli2telegram-h# From argumentscli2telegram"This is a message"cli2telegram"Header""This is a multiline message."# From STDINechoMyMessage|cli2telegramprintf"Header\nThis is a multiline message."|cli2telegram# Config via parametersprintf"Message"|cli2telegram-b"123456789:ABCDEFG"-c"123456789"# Config via parameters and send message in a code blockprintf"Message"|cli2telegram-b"123456789:ABCDEFG"-c"123456789"-C# as a Daemoncli2telegram-d-p"/tmp/cli2telegram"echo"hello world!">/tmp/cli2telegramInstallTo use this utility install it either using:pip install cli2telegramor - if you don't want to install it globally - using f.ex.venv-install:venv-install cli2telegram cli2telegramor your customvenvmanager of choice.ConfigurationTo be able to send you messages you have to provide abot tokenand achat id.
You can configure cli2telegram using cli parameters, a configuration file,
environment variables, or a combination of them.ParametersNameTypeDescription-b,--bot-tokenStringTelegram Bot Token-c,--chat-idStringTelegram Chat ID-C,--code-blockStringSend message inside a code block-d,--daemonFlagRun as a daemon-p,--pipeStringFile path to the pipe used in daemon modeFilecli2telegram usescontainer-app-confso you can use YAML, TOML, or ENV to set those.Have a look at thecli2telegram.toml_examplefile to get an idea.DaemonWhen running cli2telegram as a daemon, the pipe will close for a brief amount of time between receiving input messages.
If you are sending multiple messages to the pipe using f.ex. a script, make sure to wait a bit (f.ex. 0.5 seconds)
between sending messages, otherwise:multiple messages may be received as onemessages may get lostyou may receive aBroken pipeerrorUse CasesZFS Event Daemon (ZED)To makezedcall cli2telegram we will trick it and make it use cli2telegram as an E-Mail client.Edit/etc/zfs/zed.d/zed.rcas root:sudonano-w/etc/zfs/zed.d/zed.rcanduncommentZED_EMAIL_ADDR, the value does not matter since we use our own email script, butit is necessary to set a value to make ZED send 'emails'setZED_EMAIL_PROGto the path of the script, f.ex./usr/bin/cli2telegramit is important to note that zed does not seem to work if your command needs arguments to run# this must not be empty!
ZED_EMAIL_ADDR="root"

[...]

ZED_EMAIL_PROG="/usr/bin/cli2telegram"

[...]

# this must not be empty!
ZED_EMAIL_OPTS="#zfs #$(hostname)"

[...]

# If you want to receive email no matter the state of your pool, you’ll want to set:
ZED_NOTIFY_VERBOSE=1

[...]Sincezedwill run your scripts as root, if you want to use a config file
you have to put it in f.ex./root/.config/cli2telegram.toml.ContributingGitHub is for social coding: if you want to write code, I encourage contributions through pull requests from forks
of this repository. Create GitHub tickets for bugs and new features and comment on the ones that you are interested in.Licensecli2telegram by Markus Ressel
Copyright (C) 2018  Markus Ressel

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.