fixed nonauth client

This commit is contained in:
divyam234 2023-08-25 16:00:46 +05:30
parent 20bca7952e
commit ca06088900
2 changed files with 109 additions and 102 deletions

View file

@ -246,9 +246,9 @@ func (as *AuthService) HandleMultipleLogin(c *gin.Context) {
dispatcher := tg.NewUpdateDispatcher()
loggedIn := qrlogin.OnLoginToken(dispatcher)
sessionStorage := &session.StorageMemory{}
tgClient := utils.GetNonAuthClient(dispatcher, sessionStorage)
tgClient, stop, _ := utils.StartNonAuthClient(dispatcher, sessionStorage)
tgClient.Run(c, func(ctx context.Context) error {
defer stop()
for {
message := &SocketMessage{}
@ -256,7 +256,7 @@ func (as *AuthService) HandleMultipleLogin(c *gin.Context) {
if err != nil {
log.Println(err)
return err
return
}
if message.AuthType == "qr" {
go func() {
@ -343,6 +343,5 @@ func (as *AuthService) HandleMultipleLogin(c *gin.Context) {
}()
}
}
})
}

View file

@ -115,17 +115,25 @@ func GetAuthClient(ctx context.Context, sessionStr string, userId int64) (*teleg
return client, nil
}
func GetNonAuthClient(handler telegram.UpdateHandler, storage telegram.SessionStorage) *telegram.Client {
func StartNonAuthClient(handler telegram.UpdateHandler, storage telegram.SessionStorage) (*telegram.Client, bg.StopFunc, error) {
middlewares := []telegram.Middleware{}
if config.RateLimit {
middlewares = append(middlewares, ratelimit.New(rate.Every(time.Millisecond*100), 5))
}
client := telegram.NewClient(config.AppId, config.AppHash, telegram.Options{
SessionStorage: storage,
Middlewares: middlewares,
Device: getDeviceConfig(),
UpdateHandler: handler,
ReconnectionBackoff: reconnectionBackoff,
RetryInterval: 5 * time.Second,
MaxRetries: 5,
})
return client
stop, err := bg.Connect(client)
if err != nil {
return nil, nil, err
}
return client, stop, nil
}
func startBotClient(ctx context.Context, client *telegram.Client, token string) (bg.StopFunc, error) {