Skip to content

Commit ea14b10

Browse files
committed
feat: dual-mode bot/user + WebUI overhaul
Bot mode via Grammy Bot API with native streaming. Architecture refacto: EventBus, 4 class extractions, hot-swap setters. WebUI: bot mode setup wizard, mode switch in dashboard sidebar, UI improvements.
1 parent f99d9d1 commit ea14b10

217 files changed

Lines changed: 15417 additions & 2082 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ Agent: [Displays uptime, model, tool count, wallet balance]
146146
147147
---
148148

149+
## User Mode vs Bot Mode
150+
151+
Teleton can run as a **user account** (MTProto) or a **Telegram bot** (Bot API). Set `telegram.mode` in your config:
152+
153+
| | User Mode (default) | Bot Mode |
154+
|---|---|---|
155+
| **Auth** | Phone + api_id + api_hash | Bot token from @BotFather |
156+
| **Protocol** | MTProto (GramJS) | Bot API (Grammy) |
157+
| **Tools** | 135+ | 67 (11 Telegram + 56 non-Telegram) |
158+
| **Risk** | Account ban possible | No ban risk |
159+
| **Dialogs/History** | Full access | Not available |
160+
| **Media sending** | All types | Photos only (v1) |
161+
| **Inline keyboards** | Via bot_token | Native |
162+
| **Stars/Gifts** | Full access | Not available |
163+
| **Profile editing** | Yes | No |
164+
| **Scheduled tasks** | Yes | Not available |
165+
| **Setup** | `telegram.mode: "user"` | `telegram.mode: "bot"` |
166+
167+
---
168+
149169
## Configuration
150170

151171
The `teleton setup` wizard generates a fully configured `~/.teleton/config.yaml` file. Manual editing is only necessary if you want to adjust settings after the initial setup.

