PEPPASORG is a system that integrates a Telegram bot and a Minecraft server in GCP, allowing remote control and server automation along with dynamic responses in chat.
- Telegram Bot: Uses
Telegraf
to interact with the Telegram API,node-fetch
for HTTP requests, andGiphyFetch
to integrate GIF search. - Minecraft Server: An instance on GCP allows players to access a persistent Minecraft world, with the ability to control the state of the server through the Telegram bot.
- Deployment in GCP: The steps to deploy the Telegram bot as a serverless function in Google Cloud Run and the VM for the Minecraft server are detailed.
Bot commands include:
/prender_servercito
: Starts the server and responds with a game GIF./apagar_servercito
: Stops the server and responds with a sleepy GIF.
- Introduction
- Minecraft Server Configuration
- Telegram Bot Deployment
- Getting API Tokens and Credentials
- Minecraft Server Configuration and Administration
- Development
- Support and Documentation
- Contributors
👉 You will be asked to enable compute.googleapis.com to create the virtual machine where the Minecraft server will run.
- Reserve a static IP address in GCP:
gcloud compute addresses create minecraft-static-ip --region=us-central1
- Create a VM instance in GCP with the following command:
SERVER_GCP_ZONE=us-central1-a SERVER_GCP_NAME=minecraft-server SERVER_GCP_MACHINE_TYPE=e2-standard-4 USERNAME=$(whoami) gcloud compute instances create $SERVER_GCP_NAME \ --zone=$SERVER_GCP_ZONE \ --machine-type=$SERVER_GCP_MACHINE_TYPE \ --boot-disk-size=20GB \ --image-family=debian-10 \ --image-project=debian-cloud \ --tags=$SERVER_GCP_NAME \ --address=minecraft-static-ip \ --metadata username=$USERNAME,startup-script='#!/bin/sh USERNAME=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/attributes/username" -H "Metadata-Flavor: Google") mkdir -p /home/minecraft && \ git clone https://github.com/LuisCusihuaman/peppasorg.git /home/minecraft && \ mkdir -p /home/minecraft/mods && \ chown -R $USERNAME:$USERNAME /home/minecraft curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && usermod -aG docker $USERNAME cd /home/$USERNAME/ && sudo -u $USERNAME docker compose up -d'
💸 PRICING: $104.82/ mo
- Add firewall rules to allow traffic on the necessary ports:
gcloud compute firewall-rules create allow-25565-8080 \ --allow tcp:25565,tcp:8080 \ --target-tags=$SERVER_GCP_NAME \ --description="Allow traffic on port 25565 (MINECRAFT SERVER) and 8080 (FILE SERVER)"
👉 You will be asked to enable cloudbuild.googleapis.com and run.googleapis.com (IT WILL TAKE A TIME) for the construction and deployment of the bot.
-
Create the service account:
gcloud iam service-accounts create minecraft-server-account --display-name "Minecraft Server Account"
-
Get your project ID automatically:
PROJECT_ID=$(gcloud config get-value project) echo $PROJECT_ID
-
Create a custom role with the necessary permissions to start and stop the Minecraft instance:
gcloud iam roles create minecraft_instance_control --project $PROJECT_ID --title "Minecraft Instance Control" --description "Custom role for starting and stopping Minecraft instance" --permissions compute.instances.start,compute.instances.stop,compute.instances. list,compute.zoneOperations.get,compute.zoneOperations.list
-
Assign the custom role to the service account:
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:minecraft-server-account@$PROJECT_ID.iam.gserviceaccount.com" --role=projects/$PROJECT_ID/roles/minecraft_instance_control
-
Generate the JSON key file for the service account:
gcloud iam service-accounts keys create ./my_credentials.json --iam-account=minecraft-server-account@$PROJECT_ID.iam.gserviceaccount.com
-
Clone the bot repository: First, clone the Telegram bot repository to your local or development environment:
git clone https://github.com/LuisCusihuaman/peppasorg.git peppasorg-bot
-
Copy the credentials file: Copy
my_credentials.json
to the cloned project directory:cp my_credentials.json peppasorg-bot/
-
Build the container image and upload it to Container Registry: From the project directory, build and upload the image directly to Google Container Registry:
PROJECT_ID=$(gcloud config get-value project) gcloud builds submit --tag gcr.io/$PROJECT_ID/peppasorg-bot peppasorg-bot/
-
Deploy to Cloud Run: Use the following command to deploy your bot:
SERVER_GCP_REGION=us-central1 SERVER_GCP_ZONE=us-central1-a SERVER_GCP_NAME=minecraft-server GIPHY_TOKEN=your-giphy-token BOT_TOKEN=your-bot-token gcloud run deploy peppasorg-bot \ --image gcr.io/$PROJECT_ID/peppasorg-bot \ --platform managed \ --region $SERVER_GCP_REGION \ --allow-unauthenticated \ --set-env-vars PRODUCTION='true',\ SERVER_GCP_NAME=$SERVER_GCP_NAME,\ SERVER_GCP_ZONE=$SERVER_GCP_ZONE,\ GIPHY_TOKEN=$GIPHY_TOKEN,\ BOT_TOKEN=$BOT_TOKEN
-
Configure the Telegram webhook: Configure the Telegram webhook so that the bot can receive message updates:
CLOUD_RUN_URL=$(gcloud run services describe peppasorg-bot --region $SERVER_GCP_REGION --format 'value(status.url)') curl -F "url=${CLOUD_RUN_URL}/bot${BOT_TOKEN}" https://api.telegram.org/bot${BOT_TOKEN}/setWebhook
Replace
your-bot-token
with your Telegram bot token,your-giphy-token
with your Giphy API token.
This process will clone the bot repository, copy the necessary credentials file to the project directory, build the container image, and deploy it to Google Cloud Run.
- Open the Telegram app and search for the “BotFather” bot.
- Start a chat with BotFather and send the command
/newbot
. - Follow the prompts to create a new bot and get your bot token.
- Go to Giphy Developer Portal.
- Create a new app and get your Giphy API key.
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to "APIs and services" > "Credentials".
- Click "Create Credentials" and select "Service Account".
- Follow the prompts to create a new service account and download the JSON key file.
After obtaining these tokens and credentials, place the GCP JSON key file in the root of the project, with the name:
const options = {
keyFilename: './my_credentials.json',
};
Execute any of these commands in RCON:
RCON_PASSWORD=password
docker compose exec mc rcon-cli list
docker compose exec mc rcon-cli say "Hello gamers"
docker compose exec mc rcon-cli op <player> #Give administrator permissions
docker compose exec mc rcon-cli deop <player> #Remove administrator permissions
docker compose exec mc rcon-cli whitelist add <player>
docker compose exec mc rcon-cli whitelist remove <player>
docker compose exec mc rcon-cli ban <player>
docker compose exec mc rcon-cli ban-ip <ip>
docker compose exec mc rcon-cli pardon <player>
docker compose exec mc rcon-cli pardon-ip <ip>
docker compose exec mc rcon-cli save-all
docker compose exec mc rcon-cli save-off
docker compose exec mc rcon-cli save-on
docker compose exec mc rcon-cli stop
Configure the minecraft.env with the following environment variables:
Minecraft Server Documentation
-
Export the necessary environment variables in your terminal:
export SERVER_GCP_NAME=minecraft-server export SERVER_GCP_ZONE=us-central1-a export BOT_TOKEN=your-bot-token export GIPHY_TOKEN=your-giphy-token
-
Copy the GCP credentials file
my_credentials.json
to the project directory. -
Run
pnpm install
to install the necessary dependencies. -
Run
pnpm start
to start the development server.
For more information and troubleshooting, see the following resources:
This project has been possible thanks to the collaboration of the following contributors:
Contributor | Profile |
---|---|
![]() |
Eduardo Cusihuaman |
![]() |
Eddy Vega |
We appreciate your dedication and effort in carrying out this project!