From 55797b98a0673a792b6d0f54a4e9577799f4a9a5 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Tue, 5 Nov 2019 02:25:15 +0200 Subject: telegram package refactoring --- telegram/connect.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 telegram/connect.go (limited to 'telegram/connect.go') 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 + } +} -- cgit v1.2.3