11# miloco-bot
22
3+ English | [ 中文] ( README_CN.md )
4+
35** miloco-bot** is a TypeScript-based middleware that acts as a ** Model Context Protocol (MCP)** server for [ Xiaomi Miloco] ( https://github.com/XiaoMi/xiaomi-miloco ) . It bridges Miloco with ** Telegram** , enabling bi-directional communication and remote management capabilities.
46
57## Features
1921
2022## Prerequisites
2123
22- - ** Node.js** (v24 or higher recommended for building)
23- - ** npm** or ** yarn** or ** pnpm**
2424- A ** Telegram Bot Token** (obtained from [ @BotFather ] ( https://t.me/BotFather ) )
2525- ** Miloco** instance running and accessible.
2626
27- ## Installation
27+ ## Installation (Linux x64)
2828
29- 1 . ** Clone the repository** :
30- ``` bash
31- git clone https://github.com/your-username/miloco-bot.git
32- cd miloco-bot
33- ```
29+ We provide a single-command installation script that downloads the latest binary release and sets up the systemd service.
30+
31+ ** Run the following command as root:**
32+
33+ ``` bash
34+ wget -O - https://raw.githubusercontent.com/AkarinServer/miloco-bot/main/scripts/install.sh | sudo bash
35+ ```
36+
37+ ** What this script does:**
38+ 1 . Downloads the latest ` miloco-bot-linux ` binary from GitHub Releases.
39+ 2 . Installs it to ` /opt/miloco-bot/ ` .
40+ 3 . Sets up a systemd service named ` miloco-bot ` .
41+ 4 . Creates a ` .env ` configuration file if one doesn't exist.
42+
43+ ### Configuration
44+
45+ After installation, you ** must** configure the bot:
3446
35- 2 . ** Install dependencies ** :
47+ 1 . Edit the configuration file :
3648 ``` bash
37- npm install
49+ sudo nano /opt/miloco-bot/.env
3850 ```
39-
40- 3. ** Configuration** :
41- Create a ` .env` file in the root directory (see ` .env_template` ):
51+ 2. Fill in your details (Telegram Token, User IDs, Miloco URL, etc.):
4252 ` ` ` env
4353 # Telegram Configuration
4454 TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
4858 MILOCO_WS_URL=wss://localhost:8000/api/chat/ws/query
4959 MILOCO_ADMIN_USERNAME=admin
5060 MILOCO_PASSWORD=your_miloco_password
51- # MILOCO_DATA_DIR=/path/to/miloco/data # Optional, for image access
52-
53- # Server Configuration
54- PORT=3000
55- # MCP_API_KEY=your-secret-token # Optional, for securing the MCP server endpoint
61+ ` ` `
62+ 3. Start the service:
63+ ` ` ` bash
64+ sudo systemctl start miloco-bot
5665 ` ` `
5766
58- # # Usage
67+ # ## Manage Service
5968
60- # ## Development Mode
6169` ` ` bash
62- npm run dev
70+ sudo systemctl status miloco-bot
71+ sudo systemctl restart miloco-bot
72+ sudo journalctl -u miloco-bot -f # View logs
6373` ` `
6474
65- # ## Connect to Miloco
75+ # # Connect to Miloco
76+
66771. Open your Miloco dashboard.
67782. Navigate to ** MCP Services** -> ** Add Service** .
68793. Select ** Streamable HTTP** .
69804. Fill in the details:
70- - ** URL** : ` http://< your-ip> :3000/mcp`
81+ - ** URL** : ` http://< your-server- ip> :3000/mcp`
7182 - ** Request Header (Token)** : ` Authorization: Bearer < your-secret-token> ` (if ` MCP_API_KEY` is set).
72835. Click ** Add** .
7384
7485# # Telegram Commands
86+
7587- ` /start` : Check if the bot is running and you are authorized.
7688- ` /help` : Show available commands.
7789- ` /ping` : Check connection to Miloco.
7890- ` /rules` : View and manage Miloco trigger rules (Interactive UI).
7991- ` /status` : Show system status.
8092
8193# # MCP Tools Provided
94+
8295The following tools are exposed to Miloco:
8396
8497- ` send_telegram_message` :
@@ -99,43 +112,25 @@ The following tools are exposed to Miloco:
99112 - ** Description** : Enables or disables a specific rule.
100113 - ** Inputs** : ` rule_id` (string), ` enabled` (boolean).
101114
102- # # Deployment on Ubuntu (Single Binary)
115+ # # Development
103116
104- To package the application as a single executable for Linux (e.g., Ubuntu) :
117+ For contributors who want to build from source :
105118
106- 1. ** Build the Linux Binary ** :
119+ 1. Clone and install dependencies :
107120 ` ` ` bash
108- npm run build:linux
121+ git clone https://github.com/AkarinServer/miloco-bot.git
122+ cd miloco-bot
123+ npm install
109124 ` ` `
110- - This downloads the Node.js 24 binary (cached in ` .cache/` ), generates a blob, and injects it to create ` dist/miloco-bot-linux` .
111-
112- 2. ** Deploy to Server** :
113- Copy the following to your server (e.g., ` /opt/miloco-bot/` ):
114- - ` dist/miloco-bot-linux`
115- - ` scripts/manage.sh`
116- - ` .env`
117-
118- 3. ** Install and Run** :
119- On the server:
125+ 2. Run in dev mode:
120126 ` ` ` bash
121- chmod +x manage.sh
122- sudo ./manage.sh install
127+ npm run dev
123128 ` ` `
124-
125- 4. ** Manage Service** :
129+ 3. Build binary:
126130 ` ` ` bash
127- sudo ./manage.sh start # Start service
128- sudo ./manage.sh stop # Stop service
129- sudo ./manage.sh restart # Restart service
130- sudo ./manage.sh logs # View logs
131+ npm run build:linux
131132 ` ` `
132133
133- # # Project Structure
134-
135- - ` src/index.ts` : Main entry point, MCP server, Telegram bot logic, and MCP tool definitions.
136- - ` src/miloco_client.ts` : Client for interacting with Miloco API (Login, Rules, etc.).
137- - ` scripts/` : Build and management scripts.
138-
139134# # License
140135
141136MIT
0 commit comments