SDK_SUGGESTIONS.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# SDK Suggestions — Plugin Developer Wishlist
2+
3+
Feedback from building 26+ plugins (183+ tools) against SDK v1.0.0.
4+
These suggestions target pain points shared across multiple plugins.
5+
6+
---
7+
8+
## Priority 1: High Impact
9+
10+
### `sdk.ton.sendRaw(to, value, body, opts?)`
11+
12+
**Problem**: Every plugin that interacts with a custom smart contract must duplicate ~30 lines of wallet boilerplate: read `wallet.json`, derive keypair, create `WalletContractV5R1`, get seqno, build internal message, sendTransfer with SendMode flags. This is repeated in gaspump, x1000, sbt, stormtrade, groypfi — any plugin with custom opcodes.
13+
14+
**Proposal**:
15+
```js
16+
await sdk.ton.sendRaw(tokenAddress, "1.5", bodyCell, {
17+
bounce: true, // default true
18+
stateInit: null, // optional, for deploy
19+
});
20+
// Returns: { seqno, walletAddress, hash? }
21+
```
22+
23+
- Signs automatically from the agent wallet
24+
- Manages seqno internally (prevents collisions on rapid calls)
25+
- Uses `SendMode.PAY_GAS_SEPARATELY | SendMode.IGNORE_ERRORS` by default
26+
- Accepts a Cell body (from `@ton/core`)
27+
28+
**Plugins that benefit**: x1000, gaspump, sbt, stormtrade, groypfi, evaa — all 7 on-chain plugins.
29+
30+
**Impact**: Eliminates `getAgentWallet()` pattern from every plugin. Wallet management stays centralized in the agent. Plugins only build the Cell body.
31+
32+
---
33+
34+
### `sdk.ton.getAddressObject()`
35+
36+
**Problem**: `sdk.ton.getAddress()` returns a string. But Cell builders need an `Address` object (from `@ton/core`) for `storeAddress()`. Plugins must `Address.parse(sdk.ton.getAddress())` or keep a separate wallet loading path just to get the native object.
37+
38+
**Proposal**:
39+
```js
40+
const addr = sdk.ton.getAddressObject();
41+
// Returns: Address instance from @ton/core
42+
// Can be used directly in beginCell().storeAddress(addr)
43+
```
44+
45+
**Plugins that benefit**: x1000, gaspump, sbt — any plugin that builds Cell bodies containing the agent's address.
46+
47+
---
48+
49+
### `sdk.ton.cell(fn)` / `sdk.ton.beginCell()`
50+
51+
**Problem**: Every on-chain plugin needs `@ton/core`'s `beginCell()`. Since `@ton/core` is CJS, plugins must use the `createRequire(realpathSync(process.argv[1]))` workaround — 3 lines of boilerplate that are easy to get wrong and confusing for new plugin authors.
52+
53+
**Proposal** (option A — expose builder):
54+
```js
55+
const body = sdk.ton.beginCell()
56+
.storeUint(0x94826557, 32)
57+
.storeUint(0, 64)
58+
.endCell();
59+
```
60+
61+
**Proposal** (option B — callback helper):
62+
```js
63+
const body = sdk.ton.cell(b => b
64+
.storeUint(0x94826557, 32)
65+
.storeUint(0, 64)
66+
);
67+
```
68+
69+
Option A is simpler and more flexible (plugin authors already know the `beginCell()` API from TON docs).
70+
71+
**Plugins that benefit**: All 7 on-chain plugins. Also makes the SDK self-contained — no `createRequire` needed for basic Cell building.
72+
73+
---
74+
75+
## Priority 2: Medium Impact
76+
77+
### `sdk.ton.sendRawBatch(messages[])`
78+
79+
**Problem**: Some operations need multiple messages in one transaction (e.g., deploy + initial buy, or batch claims). Currently plugins build the messages array manually.
80+
81+
**Proposal**:
82+
```js
83+
await sdk.ton.sendRawBatch([
84+
{ to: factoryAddr, value: "1.1", body: deployBody, bounce: false, stateInit },
85+
{ to: tokenAddr, value: "0.5", body: buyBody },
86+
]);
87+
```
88+
89+
**Plugins that benefit**: gaspump (deploy + register), x1000 (potential future batch ops), stormtrade (multi-position).
90+
91+
---
92+
93+
### `sdk.ton.toNano(amount)` / `sdk.ton.fromNano(amount)` — already exists but...
94+
95+
**Problem**: `sdk.ton.toNano()` exists but returns a string. On-chain Cell builders need `bigint` for `storeCoins()`. Plugins end up importing `toNano` from `@ton/ton` directly anyway.
96+
97+
**Proposal**: Ensure `sdk.ton.toNano()` returns `bigint` (or add `sdk.ton.toNanoBigInt()`).
98+
99+
---
100+
101+
### `sdk.ton.runGetMethod(address, method, args?)`
102+
103+
**Problem**: Some plugins need to call GET methods on contracts (e.g., `get_jetton_data`, `get_wallet_address`, custom methods). Currently they must create their own `TonClient` instance.
104+
105+
**Proposal**:
106+
```js
107+
const result = await sdk.ton.runGetMethod(contractAddr, "get_jetton_data");
108+
// Returns: parsed stack (numbers, addresses, cells)
109+
```
110+
111+
**Plugins that benefit**: gaspump, x1000, giftindex (on-chain order book reads), any plugin querying contract state.
112+
113+
---
114+
115+
## Priority 3: Nice to Have
116+
117+
### `sdk.ton.waitForTransaction(address, seqno, opts?)`
118+
119+
**Problem**: After sending a transaction, plugins tell users "check after ~15 seconds". There's no way to confirm the transaction landed. Every plugin repeats this pattern.
120+
121+
**Proposal**:
122+
```js
123+
const confirmed = await sdk.ton.waitForTransaction(walletAddr, seqno, {
124+
timeout: 30000, // ms, default 60s
125+
interval: 3000, // polling interval
126+
});
127+
// Returns: { success: boolean, hash?, lt? }
128+
```
129+
130+
**Plugins that benefit**: All on-chain plugins. Enables reliable "transaction confirmed" responses.
131+
132+
---
133+
134+
### `sdk.ton.estimateGas(to, value, body)`
135+
136+
**Problem**: Plugins hardcode gas amounts (0.05, 0.1, 0.15 TON). These are estimates that might be too low or wasteful as the network evolves.
137+
138+
**Proposal**:
139+
```js
140+
const gas = await sdk.ton.estimateGas(tokenAddr, "0", claimBody);
141+
// Returns: estimated TON needed (string)
142+
```
143+
144+
---
145+
146+
### `sdk.ton.constants`
147+
148+
**Problem**: Plugins import `SendMode` from `@ton/core` just to use `SendMode.PAY_GAS_SEPARATELY | SendMode.IGNORE_ERRORS`. If `sendRaw` is implemented, this becomes less needed — but useful as a general reference.
149+
150+
**Proposal**:
151+
```js
152+
sdk.ton.constants.SendMode.PAY_GAS_SEPARATELY // 1
153+
sdk.ton.constants.SendMode.IGNORE_ERRORS // 2
154+
sdk.ton.constants.JETTON_TRANSFER_OP // 0x0f8a7ea5
155+
```
156+
157+
---
158+
159+
## Summary
160+
161+
| Method | Priority | Plugins impacted | Boilerplate eliminated |
162+
|--------|----------|-----------------|----------------------|
163+
| `sendRaw()` | P1 | 7 (all on-chain) | ~30 lines per operation |
164+
| `getAddressObject()` | P1 | 3+ | `Address.parse()` calls |
165+
| `beginCell()` | P1 | 7 (all on-chain) | `createRequire` workaround |
166+
| `sendRawBatch()` | P2 | 3 | Manual message array building |
167+
| `toNano()` as bigint | P2 | 7 | Double import of toNano |
168+
| `runGetMethod()` | P2 | 4+ | Manual TonClient creation |
169+
| `waitForTransaction()` | P3 | 7 | "Check after 15s" pattern |
170+
| `estimateGas()` | P3 | 7 | Hardcoded gas amounts |
171+
| `constants` | P3 | 7 | SendMode/opcode imports |
172+
173+
**The top 3 (`sendRaw` + `getAddressObject` + `beginCell`) together would eliminate the need for plugins to ever touch `wallet.json`, `createRequire`, or `@ton/core` imports directly.** Plugin deploy.js files would shrink from ~200 lines to ~50 lines.

