parent
0f047c3816
commit
55797b98a0
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in new issue