aboutsummaryrefslogtreecommitdiff
path: root/telegram/connect.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-08-15 13:10:29 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-08-15 13:10:29 +0300
commite9e65b6778d52cf140247bf2f548c5e698183c1d (patch)
treee28aa1f9774d3281fbcdcbe1022458678afecf50 /telegram/connect.go
parent0c71036148b0327db6f05f5d1a8d878be86f72c9 (diff)
Registration support
Diffstat (limited to 'telegram/connect.go')
-rw-r--r--telegram/connect.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/telegram/connect.go b/telegram/connect.go
index 37f719e..ed0a46b 100644
--- a/telegram/connect.go
+++ b/telegram/connect.go
@@ -18,6 +18,9 @@ type clientAuthorizer struct {
Code chan string
State chan client.AuthorizationState
Password chan string
+ FirstName chan string
+ LastName chan string
+ isClosed bool
}
func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.AuthorizationState) error {
@@ -52,7 +55,11 @@ func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.Auth
return err
case client.TypeAuthorizationStateWaitRegistration:
- return client.ErrNotSupportedAuthorizationState
+ _, err := c.RegisterUser(&client.RegisterUserRequest{
+ FirstName: <-stateHandler.FirstName,
+ LastName: <-stateHandler.LastName,
+ })
+ return err
case client.TypeAuthorizationStateWaitPassword:
_, err := c.CheckAuthenticationPassword(&client.CheckAuthenticationPasswordRequest{
@@ -77,11 +84,14 @@ func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.Auth
}
func (stateHandler *clientAuthorizer) Close() {
+ stateHandler.isClosed = true
close(stateHandler.TdlibParameters)
close(stateHandler.PhoneNumber)
close(stateHandler.Code)
close(stateHandler.State)
close(stateHandler.Password)
+ close(stateHandler.FirstName)
+ close(stateHandler.LastName)
}
// Connect starts TDlib connection
@@ -102,6 +112,8 @@ func (c *Client) Connect(resource string) error {
Code: make(chan string, 1),
State: make(chan client.AuthorizationState, 10),
Password: make(chan string, 1),
+ FirstName: make(chan string, 1),
+ LastName: make(chan string, 1),
}
c.locks.authorizationReady.Add(1)
@@ -212,6 +224,10 @@ func (c *Client) interactor() {
case client.TypeAuthorizationStateWaitCode:
log.Warn("Waiting for authorization code...")
gateway.SendMessage(c.jid, "", "Please, enter authorization code via /code 12345", c.xmpp)
+ // stage 1b: wait for registration
+ case client.TypeAuthorizationStateWaitRegistration:
+ log.Warn("Waiting for full name...")
+ gateway.SendMessage(c.jid, "", "This number is not registered yet! Please, enter your name via /setname John Doe", c.xmpp)
// stage 2: wait for 2fa
case client.TypeAuthorizationStateWaitPassword:
log.Warn("Waiting for 2FA password...")