diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-05 03:25:15 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-05 03:25:15 +0300 |
commit | 55797b98a0673a792b6d0f54a4e9577799f4a9a5 (patch) | |
tree | 002619d502a4520c7ae9c9aec7f453dd53055eb1 /telegram/connect.go | |
parent | 0f047c38168949b246223dc1b1154a6969753d2e (diff) |
telegram package refactoring
Diffstat (limited to 'telegram/connect.go')
-rw-r--r-- | telegram/connect.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/telegram/connect.go b/telegram/connect.go new file mode 100644 index 0000000..72cd417 --- /dev/null +++ b/telegram/connect.go @@ -0,0 +1,36 @@ +package telegram + +import ( + "github.com/pkg/errors" + + "github.com/zelenin/go-tdlib/client" +) + +// Connect starts TDlib connection +func (c *Client) Connect() error { + if c.online { + return nil + } + + authorizer := client.ClientAuthorizer() + authorizer.TdlibParameters <- c.parameters + + tdlibClient, err := client.NewClient(authorizer, c.logVerbosity) + if err != nil { + return errors.Wrap(err, "Coudn't initialize a Telegram client instance") + } + + c.client = tdlibClient + c.online = true + + go updateHandler(c.client) + + return nil +} + +// Disconnect drops TDlib connection +func (c *Client) Disconnect() { + if !c.online { + return + } +} |