func main() {
sessionPath := "session_phone.json"
storage := &session.FileStorage{Path: sessionPath}
client := telegram.NewClient(appID, appHash, telegram.Options{SessionStorage: storage})
err := client.Run(context.Background(), func(ctx context.Context) error {
authCli := client.Auth()
status, err := authCli.Status(ctx)
if err != nil {
log.Fatal(err)
}
if !status.Authorized {
phoneNumber := "+"
code, err := authCli.SendCode(ctx, phoneNumber, auth.SendCodeOptions{
AllowAppHash: true,
})
if err != nil {
return fmt.Errorf("failed to send code: %w", err)
}
sentCode := code.(*tg.AuthSentCode)
var receivedCode string
fmt.Print("Enter the code you received: ")
fmt.Scanln(&receivedCode)
_, err = authCli.SignIn(ctx, phoneNumber, sentCode.PhoneCodeHash, receivedCode)
if err != nil {
log.Fatal(err)
}
fmt.Println("Successfully logged in!")
}
return nil
})
if err != nil {
log.Fatalf("Failed to run Telegram client: %v", err)
}
}
The verification code can be received, and the parameters passed are correct. PHONE_CODE_EMPTY is still reportedPay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too