This Python script allows you to send a message to a personal chat or channel using a Telegram bot. It utilizes the python-telegram-bot library to interact with Telegram's API asynchronously.
- Sends custom messages to a personal chat or Telegram channel
- Uses the Telegram Bot API to interact with Telegram
- Scheduled message sending capabilities
- Python 3.7+
- Telegram Bot Token
- Python Libraries:
python-telegram-botpython-dotenvasyncio
This repository includes several automated workflows:
- Triggers: Daily at 9:00 AM UTC (configurable), Manual dispatch
- Features:
- Automated daily message sending
- Custom message input via workflow dispatch
- Secure environment variable handling
- Execution logging
-
Clone the repository:
git clone https://github.com/cambridgeitcollege/TelegramBot cd TelegramBotCode -
Set up a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up the environment variables:
- Create a .env file in the root of the project:
cp .env.example .env
- Edit the
.envfile and add your credentials:BOTAPIKEY: Get this by creating a bot via @BotFather on TelegramCHATID: Your personal chat ID or channel ID
-
Run the Script:
python3 main.py
To use the automated workflows, you need to set up repository secrets:
-
Rename the Folder:
- Rename the folder
.github.example/workflowsto.github/workflows
- Rename the folder
-
Go to your GitHub repository → Settings → Secrets and variables → Actions
-
Add the following secrets:
BOTAPIKEY: Your Telegram bot API keyCHATID: Your chat or channel ID
-
Available Workflows:
- Manual Message Sending: Go to Actions → "Scheduled Message Sender" → "Run workflow"
- Automated Daily Messages: Runs automatically at 9:00 AM UTC
You can customize the message by:
-
Direct code modification: Edit the
messagevariable inmain.py -
GitHub Actions manual trigger: Use the workflow dispatch feature to send custom messages
-
Scheduled messages: Modify the cron schedule in
.github/workflows/scheduled-message.yml
TelegramBotCode/
├── .github/
│ └── workflows/
│ ├── scheduled-message.yml # Scheduled Message Sender
├── .env.example # Environment variables template
├── .gitignore # Git ignore file
├── main.py # Main bot script
├── requirements.txt # Python dependencies
├── README.md # Project documentation
├── LICENSE # MIT License
├── CodeOfConduct.md # Code of conduct
├── Contribution.md # Contribution guidelines
We welcome contributions! If you'd like to contribute to this Telegram Bot project, please check out our Contribution Guidelines.
Please review our Code of Conduct before participating in this project.
This project is licensed under the MIT License.
- python-telegram-bot - Python wrapper for Telegram Bot API
- GitHub Actions - For automation and CI/CD