Skip to content

Commit d098b9a

Browse files
ernadoclaude
andcommitted
docs(guide): add full usage guide; mark Phase 7 done
Add docs/guide.md — a practical tour of the whole surface (sending, formatting, keyboards, media, handlers, predicates, middleware, groups, commands, callback/inline queries, editing, files, chat management, errors, resilience, persistence, pooling, escape hatch). Refresh the README usage section to the typed API and link the guide and examples. Mark Phase 7 complete in the roadmap (pool, examples incl. advanced, benchmarks, conformance test, docs). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e89d80a commit d098b9a

3 files changed

Lines changed: 383 additions & 26 deletions

File tree

README.md

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,57 +41,43 @@ In priority order (see [`docs/architecture.md`](./docs/architecture.md)):
4141

4242
## Usage
4343

44-
> The high-level typed methods are still being built. Today you get the `Bot`
45-
> lifecycle plus the raw `gotd/td` client and message sender.
46-
4744
```go
4845
package main
4946

5047
import (
5148
"context"
5249

5350
"github.com/gotd/botapi"
54-
"github.com/gotd/botapi/storage"
55-
"github.com/gotd/td/tg"
56-
"go.etcd.io/bbolt"
57-
"go.uber.org/zap"
5851
)
5952

6053
func main() {
61-
ctx := context.Background()
62-
63-
db, err := bbolt.Open("bot.bbolt", 0o600, nil)
64-
if err != nil {
65-
panic(err)
66-
}
67-
defer db.Close()
68-
6954
// Bots still need an MTProto app identity (https://my.telegram.org).
7055
// This is NOT the bot token.
7156
bot, err := botapi.New("<bot-token>", botapi.Options{
7257
AppID: 123456,
7358
AppHash: "<app-hash>",
74-
Logger: zap.NewExample(),
75-
Storage: storage.NewBBoltStorage(db),
7659
})
7760
if err != nil {
7861
panic(err)
7962
}
8063

81-
// Register raw MTProto update handlers on the dispatcher (the typed
82-
// handler framework is built on top of this in a later phase).
83-
bot.Dispatcher().OnNewMessage(func(ctx context.Context, e tg.Entities, u *tg.UpdateNewMessage) error {
84-
// ... use bot.Sender() to reply ...
85-
return nil
64+
bot.OnCommand("start", "Start the bot", func(c *botapi.Context) error {
65+
_, err := c.Reply("Hello!")
66+
return err
8667
})
8768

8869
// Connects, authorizes as a bot, and serves updates until ctx is cancelled.
89-
if err := bot.Run(ctx); err != nil {
70+
if err := bot.Run(context.Background()); err != nil {
9071
panic(err)
9172
}
9273
}
9374
```
9475

76+
See the [**guide**](./docs/guide.md) for the full surface (sending, media,
77+
keyboards, handlers, predicates, middleware, commands, files, chat management,
78+
errors, pooling) and [`examples/`](./examples) for runnable bots
79+
(`echo`, `buttons`, `inline`, `media`, `advanced`).
80+
9581
`Options.Storage` is optional — leave it nil to keep session, peers and update
9682
state in memory (nothing survives a restart). `storage.BBoltStorage` persists
9783
all of it to a single bbolt file.

0 commit comments

Comments
 (0)