WebUI.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
1. ca marche comment " channel agent " cest pas vraiment clair il faut investiguer cette config

config.example.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ agent:
1818
idle_expiry_minutes: 1440 # 24 hours
1919

2020
telegram:
21+
mode: "user" # "user" (default) or "bot" — user requires phone auth, bot requires bot_token
2122
api_id: 0 # From https://my.telegram.org/apps
2223
api_hash: "YOUR_API_HASH"
2324
phone: "+1234567890" # Phone number linked to Telegram account

docs-sdk/TEMPLATE.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# HTML Template for SDK Reference Pages
2+
3+
Use this exact HTML structure for every page. Replace PLACEHOLDERS in CAPS.
4+
5+
## Sidebar HTML (same for ALL pages — add `active` class to the current page link)
6+
7+
```html
8+
<div class="nav-section"><div class="nav-section-title">Start Here</div><ul class="nav-list"><div class="nav-list-inner"><li><a href="/index.html" class="nav-link">Introduction</a></li><li><a href="installation.html" class="nav-link">Installation</a></li><li><a href="quickstart.html" class="nav-link">Quick Start</a></li><li><a href="configuration.html" class="nav-link">Configuration</a></li></div></ul></div>
9+
<div class="nav-section"><div class="nav-section-title">Understand</div><ul class="nav-list"><div class="nav-list-inner"><li><a href="architecture.html" class="nav-link">Architecture</a></li><li><a href="agentic-loop.html" class="nav-link">Agentic Loop</a></li><li><a href="memory-system.html" class="nav-link">Memory System</a></li><li><a href="security.html" class="nav-link">Security</a></li></div></ul></div>
10+
<div class="nav-section"><div class="nav-section-title">Tools</div><ul class="nav-list"><div class="nav-list-inner"><li><a href="tools-telegram.html" class="nav-link">Telegram (76)</a></li><li><a href="tools-ton.html" class="nav-link">TON Blockchain (15)</a></li><li><a href="tools-dex.html" class="nav-link">DEX Trading (10)</a></li><li><a href="tools-dns.html" class="nav-link">DNS &amp; Domains (8)</a></li><li><a href="tools-deals.html" class="nav-link">Deals &amp; Escrow (5)</a></li><li><a href="tools-other.html" class="nav-link">Utilities</a></li></div></ul></div>
11+
<div class="nav-section"><div class="nav-section-title">Configure</div><ul class="nav-list"><div class="nav-list-inner"><li><a href="multi-llm.html" class="nav-link">Multi-LLM Providers</a></li><li><a href="scheduled-tasks.html" class="nav-link">Scheduled Tasks</a></li><li><a href="webui.html" class="nav-link">WebUI Dashboard</a></li></div></ul></div>
12+
<div class="nav-section"><div class="nav-section-title">Build Plugins</div><ul class="nav-list"><div class="nav-list-inner"><li><a href="plugin-sdk.html" class="nav-link">Plugin SDK</a></li><li><a href="create-plugin.html" class="nav-link">Create a Plugin</a></li><li><a href="api-events.html" class="nav-link">Plugin Lifecycle</a></li><li><a href="mcp-servers.html" class="nav-link">MCP Servers</a></li></div></ul></div>
13+
<div class="nav-section"><div class="nav-section-title">SDK Reference</div><ul class="nav-list"><div class="nav-list-inner"><li><a href="sdk-overview.html" class="nav-link">Overview</a></li><li><a href="sdk-ton.html" class="nav-link">TON Blockchain</a></li><li><a href="sdk-dex.html" class="nav-link">DEX Trading</a></li><li><a href="sdk-dns.html" class="nav-link">DNS &amp; Domains</a></li><li><a href="sdk-telegram.html" class="nav-link">Telegram</a></li><li><a href="sdk-bot.html" class="nav-link">Bot SDK</a></li><li><a href="sdk-utilities.html" class="nav-link">Utilities</a></li><li><a href="sdk-errors.html" class="nav-link">Error Handling</a></li><li><a href="tutorial-payment-bot.html" class="nav-link">Tutorial: Payment Bot</a></li><li><a href="tutorial-dex-bot.html" class="nav-link">Tutorial: DEX Bot</a></li><li><a href="tutorial-inline-bot.html" class="nav-link">Tutorial: Inline Bot</a></li></div></ul></div>
14+
<div class="nav-section"><div class="nav-section-title">Deploy &amp; Manage</div><ul class="nav-list"><div class="nav-list-inner"><li><a href="deploy-docker.html" class="nav-link">Docker</a></li><li><a href="api-commands.html" class="nav-link">Admin Commands</a></li><li><a href="api-config.html" class="nav-link">Config Schema</a></li><li><a href="cli-reference.html" class="nav-link">CLI Reference</a></li></div></ul></div>
15+
```
16+
17+
## Full Page Skeleton
18+
19+
```html
20+
<!DOCTYPE html>
21+
<html lang="en" data-theme="light">
22+
<head>
23+
<meta charset="UTF-8">
24+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
25+
<title>PAGE_TITLE - Teleton Agent Documentation</title>
26+
<meta name="description" content="PAGE_DESCRIPTION">
27+
<link rel="icon" type="image/svg+xml" href="/assets/favicon.svg">
28+
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin>
29+
<link href="https://cdn.jsdelivr.net/npm/geist@1.3.1/dist/fonts/geist-sans/style.min.css" rel="stylesheet">
30+
<link href="https://cdn.jsdelivr.net/npm/geist@1.3.1/dist/fonts/geist-mono/style.min.css" rel="stylesheet">
31+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css" id="hljs-theme">
32+
<link rel="stylesheet" href="/css/style.css?v=5">
33+
</head>
34+
<body data-page="PAGE_ID">
35+
<div class="overlay" id="overlay"></div>
36+
<header class="header"><div class="header-inner">
37+
<button class="menu-toggle" id="menuToggle" aria-label="Toggle menu"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg></button>
38+
<a href="/index.html" class="logo"><svg viewBox="0 0 56 56" fill="none" width="28" height="28"><path d="M28 56C43.464 56 56 43.464 56 28C56 12.536 43.464 0 28 0C12.536 0 0 12.536 0 28C0 43.464 12.536 56 28 56Z" fill="#0098EA"/><path d="M37.5603 15.6277H18.4386C14.9228 15.6277 12.6944 19.4202 14.4632 22.4861L26.2644 42.9409C27.0345 44.2765 28.9644 44.2765 29.7345 42.9409L41.5381 22.4861C43.3045 19.4251 41.0761 15.6277 37.5627 15.6277H37.5603ZM26.2548 36.8068L23.6847 31.8327L17.4833 20.7414C17.0742 20.0315 17.5795 19.1218 18.4362 19.1218H26.2524V36.8092L26.2548 36.8068ZM38.5108 20.739L32.3118 31.8351L29.7417 36.8068V19.1194H37.5579C38.4146 19.1194 38.9199 20.0291 38.5108 20.739Z" fill="white"/></svg><span>Teleton Agent Docs</span></a>
39+
<div class="header-actions">
40+
<button class="search-btn" id="searchBtn" aria-label="Search"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg><span class="search-hint">Search...</span><kbd>Ctrl+K</kbd></button>
41+
<button class="lang-toggle" id="langToggle" aria-label="Toggle language">EN</button>
42+
<button class="theme-toggle" id="themeToggle" aria-label="Toggle theme"><svg class="sun-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg><svg class="moon-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg></button>
43+
<a href="https://github.com/TONresistor/teleton-agent" class="github-link" target="_blank" rel="noopener" aria-label="GitHub"><svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></a>
44+
</div>
45+
</div></header>
46+
<div class="search-modal" id="searchModal"><div class="search-modal-content"><div class="search-input-wrapper"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg><input type="text" id="searchInput" placeholder="Search documentation..." autocomplete="off"><kbd>ESC</kbd></div><div class="search-results" id="searchResults"><div class="search-empty">Start typing to search...</div></div></div></div>
47+
<div class="layout">
48+
<aside class="sidebar" id="sidebar"><nav class="sidebar-nav">
49+
SIDEBAR_HTML_HERE (with active class on current page)
50+
</nav></aside>
51+
<main class="main"><article class="content">
52+
53+
PAGE_CONTENT_HERE
54+
55+
</article></main>
56+
</div>
57+
<footer class="footer"><div class="footer-inner"><div class="footer-left"><p>Teleton Agent &copy; 2026</p></div><div class="footer-links"><a href="https://t.me/teletonagents" target="_blank">Telegram</a><a href="https://github.com/TONresistor/teleton-agent" target="_blank">GitHub</a><a href="https://teletonagent.dev" target="_blank">Website</a></div></div></footer>
58+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
59+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/typescript.min.js"></script>
60+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/bash.min.js"></script>
61+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/yaml.min.js"></script>
62+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/json.min.js"></script>
63+
<script src="/js/main.js?v=5"></script>
64+
<script src="/js/i18n.js?v=1"></script>
65+
</body>
66+
</html>
67+
```
68+
69+
## Content Patterns
70+
71+
### Method table:
72+
```html
73+
<div class="table-wrapper"><table>
74+
<thead><tr><th>Method</th><th>Returns</th><th>Description</th></tr></thead>
75+
<tbody>
76+
<tr><td><code>methodName(params)</code></td><td><code>ReturnType</code></td><td>Description text.</td></tr>
77+
</tbody>
78+
</table></div>
79+
```
80+
81+
### Code example:
82+
```html
83+
<div class="code-block"><div class="code-header"><span>Title</span></div><pre><code class="language-typescript">// code here</code></pre></div>
84+
```
85+
86+
### Section with ID (for anchor links):
87+
```html
88+
<section class="section" id="section-id">
89+
<h2>Section Title</h2>
90+
<p>Content...</p>
91+
</section>
92+
```
93+
94+
### Lead paragraph:
95+
```html
96+
<p class="lead">Intro text with <code>inline code</code>.</p>
97+
```
98+
99+
## IMPORTANT HTML Escaping Rules
100+
- Use `&lt;` for `<` and `&gt;` for `>` in type signatures inside HTML (e.g., `Promise&lt;string&gt;`)
101+
- Use `&amp;` for `&`
102+
- Use `&#x1F4B0;` etc. for emojis
103+
- Backtick code in <code> tags, NOT raw backticks

0 commit comments

Comments
 (0)