-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package telegram | ||
|
||
import ( | ||
"context" | ||
|
||
"golang.org/x/xerrors" | ||
|
||
"github.com/ernado/td/bin" | ||
"github.com/ernado/td/internal/tg" | ||
) | ||
|
||
// BotLogin wraps credentials that are required to login as bot. | ||
type BotLogin struct { | ||
// ID is api_id. | ||
ID int | ||
// Hash is api_hash. | ||
Hash string | ||
// Token is bot auth token. | ||
Token string | ||
} | ||
|
||
type authBox struct { | ||
Auth tg.AuthAuthorizationClass | ||
} | ||
|
||
func (a *authBox) Decode(b *bin.Buffer) error { | ||
v, err := tg.DecodeAuthAuthorization(b) | ||
if err != nil { | ||
return err | ||
} | ||
a.Auth = v | ||
return nil | ||
} | ||
|
||
// BotLogin performs bot authorization request. | ||
func (c *Client) BotLogin(ctx context.Context, login BotLogin) error { | ||
var res authBox | ||
if err := c.do(ctx, &tg.AuthImportBotAuthorizationRequest{ | ||
APIID: login.ID, | ||
APIHash: login.Hash, | ||
BotAuthToken: login.Token, | ||
}, &res); err != nil { | ||
return xerrors.Errorf("failed to do request: %w", err) | ||
} | ||
switch res.Auth.(type) { | ||
case *tg.AuthAuthorization: | ||
// Ok. | ||
return nil | ||
default: | ||
return xerrors.Errorf("got unexpected response %T", res.Auth) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package telegram | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/ernado/td/bin" | ||
"github.com/ernado/td/internal/mt" | ||
) | ||
|
||
func (c *Client) handleAck(b *bin.Buffer) error { | ||
var ack mt.MsgsAck | ||
if err := ack.Decode(b); err != nil { | ||
return xerrors.Errorf("failed to decode: %x", err) | ||
} | ||
c.log.With(zap.Int64s("messages", ack.MsgIds)).Debug("Ack") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters