package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type MessagesGetWebPagePreviewRequest struct {
Flags bin .Fields
Message string
Entities []MessageEntityClass
}
const MessagesGetWebPagePreviewRequestTypeID = 0x8b68b0cc
var (
_ bin .Encoder = &MessagesGetWebPagePreviewRequest {}
_ bin .Decoder = &MessagesGetWebPagePreviewRequest {}
_ bin .BareEncoder = &MessagesGetWebPagePreviewRequest {}
_ bin .BareDecoder = &MessagesGetWebPagePreviewRequest {}
)
func (g *MessagesGetWebPagePreviewRequest ) Zero () bool {
if g == nil {
return true
}
if !(g .Flags .Zero ()) {
return false
}
if !(g .Message == "" ) {
return false
}
if !(g .Entities == nil ) {
return false
}
return true
}
func (g *MessagesGetWebPagePreviewRequest ) String () string {
if g == nil {
return "MessagesGetWebPagePreviewRequest(nil)"
}
type Alias MessagesGetWebPagePreviewRequest
return fmt .Sprintf ("MessagesGetWebPagePreviewRequest%+v" , Alias (*g ))
}
func (g *MessagesGetWebPagePreviewRequest ) FillFrom (from interface {
GetMessage () (value string )
GetEntities () (value []MessageEntityClass , ok bool )
}) {
g .Message = from .GetMessage ()
if val , ok := from .GetEntities (); ok {
g .Entities = val
}
}
func (*MessagesGetWebPagePreviewRequest ) TypeID () uint32 {
return MessagesGetWebPagePreviewRequestTypeID
}
func (*MessagesGetWebPagePreviewRequest ) TypeName () string {
return "messages.getWebPagePreview"
}
func (g *MessagesGetWebPagePreviewRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messages.getWebPagePreview" ,
ID : MessagesGetWebPagePreviewRequestTypeID ,
}
if g == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Message" ,
SchemaName : "message" ,
},
{
Name : "Entities" ,
SchemaName : "entities" ,
Null : !g .Flags .Has (3 ),
},
}
return typ
}
func (g *MessagesGetWebPagePreviewRequest ) SetFlags () {
if !(g .Entities == nil ) {
g .Flags .Set (3 )
}
}
func (g *MessagesGetWebPagePreviewRequest ) Encode (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't encode messages.getWebPagePreview#8b68b0cc as nil" )
}
b .PutID (MessagesGetWebPagePreviewRequestTypeID )
return g .EncodeBare (b )
}
func (g *MessagesGetWebPagePreviewRequest ) EncodeBare (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't encode messages.getWebPagePreview#8b68b0cc as nil" )
}
g .SetFlags ()
if err := g .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.getWebPagePreview#8b68b0cc: field flags: %w" , err )
}
b .PutString (g .Message )
if g .Flags .Has (3 ) {
b .PutVectorHeader (len (g .Entities ))
for idx , v := range g .Entities {
if v == nil {
return fmt .Errorf ("unable to encode messages.getWebPagePreview#8b68b0cc: field entities element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.getWebPagePreview#8b68b0cc: field entities element with index %d: %w" , idx , err )
}
}
}
return nil
}
func (g *MessagesGetWebPagePreviewRequest ) Decode (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't decode messages.getWebPagePreview#8b68b0cc to nil" )
}
if err := b .ConsumeID (MessagesGetWebPagePreviewRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode messages.getWebPagePreview#8b68b0cc: %w" , err )
}
return g .DecodeBare (b )
}
func (g *MessagesGetWebPagePreviewRequest ) DecodeBare (b *bin .Buffer ) error {
if g == nil {
return fmt .Errorf ("can't decode messages.getWebPagePreview#8b68b0cc to nil" )
}
{
if err := g .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.getWebPagePreview#8b68b0cc: field flags: %w" , err )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode messages.getWebPagePreview#8b68b0cc: field message: %w" , err )
}
g .Message = value
}
if g .Flags .Has (3 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.getWebPagePreview#8b68b0cc: field entities: %w" , err )
}
if headerLen > 0 {
g .Entities = make ([]MessageEntityClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeMessageEntity (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.getWebPagePreview#8b68b0cc: field entities: %w" , err )
}
g .Entities = append (g .Entities , value )
}
}
return nil
}
func (g *MessagesGetWebPagePreviewRequest ) GetMessage () (value string ) {
if g == nil {
return
}
return g .Message
}
func (g *MessagesGetWebPagePreviewRequest ) SetEntities (value []MessageEntityClass ) {
g .Flags .Set (3 )
g .Entities = value
}
func (g *MessagesGetWebPagePreviewRequest ) GetEntities () (value []MessageEntityClass , ok bool ) {
if g == nil {
return
}
if !g .Flags .Has (3 ) {
return value , false
}
return g .Entities , true
}
func (g *MessagesGetWebPagePreviewRequest ) MapEntities () (value MessageEntityClassArray , ok bool ) {
if !g .Flags .Has (3 ) {
return value , false
}
return MessageEntityClassArray (g .Entities ), true
}
func (c *Client ) MessagesGetWebPagePreview (ctx context .Context , request *MessagesGetWebPagePreviewRequest ) (MessageMediaClass , error ) {
var result MessageMediaBox
if err := c .rpc .Invoke (ctx , request , &result ); err != nil {
return nil , err
}
return result .MessageMedia , nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .