This is a simple Flask-based API that allows sending messages to a Telegram chat using a bot.
- Receives
POSTrequests withchat_idandupdate(message text) in JSON format. - Sends messages to a specified Telegram chat via the bot.
- Returns success or error messages based on the API response.
Ensure you have Python installed and install the necessary dependencies using:
pip install -r requirements.txt- Flask==3.1.0
- requests==2.32.3
- python-dotenv==1.0.1
-
Clone this repository:
git clone https://github.com/yourusername/flask-telegram-bot.git cd flask-telegram-bot -
Install dependencies using
pip install -r requirements.txt. -
Create a
.envfile in the project root and add your Telegram bot token:BOT_ACCESS_TOKEN=your_telegram_bot_token_here
Run the Flask app:
python app.pySend a POST request to the endpoint /submit with a JSON body:
{
"chat_id": "123456789",
"update": "Hello, this is a test message!"
}curl -X POST "http://127.0.0.1:5000/submit" \
-H "Content-Type: application/json" \
-d '{"chat_id": "123456789", "update": "Hello from Flask!"}'{
"ok": true,
"result": {
"message_id": 1,
"chat": { "id": 123456789, "type": "private" },
"text": "Hello from Flask!"
}
}- Returns
400if required fields are missing. - Returns
500for unexpected errors. - If Telegram API fails, returns the error message received from Telegram.
Contributions are welcome! Feel free to open issues or submit pull requests.
This project is open-source and available under the MIT License.
For any questions, reach out to [your email or GitHub profile link].