This project is a Telegram bot that responds to text messages. Based on:
- python-telegram-bot: A library that provides a pure Python interface for the Telegram Bot API.
- python-sagemcom-api: A library to interact with Sagemcom devices.
Before running the bot, ensure you have the following:
- Python 3.7 or higher.
- Pip (Python package manager).
-
Clone this repository to your machine:
git clone https://github.com/your_username/your_repository.git cd your_repository -
Install the necessary dependencies:
pip install python-telegram-bot==21.6 sagemcom-api psutil
- Open Telegram and search for the user BotFather.
- Start a conversation with BotFather and use the command
/newbotto create a new bot. - Follow the prompts to name your bot and give it a unique username. After creation, you will receive a token that you will need to access the Telegram Bot API.
- To enable the bot to receive messages in groups, you need to disable privacy mode. You can do this by sending the command
/setprivacyto BotFather and selecting the bot you created. Choose the option to disable privacy mode.
-
Open the bot script (e.g.,
bot.py) and replaceYOUR_BOT_TOKENwith the token you received from BotFather. -
To run the bot, use the following command:
python telegram_bot.py
To run your bot as a service at system startup, you can create a systemd service file.
-
Create a new service file:
sudo nano /etc/systemd/system/telegram-bot.service
-
Add the following content to the file, replacing
/path/to/your/bot.pywith the actual path to your bot script:[Unit] Description=Telegram Bot [Service] ExecStart=/usr/bin/python3 /path/to/your/bot.py WorkingDirectory=/path/to/your/dir Restart=always User=your_username [Install] WantedBy=multi-user.target
-
Save the file and exit the editor.
-
Enable and start the service:
sudo systemctl enable telegram-bot.service sudo systemctl start telegram-bot.service -
To check the status of your bot, you can run:
sudo systemctl status telegram-bot.service
