authorizationStateHandler State is empty
FunkyYang opened this issue · 25 comments
I create td lib client when program start and receive auth code when try login my account,but authorizationStateHandler State is empty when I login again with auth code ,how to fix it ?
when does client re auth authorizationStateHandler
The same question ,
Sloved solution: go-tdlib: Use https://github.com/zelenin/go-tdlib/tree/v0.6.0 and tdlib: https://github.com/tdlib/td use 1.8.0
Because the https://github.com/tdlib/td 1.8.0 is the official release branch,
use last lib version + supported tdlib version and check demo - it is working
lib v0.6.0 , td v1.8.0 and the demo works well.
but in my program I receive TypeAuthorizationStateWaitTdlibParameters first and I send tdlIbParamters soon,receive TypeAuthorizationStateWaitEncryptionKey at that time and authorizationStateHandler State is empty then
not sure ,you can put on your code here ,let's find what may contains
func (t *Instance) Login() (int, error) {
for {
select {
case state, ok := <-t.authorization.State:
if !ok {
continue
}
switch state.AuthorizationStateType() {
case client.TypeAuthorizationStateWaitTdlibParameters:
apiId64, _ := strconv.ParseInt(t.apiId, 10, 32)
t.authorization.TDLibParameters <- &client.TdlibParameters{
UseTestDc: false,
DatabaseDirectory: filepath.Join(t.rootDir, t.name, "db"),
FilesDirectory: filepath.Join(t.rootDir, t.name, "files"),
UseFileDatabase: true,
UseChatInfoDatabase: true,
UseMessageDatabase: true,
UseSecretChats: false,
ApiId: int32(apiId64),
ApiHash: t.apiHash,
SystemLanguageCode: t.tdConf.TDLib.SystemLanguage,
DeviceModel: t.tdConf.TDLib.DeviceModel,
SystemVersion: t.tdConf.TDLib.SystemVersion,
ApplicationVersion: t.tdConf.TDLib.ApplicationVersion,
EnableStorageOptimizer: true,
IgnoreFileNames: false,
}
case client.TypeAuthorizationStateWaitPhoneNumber:
t.authorization.PhoneNumber <- t.name
case client.TypeAuthorizationStateWaitCode:
select {
case code := <-t.codeChan:
t.authorization.Code <- code
default:
return 1, fmt.Errorf("please enter a code")
}
case client.TypeAuthorizationStateWaitPassword:
t.authorization.Password <- t.password
case client.TypeAuthorizationStateReady:
t.state = account.StateRunning
cmd := &account.SetTwoCmd{Name: t.name, WorkStatus: t.state, LastLoginTime: time.Now().Unix()}
if err := t.SetRemote(cmd); err != nil {
return -1, err
}
return 0, nil
}
}
}
}
that is my code,when I create instance I new a client
authorization := NewAuthorization()
tdInstance.authorization = authorization
go func() {
tdLibClient, err := client.NewClient(authorization)
if err != nil {
log.Printf("init tdlibClient error,reason:%s", err.Error())
} else {
tdInstance.client = tdLibClient
}
}()
and authorization
copy from clientAuthorization
in demo
and Last day I use lib v0.7.0 and td lib v1.8.18 and first can work(receive a code from telegram) and provide code to td lib did't work
did't work at all today
the CliInteractor() is a go routine methods, client.CliInteractor(authorizer), your login routine should after this routine
I see .but when I try to login,receive a auth code first.I have no idea after that .
it means I need receive a response when I login .and use that response complete the rest of thing
and login logical in client.CliInteractor(authorizer)
Do you go client.CliInteractor(authorizer)
?
above Login()
should be properly placed ,make sure every Login() receive state after client.CliInteractor(authorizer)
when I Login must new a client?
no ,but each client should has his own login info ,
I dont have any idea
func NewClient(authorizationStateHandler AuthorizationStateHandler, options ...Option) (*Client, error) {
client := &Client{
jsonClient: NewJsonClient(),
responses: make(chan *Response, 1000),
listenerStore: newListenerStore(),
catchersStore: &sync.Map{},
}
client.extraGenerator = UuidV4Generator()
client.catchTimeout = 60 * time.Second
for _, option := range options {
option(client)
}
tdlibInstance.addClient(client)
go client.receiver()
err := Authorize(client, authorizationStateHandler)
if err != nil {
return nil, err
}
return client, nil
}
I need client without execute Authorize
work now?
good news.I edit my program and first I can receive a auth code .but second I provide auth code difficult because can't execute client.newClient(author)
twice so authorizationStateHandler State is empt