Skip to content

Comments

feat: add HTTP API for programmatic file downloads#197

Open
na1oh wants to merge 1 commit intokrau:mainfrom
na1oh:feature/http-api
Open

feat: add HTTP API for programmatic file downloads#197
na1oh wants to merge 1 commit intokrau:mainfrom
na1oh:feature/http-api

Conversation

@na1oh
Copy link

@na1oh na1oh commented Feb 22, 2026

Description

This PR adds an HTTP API for programmatic access to download files from Telegram messages.

Features

  • POST /api/v1/download: Submit download tasks with Telegram message URL
  • GET /api/v1/task/{id}: Query task status
  • GET /health: Health check endpoint
  • Token-based authentication: Optional authentication via Authorization header or query parameter
  • CORS support: Cross-origin resource sharing enabled

Configuration

Add the following section to config.toml:

```toml
[api]
enable = true
host = "0.0.0.0"
port = 8080
token = "your-secret-token" # Optional
```

Usage Example

```bash

Submit a download task

curl -X POST http://localhost:8080/api/v1/download \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-token" \
-d '{
"url": "https://t.me/channel/123\",
"storage": "local"
}'

Check task status

curl http://localhost:8080/api/v1/task/abc123 \
-H "Authorization: Bearer your-token"
```

Implementation Details

  • New pkg/api package with HTTP server implementation
  • Configuration support in config/api.go
  • Integration with existing core task queue
  • Integration with existing tgutil for message parsing
  • Comprehensive API documentation in docs/api.md

Related Issue

Closes #179

- Add REST API endpoints for downloading files from Telegram messages
- POST /api/v1/download: submit download tasks
- GET /api/v1/task/{id}: query task status
- GET /health: health check endpoint
- Support token-based authentication
- Add API configuration section to config.toml
- Add comprehensive API documentation

This allows external applications to integrate with SaveAny-Bot
for automated file downloads from Telegram messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

能否增加一个api接口下载文件

1 participant