-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #672 from tdakkota/fix/participants-iterator
fix(participants): checking of the last batch
- Loading branch information
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package peers_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/gotd/td/telegram" | ||
"github.com/gotd/td/telegram/peers" | ||
"github.com/gotd/td/telegram/updates" | ||
"github.com/gotd/td/tg" | ||
) | ||
|
||
func ExampleManager() { | ||
logger := zap.NewExample() | ||
|
||
var ( | ||
dispatcher = tg.NewUpdateDispatcher() | ||
h telegram.UpdateHandler | ||
) | ||
client, err := telegram.ClientFromEnvironment(telegram.Options{ | ||
Logger: logger.Named("client"), | ||
UpdateHandler: telegram.UpdateHandlerFunc(func(ctx context.Context, u tg.UpdatesClass) error { | ||
return h.Handle(ctx, u) | ||
}), | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
peerManager := peers.Options{ | ||
Logger: logger, | ||
}.Build(client.API()) | ||
gaps := updates.New(updates.Config{ | ||
Handler: dispatcher, | ||
AccessHasher: peerManager, | ||
Logger: logger.Named("gaps"), | ||
}) | ||
h = peerManager.UpdateHook(gaps) | ||
|
||
if err := client.Run(context.TODO(), func(ctx context.Context) error { | ||
if err := peerManager.Init(ctx); err != nil { | ||
return err | ||
} | ||
u, err := peerManager.Self(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, isBot := u.ToBot() | ||
if err := gaps.Auth(ctx, client.API(), u.ID(), isBot, false); err != nil { | ||
return err | ||
} | ||
defer gaps.Logout() | ||
|
||
p, err := peerManager.Resolve(ctx, "durov") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
username, _ := p.Username() | ||
fmt.Println(username) | ||
return nil | ||
}); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters