Skip to content

Commit 2272dc0

Browse files
committed
feat: add ci/cd, install script, and update docs for binary-only deployment
1 parent c8b5843 commit 2272dc0

4 files changed

Lines changed: 209 additions & 102 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Use Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20'
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Build Linux Binary
27+
run: npm run build:linux
28+
29+
- name: Create Release
30+
uses: softprops/action-gh-release@v1
31+
with:
32+
name: Latest Build
33+
tag_name: latest
34+
files: dist/miloco-bot-linux
35+
draft: false
36+
prerelease: false
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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
@@ -19,26 +21,34 @@
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
@@ -48,37 +58,40 @@
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+
6677
1. Open your Miloco dashboard.
6778
2. Navigate to **MCP Services** -> **Add Service**.
6879
3. Select **Streamable HTTP**.
6980
4. 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).
7283
5. 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+
8295
The 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

141136
MIT

README_CN.md

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# miloco-bot
22

3+
[English](README.md) | 中文
4+
35
**miloco-bot** 是一个基于 TypeScript 开发的中间件程序,它作为 [Xiaomi Miloco](https://github.com/XiaoMi/xiaomi-miloco)**Model Context Protocol (MCP)** 服务端。它在 Miloco 和 **Telegram** 之间架起了一座桥梁,实现了双向通信和远程管理能力。
46

57
## 功能特性
@@ -19,26 +21,34 @@
1921

2022
## 前置要求
2123

22-
- **Node.js** (构建建议 v24 或更高版本)
23-
- **npm****yarn****pnpm**
2424
- **Telegram Bot Token** (通过 [@BotFather](https://t.me/BotFather) 获取)
2525
- 已运行且可访问的 **Miloco** 实例。
2626

27-
## 安装步骤
27+
## 安装步骤 (Linux x64)
2828

29-
1. **克隆仓库**:
30-
```bash
31-
git clone https://github.com/your-username/miloco-bot.git
32-
cd miloco-bot
33-
```
29+
我们提供了一个单行命令安装脚本,用于下载最新的二进制版本并配置 systemd 服务。
30+
31+
**请使用 root 权限运行以下命令:**
32+
33+
```bash
34+
wget -O - https://raw.githubusercontent.com/AkarinServer/miloco-bot/main/scripts/install.sh | sudo bash
35+
```
36+
37+
**脚本执行内容:**
38+
1. 从 GitHub Releases 下载最新的 `miloco-bot-linux` 二进制文件。
39+
2. 安装到 `/opt/miloco-bot/` 目录。
40+
3. 创建一个名为 `miloco-bot` 的 systemd 服务。
41+
4. 如果不存在,则创建一个初始的 `.env` 配置文件。
42+
43+
### 配置
44+
45+
安装完成后,你**必须**配置机器人:
3446

35-
2. **安装依赖**:
47+
1. 编辑配置文件:
3648
```bash
37-
npm install
49+
sudo nano /opt/miloco-bot/.env
3850
```
39-
40-
3. **配置环境**:
41-
在项目根目录创建一个 `.env` 文件(参考 `.env_template`):
51+
2. 填写你的详细信息(Telegram Token, 用户 ID, Miloco URL 等):
4252
```env
4353
# Telegram 配置
4454
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
@@ -48,37 +58,40 @@
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 # 可选,用于图片访问
52-
53-
# 服务器配置
54-
PORT=3000
55-
# MCP_API_KEY=your-secret-token # 可选,用于保护 MCP 服务端接口
61+
```
62+
3. 启动服务:
63+
```bash
64+
sudo systemctl start miloco-bot
5665
```
5766

58-
## 使用方法
67+
### 服务管理
5968

60-
### 开发模式
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 # 查看日志
6373
```
6474

65-
### 连接到 Miloco
75+
## 连接到 Miloco
76+
6677
1. 打开你的 Miloco 控制面板。
6778
2. 导航至 **MCP 服务 (MCP Services)** -> **添加服务 (Add Service)**
6879
3. 选择 **Streamable HTTP**
6980
4. 填写详细信息:
70-
- **URL**: `http://<你的IP>:3000/mcp`
81+
- **URL**: `http://<你的服务器IP>:3000/mcp`
7182
- **请求头 (Token)**: `Authorization: Bearer <your-secret-token>` (如果设置了 `MCP_API_KEY`)。
7283
5. 点击 **添加 (Add)**
7384

7485
## Telegram 命令
86+
7587
- `/start`: 检查机器人运行状态及权限。
7688
- `/help`: 显示可用命令。
7789
- `/ping`: 检查与 Miloco 的连接状态。
7890
- `/rules`: 查看并管理 Miloco 触发规则(交互式 UI)。
7991
- `/status`: 显示系统状态信息。
8092

8193
## 提供的 MCP 工具
94+
8295
以下工具已暴露给 Miloco:
8396

8497
- `send_telegram_message`:
@@ -99,43 +112,25 @@ npm run dev
99112
- **描述**: 开启或关闭指定规则。
100113
- **输入**: `rule_id` (字符串), `enabled` (布尔值)。
101114

102-
## Ubuntu 部署 (单体程序)
115+
## 开发指南
103116

104-
将程序打包为 Linux (如 Ubuntu) 下的单体可执行文件
117+
如果你是开发者并希望从源码构建
105118

106-
1. **构建 Linux 二进制文件**:
119+
1. 克隆并安装依赖:
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-
- 该命令会自动下载 Node.js 24 二进制文件(缓存在 `.cache/` 中),生成 Blob 并注入,最终在 `dist/` 目录下生成 `miloco-bot-linux`
111-
112-
2. **上传至服务器**:
113-
将以下文件复制到你的服务器 (例如 `/opt/miloco-bot/`):
114-
- `dist/miloco-bot-linux`
115-
- `scripts/manage.sh`
116-
- `.env`
117-
118-
3. **安装并运行**:
119-
在服务器上运行:
125+
2. 运行开发模式:
120126
```bash
121-
chmod +x manage.sh
122-
sudo ./manage.sh install
127+
npm run dev
123128
```
124-
125-
4. **服务管理**:
129+
3. 构建二进制文件:
126130
```bash
127-
sudo ./manage.sh start # 启动服务
128-
sudo ./manage.sh stop # 停止服务
129-
sudo ./manage.sh restart # 重启服务
130-
sudo ./manage.sh logs # 查看日志
131+
npm run build:linux
131132
```
132133

133-
## 项目结构
134-
135-
- `src/index.ts`: 程序入口、MCP 服务器、Telegram 机器人逻辑及 MCP 工具定义。
136-
- `src/miloco_client.ts`: 用于与 Miloco API 交互的客户端(登录、规则管理等)。
137-
- `scripts/`: 构建和管理脚本。
138-
139134
## 许可证
140135

141136
MIT

0 commit comments

Comments
 (0)