Metadata-Version: 2.1
Name: notipi
Version: 1.0.0
Summary: A PyPI package to deliver notifications via your own telegram bot
Author-email: Harshit Sharma <harshit158@gmail.com>
Project-URL: Homepage, https://github.com/harshit158/notipi
Project-URL: Source, https://github.com/harshit158/notipi
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: anyio==4.4.0
Requires-Dist: certifi==2024.6.2
Requires-Dist: enum34==1.1.10
Requires-Dist: h11==0.14.0
Requires-Dist: httpcore==1.0.5
Requires-Dist: httpx==0.27.0
Requires-Dist: idna==3.7
Requires-Dist: python-dotenv==1.0.1
Requires-Dist: python-telegram-bot==21.2
Requires-Dist: sniffio==1.3.1
Requires-Dist: ipython==8.25.0
Requires-Dist: nest-asyncio==1.6.0

![PyPI - Downloads](https://img.shields.io/pypi/dm/notipi) ![PyPI - Version](https://img.shields.io/pypi/v/notipi)

<p align="center">
  <img src="assets/logo.png" alt="Logo" width="600"/>
</p>

## Installation
    $ pip install notipi 

## Setup
In order to use notipi library - you would be needing two environment variables: `BOT_API_TOKEN` and `CHAT_ID`

<u>To get `BOT_API_TOKEN`:</u>

- In the telegram app, initiate conversation with `@BotFather` (you can also click [here](https://t.me/BotFather)).
- Send `/newbot` as the message to `@BotFather` and provide a new name and username for your bot account as per the instructions.
- `@BotFather` will reply with a unique api token - this is your `BOT_API_TOKEN` <br>
(Note: Detailed instructions to create a new bot can be found at [Telegram website](https://core.telegram.org/bots/features#creating-a-new-bot:~:text=and%20managing%20bots.-,Creating%20a%20new%20bot,-Use%20the%20/newbot))

<p align="center">
  <img src="assets/bot_creation_steps.jpeg" alt="Logo" width="600"/>
</p>

<u>To get `CHAT_ID`:</u>
- Once a new bot is created, send a dummy message to the bot via Telegram app so that your chat gets assigned an ID. <br>
- Run the following script with your `BOT_API_TOKEN` to get your `CHAT_ID`
```python
from notipi.notipi import get_chat_id
get_chat_id(BOT_API_TOKEN)
```

This will give the following output:
```
Your CHAT ID: 1234567890
```

Once the `BOT_API_TOKEN` and `CHAT_ID` are obtained, set the environment variables

    export BOT_API_TOKEN=<bot_api_token>
    export CHAT_ID=<chat_id>

## Usage

Once the required environment variables are in place, you can use `notipi` in the following ways to send messages via Telegram

### (1) As a regular function

```python
from notipi.notipi import notify

def func():
    for i in range(1000):
        if i%100==0:
            notify(f"Currently at {i}")
```

### (2) As a decorator
```python
from notipi.notipi import notify

@notify
def func():
    for i in range(1000):
        pass
```

When `func()` is invoked - you will be notified once it finishes execution

`NOTE`: Both Approaches (1) and (2) are compatible inside Jupyter Notebook as well

<p align="left">
  <img src="assets/notebook_screenshot.jpg" width="900"/>
</p>

Once `func3()` is invoked - you will receive two notifications - first one after `func1()` is processed and second one after `func2()` is executed.

### (3) As a command line tool
    $ noticli -c python example.py
A notification will be sent once `example.py` finishes execution
