CSUBOT is an open-source super administrator bot.

This article describes how to deploy CSUBOT yourself.

Please read this document in its entirety first: CSUBOT Robot User Manual

Recommended: Query the public IP of this machine for accessing different websites, used to check the current network environment.

Prerequisites

To deploy CSUBOT yourself, you need to meet at least the following conditions:

  • Hold a domain name. (Hold at least a second-level domain name for the backend. In fact, the frontend and backend require two second-level domain names in total, but generally the frontend domain name can be provided by the deployment platform)
  • Hold a server. Or deploy it on a platform where backend services can be deployed. If you know of a free platform where backend services can be deployed, please don’t hesitate to click here to post a comment and tell the author .
  • Hold an unrestricted Telegram account for creating a Telegram bot and obtaining the bot’s Token
  • Hold an unrestricted Cloudflare account to enable Cloudflare Turnstile CAPTCHA. Register an account: https://dash.cloudflare.com/

Steps

  1. Enable Cloudflare Turnstile
  2. Deploy the frontend
  3. Create a Telegram bot
  4. Configure the backend

Enable Cloudflare Turnstile

Click this link to open the Cloudflare Turnstile configuration panel Turnstile Component Configuration

Click add widget to add a Turnstile widget

Click Add Hostnames to add the frontend domain name. If you plan to use the domain name provided by the frontend hosting platform, you can write anything here.

Click the create button, and then you can see the Site Key and Secret Key

Deploy the frontend

We take deploying to a frontend hosting platform as an example.

  1. Open https://github.com/cjh0613/csubot-vue and fork this repository
  2. Select the deployment platform, such as Cloudflare Pages, Vercel, Netlify, etc.
  3. Select Import from Github repository, and select the forked repository in the first step.

The working path is configured as the project root directory, and the compilation command is:

npm install && npm run build

The output directory is:

dist/

Configure environment variables:

VITE_ENDPOINT=https://xxxx.com <Backend URL, needs https>

VITE_SITEKEY=0x4AAAAAABBBBBBBBBBB <Cloudflare turnstile site key Site Key (the one at the top)>
  1. Start deployment, and after completion, you can see the domain name provided by the platform. You can also bind your own domain name. You need to wait for DNS configuration and certificate generation.

Create a Telegram bot

Send /newbot in a private chat with https://t.me/BotFather , and follow the bot’s prompts to create a new bot. After creation, you will receive a Token

Configure the backend

You can choose to directly run the binary executable file, or compile it yourself.

Environment variable reference

TGWD_TOKEN=<Telegram bot's token, obtained from @botfather>
TGWD_FRONTEND_DOMAIN=<Frontend domain name, no https required>
TGWD_SECRET=<Fill in anything>
TGWD_PORT=8000
TGWD_CFTS_API_KEY=<Cloudflare turnstile's Secret Key (the one below the site key)>

Use binary executable file

We take the linux amd64 operating system as an example.

First create a new folder.

mkdir csubot && cd csubot

Download the binary executable file. For the download link here, please open https://github.com/cjh0613/csubot/releases to get the latest link, you may need to click Show all assets to find the file suitable for your platform.

wget https://github.com/cjh0613/csubot/releases/download/vxxx/csubot-linux-amd64.zip

Because it is a zip format compressed package, decompress it:

unzip csubot-linux-amd64.zip

If you cannot execute this command, please confirm that the unzip package has been successfully installed.

Enter the directory where csubot is located,

Use the following command to view the hidden .env.example file.

ls -la

Use your text editor (such as nano, vim), create a new file .env, and refer to the example file .env.example for configuration.

Try running:

export $(grep -v '^#' .env | xargs) && ./csubot

Compile yourself

Execute the command in the project root directory:

go build -o csubot

Try running:

export $(grep -v '^#' .env | xargs) && ./csubot

HTTPS

The backend does not directly provide https support, and can only be accessed via http.

You can use services such as Apache, Nginx, Microsoft Internet Information Services (IIS) to configure HTTPS.

If you use Cloudflare CDN, you can also set the encryption mode to Flexible in SSL/TLS encryption. In this way, users access the Cloudflare server using the https protocol automatically configured by Cloudflare, and then Cloudflare accesses the server where you configured the backend service using the http protocol.

Run as a systemd service

sudo mkdir /usr/local/bin/csubot/
sudo cp .env /usr/local/bin/csubot/.env
sudo cp csubot /usr/local/bin/csubot/csubot
sudo cp -r ./locales /usr/local/bin/csubot/locales

Create a service user

sudo useradd --system --no-create-home --shell /sbin/nologin csubotuser

Configure permissions

sudo chown csubotuser:csubotuser /usr/local/bin/csubot/csubot
sudo setfacl -R -m u:csubotuser:r /usr/local/bin/csubot
sudo chmod +x /usr/local/bin/csubot/csubot

Create and edit /etc/systemd/system/csubot.service and write

[Unit]
Description=CSUBOT Backend
After=network-online.target
Wants=network-online.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
User=csubotuser
Group=csubotuser
ExecStart=/usr/local/bin/csubot/csubot
WorkingDirectory=/usr/local/bin/csubot
RestartSec=10s
Restart=always
# Restart=on-failure

# Load environment variable file
EnvironmentFile=/usr/local/bin/csubot/.env
# Start the service
sudo systemctl start csubot.service

# View running status
sudo systemctl status csubot.service

# Set to start on boot
sudo systemctl enable csubot.service

Other versions of this page

This article has versions in multiple languages.

If you would like to leave a comment, please visit the following pages:

ZH EN ZH-TW JA

These pages only support browsing and do not allow posting comments or messages, but they provide more language options and load faster:

ZH EN ZH-TW JA RU KO CS ES AR FR PT DE TR IT NL SV DA FI PL UK HE RO HU EL HR TH HI BN ID SW VI NO