34 lines
670 B
Go
34 lines
670 B
Go
package telegram
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
|
|
"github.com/gotd/td/tg"
|
|
)
|
|
|
|
func (t *Telegram) GetChannelPTS(ctx context.Context, channel domain.Channel) (int, error) {
|
|
req := []tg.InputDialogPeerClass{
|
|
&tg.InputDialogPeer{
|
|
Peer: &tg.InputPeerChannel{
|
|
ChannelID: channel.ChannelID(),
|
|
AccessHash: channel.AccessHash,
|
|
},
|
|
},
|
|
}
|
|
|
|
dialogs, err := t.API().MessagesGetPeerDialogs(ctx, req)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("peer dialogs: %w", err)
|
|
}
|
|
|
|
if len(dialogs.Dialogs) > 0 {
|
|
if d, ok := dialogs.Dialogs[0].(*tg.Dialog); ok {
|
|
return d.Pts, nil
|
|
}
|
|
}
|
|
|
|
return 0, nil
|
|
}
|