Skip to main content

A tool using the Telegram Bot API for sending messages to a Telegram chat by a context manager, function call, or CLI.

Project description

py-telegram-notifier

PyPI Downloads

A tool using the Telegram Bot API for sending messages to a Telegram chat by a context manager, function call, or CLI.

Purpose

The purpose of this module is to provide a simple way to send messages to a Telegram chat using the Telegram Bot API. This is especially useful for long-running automation scripts, where the user may not be around to check the logs.

This is not a wrapper for the Telegram Bot API, but rather a utility for notifying users of enter/exit events with a context manager.

Installation

pip install py-telegram-notifier

Requirements

In order for the module to function, you must supply it with a bot token and a chat id. Full instructions on creating a bot can be found here.

Usage

Firstly, set up the config for your Notifier. Bot token and chat id are required and must be set as environment variables (TELEGRAM_TOKEN and TELEGRAM_CHAT_ID, respectively). It's strongly recommended to use a git-ignored .env file for this purpose, an example file can be found here.

As a context manager

import dotenv
from telegram_notifier import Notifier

# Load environment variables
dotenv.load_dotenv()

with Notifier("Test case") as notifier:
    # Enter message fired
    notifier.send_message("This is a progress update")
# Exit message fired

As a function call

import dotenv
from telegram_notifier import Notifier

# Load environment variables
dotenv.load_dotenv()

notifier = Notifier()
notifier.send_message("Test message")
# Does not need to be used as a context manager

As a CLI

TELEGRAM_TOKEN=0000000000 TELEGRAM_CHAT_ID=0000000000 python -m telegram_notifier "Test message"

Notes

This module treats all messages as MarkdownV2 by default, and escapes known reserved characters. See Notifier.send_message() for more information.

Disclaimer

The author of this software is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Telegram or any of its affiliates and is independently owned and created.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_telegram_notifier-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file py_telegram_notifier-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_telegram_notifier-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43e0f444f406967e4b4e985d7ce573e06d9c612943b4f1aec1e28eb33c7e298a
MD5 50e9fdf2cbf556478897e108f3689bae
BLAKE2b-256 8c7207e634a1f692711e8dc3665fd3089ae3c6964bc75762cb14bcf22c90471e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page