A FastAPI-based service for sending notifications to Telegram groups.
- Python 3.12+
- Docker (optional)
-
Clone the repo:
git clone https://github.com/yourusername/tg-push.git cd tg-push
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the root directory with the following content:BOT_TOKEN=your_bot_token_here GROUP_IDS=id1,id2,id3 WEBHOOK_URL=https://your-domain.com
uvicorn app.main:app --reload
The API will be available at http://localhost:8000
.
docker-compose up --build
- POST
/send_notification
- Query Parameters:
text
: The notification message (required)bot_id
: Custom bot token (optional)chat_id
: Custom chat ID or list of chat IDs (optional)format
: Message format ('plain', 'html', or 'markdown') (optional)
- Body: JSON object with the same fields as query parameters (optional)
- Query Parameters:
-
Basic notification:
curl -X POST "http://localhost:8000/send_notification?text=Hello, World!"
-
Using custom bot and chat:
curl -X POST "http://localhost:8000/send_notification?text=Custom notification&bot_id=your_custom_bot_token&chat_id=-1001234567890"
-
Sending HTML-formatted message:
curl -X POST "http://localhost:8000/send_notification" \ -H "Content-Type: application/json" \ -d '{"text": "<b>Bold text</b> and <i>italic</i>", "format": "html"}'
-
Sending to multiple chats:
curl -X POST "http://localhost:8000/send_notification" \ -H "Content-Type: application/json" \ -d '{"text": "Multi-chat message", "chat_id": [-1001234567890, -1009876543210]}'
You can specify custom bot tokens and chat IDs for each notification. This allows you to use different bots or send to specific chats without changing the server configuration.
- If
bot_id
is not specified, the default bot from the environment variables will be used. - If
chat_id
is not specified, the notification will be sent to all groups specified in the environment variables. - You can provide parameters either as query parameters or in the JSON body of the request.
The project includes a comprehensive test suite. To run the tests:
pytest -v
- Make your changes
- Update tests if necessary
- Ensure all tests pass
- Create a pull request
This project is licensed under the MIT License.