Files
telefind-rs/README.md

44 lines
3.2 KiB
Markdown

# telefind-rs
Rust keyword search for public Telegram channels, groups, bots and posts. The executable runs with an in-memory index. It accepts records from the caller and new channel updates delivered to the bot.
## Try a query locally
From the workspace root:
```sh
cargo run -p app -- query - '/search type:video 上海相机' <<'JSONL'
{"op":"upsert","kind":"post","id":-100501,"message_id":42,"username":"example_feed","title":"相机入门.mp4","body":"上海 摄影","media":"video"}
JSONL
```
This prints the reply as JSON, including a button with the URL `https://t.me/example_feed/42`. The example uses a fictional record.
## Telegram bot
Supply the bot token through the environment variable `TELEGRAM_BOT_TOKEN` and run:
```sh
cargo run -p app -- bot events.jsonl
```
The input file is optional. The process identifies its username via `getMe`, then long-polls for incoming messages and sends search results with URL buttons. Type keywords in private chat or use `/search@YourBot keywords` in a group. In a public channel where the bot receives posts, incoming posts and edits update the in-memory index. For channels without a public username, protected posts and unsupported content, the bot skips indexing the message. Telegram does not send ordinary post-deletion notifications via this update stream. An upstream source can supply deletion events. If a reply reached Telegram but its HTTP acknowledgement was lost, retrying an update can send the reply twice.
Use a leading `type:channel`, `type:group`, `type:bot`, `type:post`, `type:photo`, `type:video`, `type:audio` or `type:file` to filter. After the optional type filter, add `from:@username` to restrict the source, or `exclude:广告` to omit titles and bodies containing that normalized text fragment. Multiple exclusions are allowed. Follow the filters with search terms, for example `/search type:video from:@example_feed exclude:广告 相机`. Double quotes require a contiguous phrase in one field. Use `/page 2 type:video 摄影` to repeat a query on another page.
## Document input and storage
Pass an ordered UTF-8 JSONL stream in a file, or pass `-` to read standard input until EOF. The executable replays it before processing queries. A directory record uses its Telegram numeric ID. A post uses its chat ID and positive message ID. An upsert replaces the previous version with the same identity. Run a delete with the same key, for example:
```json
{"op":"delete","kind":"post","id":-100501,"message_id":42}
```
The process keeps no database or history archive. Restarting loads whichever input the caller supplies. For a persistent or concurrent host, implement `search_core::index::IndexStore` and its snapshot reader, then use `Engine::new(store)`. Pass the resulting engine to `app::telegram::run` with a `app::telegram::Client` to reuse the same polling and reply logic. The JSONL reader `app::input::load` also accepts any implementation of `SearchIndex`.
## Verification
`cargo test --workspace --locked` exercises the index, the executable with piped input, and Telegram Bot API requests against a loopback HTTP fixture. These tests use synthetic records.
For a host that needs independent indexing and query workers, see [queue integration and capacity estimates](docs/capacity.md).