py-telegram-notifier


Namepy-telegram-notifier JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/jon-edward/py-telegram-notifier
SummaryA tool using the Telegram Bot API for sending messages to a Telegram chat by a context manager, function call, or CLI.
upload_time2024-12-18 03:01:59
maintainerNone
docs_urlNone
authorJonathan Townsend
requires_python>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements requests
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # py-telegram-notifier

[![PyPI Downloads](https://static.pepy.tech/badge/py-telegram-notifier)](https://pepy.tech/projects/py-telegram-notifier)

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](https://core.telegram.org/bots/api#authorizing-your-bot) and a
[chat id](https://core.telegram.org/bots/api#getupdates). Full instructions on creating a bot
can be found [here](https://core.telegram.org/bots#3-how-do-i-create-a-bot).

## 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](https://github.com/jon-edward/py-telegram-notifier/blob/main/.env.example).

### As a context manager

```python
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

```python
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

```bash
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()`](https://github.com/jon-edward/py-telegram-notifier/blob/main/telegram_notifier/notifier.py) 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jon-edward/py-telegram-notifier",
    "name": "py-telegram-notifier",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jonathan Townsend",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# py-telegram-notifier\n\n[![PyPI Downloads](https://static.pepy.tech/badge/py-telegram-notifier)](https://pepy.tech/projects/py-telegram-notifier)\n\nA tool using the Telegram Bot API for sending messages to a Telegram chat by\na context manager, function call, or CLI.\n\n## Purpose\n\nThe purpose of this module is to provide a simple way to send messages to a Telegram chat using the Telegram Bot API. \nThis is especially useful for long-running automation scripts, where the user may not be around to check the logs. \n\nThis is not a wrapper for the Telegram Bot API, but rather a utility for notifying users of enter/exit events with a \ncontext manager.\n\n## Installation\n\n    pip install py-telegram-notifier\n\n## Requirements\n\nIn order for the module to function, you must supply it with a bot\n[token](https://core.telegram.org/bots/api#authorizing-your-bot) and a\n[chat id](https://core.telegram.org/bots/api#getupdates). Full instructions on creating a bot\ncan be found [here](https://core.telegram.org/bots#3-how-do-i-create-a-bot).\n\n## Usage \n\nFirstly, set up the config for your Notifier. Bot token and chat id are required and must be set as environment \nvariables (`TELEGRAM_TOKEN` and `TELEGRAM_CHAT_ID`, respectively). It's strongly recommended to use a git-ignored `.env` \nfile for this purpose, an example file can be found [here](https://github.com/jon-edward/py-telegram-notifier/blob/main/.env.example).\n\n### As a context manager\n\n```python\nimport dotenv\nfrom telegram_notifier import Notifier\n\n# Load environment variables\ndotenv.load_dotenv()\n\nwith Notifier(\"Test case\") as notifier:\n    # Enter message fired\n    notifier.send_message(\"This is a progress update\")\n# Exit message fired\n```\n\n### As a function call\n\n```python\nimport dotenv\nfrom telegram_notifier import Notifier\n\n# Load environment variables\ndotenv.load_dotenv()\n\nnotifier = Notifier()\nnotifier.send_message(\"Test message\")\n# Does not need to be used as a context manager\n```\n\n### As a CLI\n\n```bash\nTELEGRAM_TOKEN=0000000000 TELEGRAM_CHAT_ID=0000000000 python -m telegram_notifier \"Test message\"\n```\n\n## Notes\n\nThis module treats all messages as `MarkdownV2` by default, and escapes known reserved characters. See [`Notifier.send_message()`](https://github.com/jon-edward/py-telegram-notifier/blob/main/telegram_notifier/notifier.py) for more information.\n\n\n## Disclaimer\n\nThe author of this software is not affiliated, associated, authorized, endorsed by, or in any\nway officially connected with Telegram or any of its affiliates and is independently owned and\ncreated.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A tool using the Telegram Bot API for sending messages to a Telegram chat by a context manager, function call, or CLI.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/jon-edward/py-telegram-notifier"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8c7207e634a1f692711e8dc3665fd3089ae3c6964bc75762cb14bcf22c90471e",
                "md5": "50e9fdf2cbf556478897e108f3689bae",
                "sha256": "43e0f444f406967e4b4e985d7ce573e06d9c612943b4f1aec1e28eb33c7e298a"
            },
            "downloads": -1,
            "filename": "py_telegram_notifier-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "50e9fdf2cbf556478897e108f3689bae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 5784,
            "upload_time": "2024-12-18T03:01:59",
            "upload_time_iso_8601": "2024-12-18T03:01:59.420036Z",
            "url": "https://files.pythonhosted.org/packages/8c/72/07e634a1f692711e8dc3665fd3089ae3c6964bc75762cb14bcf22c90471e/py_telegram_notifier-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 03:01:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jon-edward",
    "github_project": "py-telegram-notifier",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.32.0"
                ]
            ]
        }
    ],
    "lcname": "py-telegram-notifier"
}
        
Elapsed time: 0.98101s