This is a Telegram bot powered by Python, OpenAI, and Docker. The bot provides functionalities like fetching Marvel Snap deck information, interacting with users via inline buttons, and monitoring updates from a website.
git clone https://github.com/rogercezidio/galactus_bot.git
cd galactus_bot
Create two .env
files: one for development and one for production.
-
.env.dev
: (for development)BOT_TOKEN=your-development-bot-token OPENAI_API_KEY=your-development-openai-api-key GALACTUS_CHAT_ID=your-group-chat-id
-
.env.prod
: (for production)BOT_TOKEN=your-production-bot-token OPENAI_API_KEY=your-production-openai-api-key GALACTUS_CHAT_ID=your-group-chat-id
Also create a .env
with the same content of .env.prod
Ensure your .env
files are in the root of the project directory and do not commit them to version control (add them to .gitignore
).
Ensure your docker-compose.yml
file looks like this:
services:
my-bot:
build: .
volumes:
- ./app/data:/app/data
environment:
- BOT_TOKEN=${BOT_TOKEN}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- GALACTUS_CHAT_ID=${GALACTUS_CHAT_ID}
This allows you to dynamically select the environment file when starting the bot.
To start the bot in development, run:
docker-compose -f docker-compose.yml -f docker-compose.override.yml up
To start the bot in production, run:
docker-compose up -d
Ensure that the last_update.txt
file persists between container restarts by mounting a volume.
- The file is stored at
./app/data/last_update.txt
inside the container. - Use Docker volumes to persist the data across container restarts.
To bring up the bot container (either in dev or prod) with Docker Compose:
docker-compose up -d
To stop the bot:
docker-compose down
To view logs:
docker-compose logs -f
To ensure the bot automatically starts after an EC2 instance reboots, you can use systemd on your EC2 instance to manage the Docker Compose service.
Create a new service file for systemd to manage your Docker Compose application.
sudo nano /etc/systemd/system/galactus-bot.service
Add the following content to the file:
[Unit]
Description=Galactus Telegram Bot
After=docker.service
Requires=docker.service
[Service]
Restart=always
WorkingDirectory=/path/to/your/project
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
[Install]
WantedBy=multi-user.target
Replace /path/to/your/project
with the actual path to your bot's project directory.
Run the following commands to enable the service so it starts automatically on reboot:
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable the service to start on boot
sudo systemctl enable galactus-bot
# Start the service
sudo systemctl start galactus-bot
Now, your Docker Compose application will automatically start when your EC2 instance reboots.
You can check the status of the service with:
sudo systemctl status galactus-bot
- Docker Not Found Error: Ensure Docker is installed and running. Use
docker ps
to verify. - Environment File Missing: Make sure the correct
.env
file is created and included in thedocker-compose.yml
. - Bot Not Starting After Reboot: Ensure the systemd service is enabled with
sudo systemctl enable galactus-bot
.
-
Restart the bot manually:
sudo systemctl restart galactus-bot
-
View systemd logs:
sudo journalctl -u galactus-bot
Feel free to fork this repository and create pull requests to add new features or fix bugs.
Roger Cezidio