Documentation ¶
Overview ¶
Package middleware wraps some useful middlewares for telegram.
Example ¶
package main import ( "context" "time" "golang.org/x/time/rate" "github.com/gotd/td/telegram" "github.com/gotd/td/tg" "github.com/johnnyipcom/gotd-contrib/middleware/floodwait" "github.com/johnnyipcom/gotd-contrib/middleware/ratelimit" ) func main() { // Create a new telegram.Client instance that handles FLOOD_WAIT errors // and limits request rate to 10 Hz with max burst size of 5 request. // // Note that you must not use test app credentials in production. // See https://core.telegram.org/api/obtaining_api_id client := telegram.NewClient( telegram.TestAppID, telegram.TestAppHash, telegram.Options{ Middlewares: []telegram.Middleware{ floodwait.NewSimpleWaiter().WithMaxRetries(10), ratelimit.New(rate.Every(100*time.Millisecond), 5), }, }, ) api := tg.NewClient(client) ctx := context.TODO() err := client.Run(ctx, func(ctx context.Context) error { _, err := api.ContactsResolveUsername(ctx, "@self") return err }) if err != nil { panic(err) } }
Output:
Directories ¶
Path | Synopsis |
---|---|
Package floodwait implements a tg.Invoker that handles flood wait errors.
|
Package floodwait implements a tg.Invoker that handles flood wait errors. |
Package ratelimit implements a tg.Invoker that limits request rate.
|
Package ratelimit implements a tg.Invoker that limits request rate. |
Package tg_prom implements middleware for prometheus metrics.
|
Package tg_prom implements middleware for prometheus metrics. |
Click to show internal directories.
Click to hide internal directories.