Channels
Telegram Admin Channel
๐ก Telegram Admin Channel Plugin for OpenClaw
Install
npm install
pnpm
Configuration Example
{
"plugins": {
"load": {
"paths": [
"/absolute/path/to/openclaw-telegram-admin-channel-plugin"
]
}
}
}
README
<div align="center">
# ๐ก Telegram Admin Channel Plugin for OpenClaw
**Turn your OpenClaw bot into a full-featured Telegram channel admin**
Publishing ยท Comments ยท Analytics ยท Scheduled Posts ยท MTProto Power
[](https://opensource.org/licenses/MIT)
[](https://nodejs.org)
[](https://www.typescriptlang.org/)
[](https://pnpm.io/)
[](http://makeapullrequest.com)
[](https://github.com/nicepkg/openclaw)
<br />
> *"Why hire a social media manager when you have an AI agent?"* โ probably someone, 2026
</div>
---
## Table of Contents
- [Features](#-features)
- [Requirements](#-requirements)
- [Installation](#-installation)
- [MTProto Setup (Optional)](#-mtproto-setup-optional)
- [Usage](#-usage)
- [How It Works](#-how-it-works)
- [Development](#-development)
- [Quick Start (TL;DR)](#-quick-start-tldr)
- [Contributing](#-contributing)
- [License](#-license)
---
## โจ Features
### Bot API (always available)
| Feature | Description |
|---------|-------------|
| ๐ **Post Publishing** | Publish posts to your channel (HTML, Markdown, MarkdownV2) |
| ๐ **Sync** | Synchronize existing posts from a public channel |
| ๐ฌ **Comments** | Collect and store comments from the discussion group |
| ๐ **Activity Feed** | View recent activity (posts + comments) |
### MTProto (requires user account authorization)
| Feature | Description |
|---------|-------------|
| ๐ **Views & Forwards** | Get view/forward counts for specific messages |
| ๐ **Channel Stats** | Subscribers, reach, growth, engagement |
| ๐ **Post Stats** | Per-post statistics with graphs |
| ๐ **Message History** | Channel message history with reactions |
| โฐ **Scheduled Posts** | Create, view, delete, and instantly send scheduled posts |
---
## ๐ Requirements
- [OpenClaw](https://github.com/nicepkg/openclaw) >= 2026.2.0
- Node.js >= 18
- pnpm
- A Telegram bot added as an admin to your channel
---
## ๐ Installation
### 1. Clone and build the plugin
```bash
git clone https://github.com/alesha-pro/openclaw-telegram-admin-channel-plugin.git
cd openclaw-telegram-admin-channel-plugin
pnpm install
pnpm build
```
### 2. Connect the plugin to OpenClaw
Open your OpenClaw config (`openclaw.json` in your project root or global `~/.openclaw/config.json`) and add the plugin path:
```jsonc
{
"plugins": {
"load": {
"paths": [
"/absolute/path/to/openclaw-telegram-admin-channel-plugin"
]
}
}
}
```
### 3. Configure Telegram account
Make sure your OpenClaw config has the Telegram channel set up with a bot token:
```jsonc
{
"channels": {
"telegram": {
"botToken": "123456:ABC-DEF..."
}
}
}
```
If you use multiple accounts, specify the desired one via `telegramAccountId` in the plugin config (defaults to `"default"`).
### 4. Configure the plugin
In the same `openclaw.json`, add a `plugins.entries` section:
```jsonc
{
"plugins": {
"load": {
"paths": ["/absolute/path/to/openclaw-telegram-admin-channel-plugin"]
},
"entries": {
"telegram-admin-channel": {
"enabled": true,
"config": {
"channel": {
"chatId": "@your_channel"
},
"ownerAllowFrom": ["123456789"]
}
}
}
}
}
```
#### Minimum configuration
| Field | Type | Required | Description |
|-------|------|:--------:|-------------|
| `channel.chatId` | string | โ
| Channel ID: `@username` or `-100...` |
| `ownerAllowFrom` | string[] | โ
| Telegram user IDs with admin rights |
#### Full configuration
<details>
<summary>Click to expand full config example</summary>
```jsonc
{
"telegram-admin-channel": {
"enabled": true,
"config": {
// Telegram account from OpenClaw (defaults to "default")
"telegramAccountId": "default",
// Channel
"channel": {
"chatId": "@your_channel" // or "-1001234567890"
},
// Discussion group (for collecting comments)
"discussion": {
"chatId": "-1001234567890"
},
// User IDs with admin rights
"ownerAllowFrom": ["123456789", "987654321"],
// Default settings
"defaults": {
"silent": false // send without notification
},
// Dangerous actions (delete, edit, pin)
"dangerousActions": {
"enabled": false
},
// Storage
"storage": {
"mode": "json" // "json" or "sqlite" (not yet implemented)
},
// MTProto โ extended stats and scheduled posts
"mtproto": {
"enabled": false,
"apiId": 12345678,
"apiHash": "abcdef1234567890abcdef1234567890",
"sessionPath": "~/.openclaw/plugins/telegram-admin-channel/mtproto.session"
}
}
}
}
```
</details>
### 5. Allow the tool in OpenClaw policy
The plugin registers an **optional** tool `tg_channel_admin`. To let the agent use it, add it to the tool allowlist:
```jsonc
{
"tools": {
"allow": ["tg_channel_admin"]
}
}
```
---
## ๐ MTProto Setup (Optional)
MTProto provides access to extended statistics and scheduled posts. It requires user account authorization (not a bot).
### 1. Get API ID and API Hash
Go to [my.telegram.org/apps](https://my.telegram.org/apps) and create an application. You will receive an `api_id` and `api_hash`.
### 2. Run the authorization script
```bash
cd openclaw-telegram-admin-channel-plugin
pnpm build
pnpm mtproto:auth
```
The script will ask for:
1. **API ID** โ number from my.telegram.org (or env var `TELEGRAM_API_ID`)
2. **API Hash** โ string from my.telegram.org (or env var `TELEGRAM_API_HASH`)
3. **Session file path** โ defaults to `~/.openclaw/plugins/telegram-admin-channel/mtproto.session`
4. **Phone number** โ with country code (e.g., `+15551234567`)
5. **Verification code** โ from Telegram
6. **2FA password** โ if enabled
After successful authorization, the script outputs JSON to paste into your config.
### 3. Update config
Add to your plugin config:
```jsonc
"mtproto": {
"enabled": true,
"apiId": 12345678,
"apiHash": "abcdef1234567890abcdef1234567890"
}
```
Or use environment variables `TELEGRAM_API_ID` / `TELEGRAM_API_HASH` and just specify:
```jsonc
"mtproto": {
"enabled": true
}
```
---
## ๐ฎ Usage
Once connected, the OpenClaw agent gets the `tg_channel_admin` tool with the following actions:
### Bot API Actions
| Action | Parameters | Description |
|--------|------------|-------------|
| `post` | `text`, `parseMode?`, `silent?` | Publish a post to the channel |
| `sync` | โ | Sync posts from a public channel |
| `list_recent_activity` | `limit?` | Show recent posts and comments |
### MTProto Actions
| Action | Parameters | Description |
|--------|------------|-------------|
| `get_views` | `messageIds` | Get views and forwards |
| `get_channel_stats` | โ | Channel stats (subscribers, reach, growth) |
| `get_post_stats` | `messageId` | Post stats (view and reaction graphs) |
| `get_history` | `limit?`, `offsetId?` | Channel message history |
| `schedule_post` | `text`, `scheduleDate`, `silent?` | Schedule a post (unix timestamp UTC) |
| `list_scheduled` | โ | List scheduled posts |
| `delete_scheduled` | `messageIds` | Delete scheduled posts |
| `send_scheduled_now` | `messageIds` | Immediately publish scheduled posts |
### Chat with the Agent โ Examples
```
> Publish a post: "Hello, world! This is a test post."
> Show me the recent activity in the channel
> How many views did post #42 get?
> What are the channel stats lately?
> Schedule a post "See you soon!" for tomorrow at 10:00 UTC
> Show all scheduled posts
```
---
## ๐ง How It Works
### Architecture
```
openclaw.json
โโโ channels.telegram.botToken โ bot token
โโโ plugins.entries.telegram-admin-channel
โโโ config โ plugin configuration
โโโ channel.chatId โ channel ID
โโโ discussion.chatId โ discussion group ID
โโโ mtproto.* โ MTProto settings
Plugin (src/index.ts)
โโโ registerTool(tg_channel_admin) โ tool for the agent
โโโ registerHooks(message_received) โ auto-collect posts/comments
โโโ PostStorage (JSON) โ post storage
โโโ CommentStorage (JSON) โ comment storage
โโโ MtprotoClient (optional) โ client for stats
```
### Data Storage
Plugin data is stored in `~/.openclaw/plugins/telegram-admin-channel/`:
| File | Description |
|------|-------------|
| `posts.json` | Published and synced posts |
| `comments.json` | Comments from the discussion group |
| `mtproto.session` | MTProto session (if enabled) |
### Hooks
The plugin automatically listens to all incoming Telegram messages via the `message_received` event. If a message comes from the configured channel or discussion group โ it gets saved locally. This lets the agent see the latest activity context without extra API calls.
---
## ๐ ๏ธ Development
```bash
# Dev mode (recompile on changes)
pnpm dev
# Build
pnpm build
# Tests
pnpm test
pnpm test:watch
# MTProto authorization
pnpm mtproto:auth
```
### Project Structure
```
src/
โโโ index.ts # Plugin entry point, registration
โโโ schema.ts # TypeBox config schema
โโโ tool.ts # Tool definition and handlers
โโโ hooks.ts # Hooks for incoming messages
โโโ storage.ts # JSON storage for posts and comments
โโโ telegram-api.ts # Bot API wrapper + HTML parser
โโโ mtproto-client.ts # MTProto client (stats, scheduling)
โโโ mtproto-auth.ts # MTProto authorization CLI script
```
---
## โก Quick Start (TL;DR)
```bash
# 1. Clone and build
git clone h
... (truncated)
channels
Comments
Sign in to leave a comment