go version: go version go1.17.2 darwin/amd64
td version: v0.55.2
var MTProtoMap map[string]*telegram.Client = make(map[string]*telegram.Client)
func TInit(phone string, apiId int, apiHash string) *telegram.Client {
client := telegram.NewClient(apiId, apiHash, telegram.Options{
SessionStorage: &RedisStorage{
phone: phone,
},
})
bg.Connect(client)
MTProtoMap[phone] = client
return client
}
func Of(phone string, apiId int, apiHash string) *telegram.Client {
client := MTProtoMap[phone]
if nil == client {
client = TInit(phone, apiId, apiHash)
}
return client
}
func CheckResult(a tg.AuthAuthorizationClass) (*tg.AuthAuthorization, error) {
switch a := a.(type) {
case *tg.AuthAuthorization:
return a, nil // ok
case *tg.AuthAuthorizationSignUpRequired:
return nil, &auth.SignUpRequired{
TermsOfService: a.TermsOfService,
}
default:
return nil, errors.Errorf("got unexpected response %T", a)
}
}
func TVerifiedCode(phone string, apiId int, apiHash string, code string, phoneCodeHash string) (*tg.AuthAuthorization, error) {
client := Of(phone, apiId, apiHash)
authAuthorization, err := client.API().AuthSignIn(context.Background(), &tg.AuthSignInRequest{
PhoneNumber: phone,
PhoneCodeHash: phoneCodeHash,
PhoneCode: code,
})
if err != nil {
return nil, err
}
return CheckResult(authAuthorization)
}
client.API().AuthSignIn not responding
Pay 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