types

package
v1.0.0-beta24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InputMediaFromFileID

func InputMediaFromFileID(fileIDStr string, caption string) (tg.InputMediaClass, error)

InputMediaFromFileID creates tg.InputMediaClass from an encoded fileID string. Uses the official github.com/gotd/td/fileid package for decoding. Returns an error if the fileID is invalid or the file type is unsupported.

The fileID should be obtained from a previous Message's FileID(), Document().FileID(), or Photo().FileID() method.

Example:

fileID := msg.FileID()
inputMedia, err := types.InputMediaFromFileID(fileID, "Check this out!")
if err != nil {
    return err
}
ctx.SendMedia(chatID, &tg.MessagesSendMediaRequest{
    Media: inputMedia,
})

Types

type AnswerOpts

type AnswerOpts struct {
	// CacheTime is the maximum time in seconds that the results may be cached on Telegram's servers.
	// Defaults to 300 (5 minutes) if not specified.
	CacheTime int
	// IsPersonal indicates whether the results should be cached only for the requesting user.
	// If true, results won't be shared with other users who send the same query.
	IsPersonal bool
	// NextOffset is the offset that will be passed to the next inline query when the user scrolls.
	// Pass an empty string if there are no more results or pagination is not supported.
	NextOffset string
	// SwitchPm instructs the client to display a button that switches the user to a private chat
	// with the bot and sends a start message.
	SwitchPm tg.InlineBotSwitchPM
	// SwitchWebview instructs the client to display a button that opens a Web App.
	SwitchWebview tg.InlineBotWebView
}

AnswerOpts contains optional parameters for answering inline queries.

type Channel

type Channel struct {
	tg.Channel
	Ctx         context.Context
	RawClient   *tg.Client
	PeerStorage *storage.PeerStorage
	SelfID      int64
}

Channel implements EffectiveChat interface for tg.Channel chats.

func (*Channel) GetAccessHash

func (u *Channel) GetAccessHash() int64

GetAccessHash returns the access hash for API authentication.

func (*Channel) GetChat

func (c *Channel) GetChat() (tg.ChatClass, error)

GetChat returns the basic chat information for this channel. Returns tg.ChatClass which can be type-asserted to *tg.Channel.

func (c *Channel) GetChatInviteLink(req ...*tg.MessagesExportChatInviteRequest) (*tg.ExportedChatInviteClass, error)

GetChatInviteLink generates an invite link for this channel.

Parameters:

  • req: Telegram's MessagesExportChatInviteRequest (use &tg.MessagesExportChatInviteRequest{} for default)

Returns exported chat invite or an error.

func (*Channel) GetChatMember

func (c *Channel) GetChatMember(userID int64) (tg.ChannelParticipantClass, error)

GetChatMember fetches information about a specific member of this channel. Returns tg.ChannelParticipantClass with the member information.

func (*Channel) GetChatMembers

func (c *Channel) GetChatMembers(opts ...*functions.GetChatMembersOpts) ([]*Participant, error)

func (*Channel) GetID

func (u *Channel) GetID() int64

GetID returns the channel ID in TDLib format. The ID is encoded with the channel prefix for proper peer identification.

func (*Channel) GetInputChannel

func (v *Channel) GetInputChannel() tg.InputChannelClass

GetInputChannel returns the InputChannel for API calls.

func (*Channel) GetInputPeer

func (v *Channel) GetInputPeer() tg.InputPeerClass

GetInputPeer returns the InputPeer for API calls.

func (*Channel) GetInputUser

func (*Channel) GetInputUser() tg.InputUserClass

GetInputUser returns the InputUser for this peer. Always returns nil for Channel (channels are not users).

func (*Channel) IsChannel

func (*Channel) IsChannel() bool

IsChannel returns true if this effective chat is a channel. Always returns true for Channel.

func (*Channel) IsChat

func (*Channel) IsChat() bool

IsChat returns true if this effective chat is a group chat. Always returns false for Channel.

func (*Channel) IsUser

func (*Channel) IsUser() bool

IsUser returns true if this effective chat is a user (private chat). Always returns false for Channel.

func (*Channel) Raw

func (c *Channel) Raw() *tg.Channel

Raw returns the underlying tg.Channel struct.

func (*Channel) SendMedia

func (c *Channel) SendMedia(media tg.InputMediaClass, opts ...any) (*Message, error)

SendMedia sends media to this channel. Opts can be:

  • string (caption parse mode): "HTML", "Markdown", "MarkdownV2", or ""
  • []tg.MessageEntityClass (raw caption entities)
  • struct with fields: Caption, ParseMode, Markup, Silent

func (*Channel) SendMessage

func (c *Channel) SendMessage(text string, opts ...any) (*Message, error)

SendMessage sends a message to this channel. Opts can be:

  • string (parse mode): "HTML", "Markdown", "MarkdownV2", or ""
  • []tg.MessageEntityClass (raw entities for backward compatibility)
  • struct with fields: ParseMode, NoWebpage, Silent, Markup

type Chat

type Chat struct {
	tg.Chat
	Ctx         context.Context
	RawClient   *tg.Client
	PeerStorage *storage.PeerStorage
	SelfID      int64
}

Chat implements EffectiveChat interface for tg.Chat chats.

func (*Chat) GetAccessHash

func (*Chat) GetAccessHash() int64

GetAccessHash returns the access hash for API authentication. Always returns 0 for Chat (group chats don't use access hashes).

func (*Chat) GetChat

func (c *Chat) GetChat() (tg.ChatClass, error)

GetChat returns the basic chat information for this chat. Returns tg.ChatClass which can be type-asserted to *tg.Chat.

func (c *Chat) GetChatInviteLink(req ...*tg.MessagesExportChatInviteRequest) (*tg.ExportedChatInviteClass, error)

GetChatInviteLink generates an invite link for this chat.

Parameters:

  • req: Telegram's MessagesExportChatInviteRequest (use &tg.MessagesExportChatInviteRequest{} for default)

Returns exported chat invite or an error.

func (*Chat) GetChatMembers

func (c *Chat) GetChatMembers(opts ...*functions.GetChatMembersOpts) ([]*Participant, error)

func (*Chat) GetID

func (u *Chat) GetID() int64

GetID returns the chat ID in TDLib format. The ID is encoded with the chat prefix for proper peer identification.

func (*Chat) GetInputChannel

func (*Chat) GetInputChannel() tg.InputChannelClass

GetInputChannel returns the InputChannel for this peer. Always returns nil for Chat (chats are not channels).

func (*Chat) GetInputPeer

func (v *Chat) GetInputPeer() tg.InputPeerClass

GetInputPeer returns the InputPeer for API calls.

func (*Chat) GetInputUser

func (*Chat) GetInputUser() tg.InputUserClass

GetInputUser returns the InputUser for this peer. Always returns nil for Chat (chats are not users).

func (*Chat) IsChannel

func (*Chat) IsChannel() bool

IsChannel returns true if this effective chat is a channel. Always returns false for Chat.

func (*Chat) IsChat

func (*Chat) IsChat() bool

IsChat returns true if this effective chat is a group chat. Always returns true for Chat.

func (*Chat) IsUser

func (*Chat) IsUser() bool

IsUser returns true if this effective chat is a user (private chat). Always returns false for Chat.

func (*Chat) Raw

func (c *Chat) Raw() *tg.Chat

Raw returns the underlying tg.Chat struct.

type ChosenInlineResult

type ChosenInlineResult struct {
	*tg.UpdateBotInlineSend
	Ctx         context.Context
	RawClient   *tg.Client
	PeerStorage *storage.PeerStorage
	SelfID      int64
	Entities    *tg.Entities
}

ChosenInlineResult represents a chosen inline query result with bound context. It wraps tg.UpdateBotInlineSend and provides convenience methods for accessing user information and the inline message for editing.

func ConstructChosenInlineResultWithContext

func ConstructChosenInlineResultWithContext(cir *tg.UpdateBotInlineSend, ctx context.Context, raw *tg.Client, peerStorage *storage.PeerStorage, selfID int64, entities *tg.Entities) *ChosenInlineResult

ConstructChosenInlineResultWithContext creates a ChosenInlineResult with full context binding.

func (*ChosenInlineResult) GetGeo

func (cir *ChosenInlineResult) GetGeo() tg.GeoPointClass

GetGeo returns the user's location if they shared it, nil otherwise.

func (*ChosenInlineResult) GetInlineMessageID

func (cir *ChosenInlineResult) GetInlineMessageID() tg.InputBotInlineMessageIDClass

GetInlineMessageID returns the inline message ID if available. This can be used to edit the sent inline message.

func (*ChosenInlineResult) GetUser

func (cir *ChosenInlineResult) GetUser() *User

GetUser returns the User who chose this inline result.

func (*ChosenInlineResult) GetUserID

func (cir *ChosenInlineResult) GetUserID() int64

GetUserID returns the ID of the user who chose this result.

func (*ChosenInlineResult) HasGeo

func (cir *ChosenInlineResult) HasGeo() bool

HasGeo returns true if the user shared their location.

func (*ChosenInlineResult) HasInlineMessageID

func (cir *ChosenInlineResult) HasInlineMessageID() bool

HasInlineMessageID returns true if an inline message ID is available for editing.

func (*ChosenInlineResult) Query

func (cir *ChosenInlineResult) Query() string

Query returns the query that was used to obtain this result.

func (*ChosenInlineResult) Raw

Raw returns the underlying tg.UpdateBotInlineSend struct.

func (*ChosenInlineResult) ResultID

func (cir *ChosenInlineResult) ResultID() string

ResultID returns the unique identifier of the chosen result.

type Document

type Document struct {
	*tg.Document
}

Document wraps tg.Document with helper methods. It provides a FileID() method that returns a base64url encoded file identifier compatible with the Bot API format.

func NewDocument

func NewDocument(doc *tg.Document) *Document

NewDocument creates a new Document wrapper from a tg.Document. Returns nil if the input document is nil.

func (*Document) FileID

func (d *Document) FileID() string

FileID returns an encoded Bot API file ID string for this document. Uses the official github.com/gotd/td/fileid package for encoding. Returns empty string if the document is nil.

Example:

doc := msg.Document()
if doc != nil {
    fileID := doc.FileID()
    if fileID != "" {
        fmt.Printf("Document FileID: %s\n", fileID)
    }
}

type EffectiveChat

type EffectiveChat interface {
	GetID() int64
	GetAccessHash() int64
	IsChannel() bool
	IsChat() bool
	IsUser() bool
	GetInputUser() tg.InputUserClass
	GetInputChannel() tg.InputChannelClass
	GetInputPeer() tg.InputPeerClass
}

EffectiveChat interface covers the all three types of chats: - tg.User - tg.Chat - tg.Channel

This interface is implemented by the following structs: - User: If the chat is a tg.User then this struct will be returned. - Chat: if the chat is a tg.Chat then this struct will be returned. - Channel: if the chat is a tg.Channel then this struct will be returned. - EmptyUC: if the PeerID doesn't match any of the above cases then EmptyUC struct is returned.

type EmptyUC

type EmptyUC struct{}

EmptyUC implements EffectiveChat interface for empty chats.

func (*EmptyUC) GetAccessHash

func (*EmptyUC) GetAccessHash() int64

GetAccessHash returns the access hash for API authentication. Always returns 0 for EmptyUC.

func (*EmptyUC) GetID

func (*EmptyUC) GetID() int64

GetID returns the chat ID. Always returns 0 for EmptyUC.

func (*EmptyUC) GetInputChannel

func (*EmptyUC) GetInputChannel() tg.InputChannelClass

GetInputChannel returns the InputChannel for this peer. Always returns nil for EmptyUC.

func (*EmptyUC) GetInputPeer

func (*EmptyUC) GetInputPeer() tg.InputPeerClass

GetInputPeer returns the InputPeer for this peer. Always returns nil for EmptyUC.

func (*EmptyUC) GetInputUser

func (*EmptyUC) GetInputUser() tg.InputUserClass

GetInputUser returns the InputUser for this peer. Always returns nil for EmptyUC.

func (*EmptyUC) IsChannel

func (*EmptyUC) IsChannel() bool

IsChannel returns true if this effective chat is a channel. Always returns false for EmptyUC.

func (*EmptyUC) IsChat

func (*EmptyUC) IsChat() bool

IsChat returns true if this effective chat is a group chat. Always returns false for EmptyUC.

func (*EmptyUC) IsUser

func (*EmptyUC) IsUser() bool

IsUser returns true if this effective chat is a user (private chat). Always returns false for EmptyUC.

type InlineQuery

type InlineQuery struct {
	*tg.UpdateBotInlineQuery
	// Context fields for bound methods
	Ctx         context.Context
	RawClient   *tg.Client
	PeerStorage *storage.PeerStorage
	SelfID      int64
	// Entities contains mapped users from the update for user lookup.
	Entities *tg.Entities
}

InlineQuery represents a Telegram inline query with bound context for method chaining. It wraps tg.UpdateBotInlineQuery and provides convenience methods for common operations like answering the query and accessing user information.

func ConstructInlineQuery

func ConstructInlineQuery(iq *tg.UpdateBotInlineQuery) *InlineQuery

ConstructInlineQuery creates an InlineQuery from tg.UpdateBotInlineQuery without context binding. The returned InlineQuery will have nil context fields and cannot perform bound operations. For full functionality, use ConstructInlineQueryWithContext instead.

func ConstructInlineQueryWithContext

func ConstructInlineQueryWithContext(iq *tg.UpdateBotInlineQuery, ctx context.Context, raw *tg.Client, peerStorage *storage.PeerStorage, selfID int64, entities *tg.Entities) *InlineQuery

ConstructInlineQueryWithContext creates an InlineQuery with full context binding. This is the preferred constructor as it enables bound methods like Answer(), GetUser(), etc.

Parameters:

  • iq: The inline query update from Telegram
  • ctx: Context for cancellation and timeouts
  • raw: The raw Telegram client for API calls
  • peerStorage: Peer storage for resolving peer references
  • selfID: The current user/bot ID for context
  • entities: Entities from the update for user lookup

func (*InlineQuery) Answer

func (iq *InlineQuery) Answer(results []tg.InputBotInlineResultClass, opts *AnswerOpts) (bool, error)

Answer responds to the inline query with the provided results. This is the primary method for responding to inline queries.

Parameters:

  • results: A slice of inline query results to display to the user
  • opts: Optional parameters for caching, pagination, and buttons (can be nil)

Returns true if successful, or an error if the operation fails.

Example:

results := []tg.InputBotInlineResultClass{
    &tg.InputBotInlineResult{
        ID:    "1",
        Type:  "article",
        Title: "Result 1",
        SendMessage: &tg.InputBotInlineMessageText{
            Message: "You selected result 1",
        },
    },
}
success, err := iq.Answer(results, &types.AnswerOpts{CacheTime: 60})

func (*InlineQuery) AnswerWithGallery

func (iq *InlineQuery) AnswerWithGallery(results []tg.InputBotInlineResultClass, opts *AnswerOpts) (bool, error)

AnswerWithGallery responds to the inline query with results displayed in a gallery format. This is equivalent to Answer() but sets the gallery flag for photo/video results.

func (*InlineQuery) GetGeo

func (iq *InlineQuery) GetGeo() tg.GeoPointClass

GetGeo returns the location of the user if they shared it, nil otherwise. Users can optionally share their location when making inline queries.

func (*InlineQuery) GetOffset

func (iq *InlineQuery) GetOffset() string

GetOffset returns the offset for pagination. This is the offset passed from a previous inline query result's NextOffset.

func (*InlineQuery) GetPeerType

func (iq *InlineQuery) GetPeerType() tg.InlineQueryPeerTypeClass

GetPeerType returns the type of chat where the inline query originated. This can be used to customize results based on the chat context.

func (*InlineQuery) GetQueryID

func (iq *InlineQuery) GetQueryID() int64

GetQueryID returns the unique identifier for this inline query. This ID is required when answering the query.

func (*InlineQuery) GetUser

func (iq *InlineQuery) GetUser() *User

GetUser returns the User who sent this inline query. Returns nil if the user cannot be found in entities or peer storage.

func (*InlineQuery) GetUserID

func (iq *InlineQuery) GetUserID() int64

GetUserID returns the ID of the user who sent this inline query.

func (*InlineQuery) HasGeo

func (iq *InlineQuery) HasGeo() bool

HasGeo returns true if the user shared their location with this query.

func (*InlineQuery) IsFromBotPM

func (iq *InlineQuery) IsFromBotPM() bool

IsFromBotPM returns true if the inline query was sent from a private chat with the bot itself.

func (*InlineQuery) IsFromChannel

func (iq *InlineQuery) IsFromChannel() bool

IsFromChannel returns true if the inline query was sent from a channel.

func (*InlineQuery) IsFromGroupChat

func (iq *InlineQuery) IsFromGroupChat() bool

IsFromGroupChat returns true if the inline query was sent from a group chat.

func (*InlineQuery) IsFromPrivateChat

func (iq *InlineQuery) IsFromPrivateChat() bool

IsFromPrivateChat returns true if the inline query was sent from a private chat.

func (*InlineQuery) IsFromSameBotPM

func (iq *InlineQuery) IsFromSameBotPM() bool

IsFromSameBotPM returns true if the inline query was sent from a private chat where the user is messaging the same bot.

func (*InlineQuery) IsFromSupergroup

func (iq *InlineQuery) IsFromSupergroup() bool

IsFromSupergroup returns true if the inline query was sent from a supergroup.

func (*InlineQuery) Query

func (iq *InlineQuery) Query() string

Query returns the text of the inline query.

func (*InlineQuery) Raw

func (iq *InlineQuery) Raw() *tg.UpdateBotInlineQuery

Raw returns the underlying tg.UpdateBotInlineQuery struct.

type Message

type Message struct {
	*tg.Message
	ReplyToMessage *Message
	Text           string
	IsService      bool
	Action         tg.MessageActionClass
	// Context fields for bound methods
	Ctx         context.Context
	RawClient   *tg.Client
	PeerStorage *storage.PeerStorage
	SelfID      int64
}

Message represents a Telegram message with bound context for method chaining. It wraps tg.Message and provides convenience methods for common operations like editing, replying, deleting, and accessing media.

func ConstructMessage

func ConstructMessage(m tg.MessageClass) *Message

ConstructMessage creates a Message from a tg.MessageClass without context binding. The returned Message will have nil context fields and cannot perform bound operations. For full functionality, use ConstructMessageWithContext instead.

func ConstructMessageWithContext

func ConstructMessageWithContext(m tg.MessageClass, ctx context.Context, raw *tg.Client, peerStorage *storage.PeerStorage, selfID int64) *Message

ConstructMessageWithContext creates a Message from a tg.MessageClass with full context binding. This is the preferred constructor as it enables bound methods like Edit(), Reply(), etc.

Parameters:

  • m: The message class (Message, MessageService, or MessageEmpty)
  • ctx: Context for cancellation and timeouts
  • raw: The raw Telegram client for API calls
  • peerStorage: Peer storage for resolving peer references
  • selfID: The current user/bot ID for context

func (*Message) Animation

func (m *Message) Animation() *Document

Animation returns the document if message contains an animation (GIF), nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) Audio

func (m *Message) Audio() *Document

Audio returns the document if message contains an audio file, nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) Contact

func (m *Message) Contact() *tg.MessageMediaContact

Contact returns the contact if message contains contact media, nil otherwise.

func (*Message) Delete

func (m *Message) Delete() error

Delete deletes the message. Returns error if failed to delete.

func (*Message) Dice

func (m *Message) Dice() *tg.MessageMediaDice

Dice returns the dice if message contains dice media, nil otherwise.

func (*Message) Document

func (m *Message) Document() *Document

Document returns the document if message contains document media, nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) Download

func (m *Message) Download(path string) (string, tg.StorageFileTypeClass, error)

Download downloads the media from this message to a file path. If path is empty, auto-generates a filename using GetMediaFileNameWithID. Returns the file path that was used and the file type.

Example:

path, fileType, err := msg.Download("")
path, fileType, err := msg.Download("downloads/photo.jpg")

func (*Message) DownloadBytes

func (m *Message) DownloadBytes() ([]byte, tg.StorageFileTypeClass, error)

DownloadBytes downloads the media from this message into memory. Returns the file content as bytes and the file type.

Example:

data, fileType, err := msg.DownloadBytes()

func (*Message) Edit

func (m *Message) Edit(text string, opts ...any) (*Message, error)

Edit edits the message text. Opts can be:

  • *adapter.ReplyOpts - from ext package
  • []tg.MessageEntityClass - raw entities for backward compatibility

func (*Message) EditCaption

func (m *Message) EditCaption(caption string, opts ...any) (*Message, error)

EditCaption edits the caption of a media message. Opts can be *adapter.ReplyOpts or []tg.MessageEntityClass for backward compatibility

func (*Message) EditMedia

func (m *Message) EditMedia(media tg.InputMediaClass, opts ...any) (*Message, error)

EditMedia edits the media of this message. Accepts tg.InputMediaClass (e.g., &tg.InputMediaPhoto{}, &tg.InputMediaDocument{}). Opts can be *adapter.ReplyMediaOpts for caption and entities.

Example using InputMedia:

editedMsg, err := msg.EditMedia(&tg.InputMediaPhoto{
    ID: &tg.InputPhoto{ID: photoID, AccessHash: accessHash},
}, &adapter.ReplyMediaOpts{
    Caption: "New photo",
})

For using fileID strings, see EditMediaWithFileID.

func (*Message) EditMediaWithFileID

func (m *Message) EditMediaWithFileID(fileID string, opts ...any) (*Message, error)

EditMediaWithFileID edits the media of this message using a fileID string. The fileID should be obtained from a previous Message's FileID(), Document().FileID(), or Photo().FileID() method. Opts can be *adapter.ReplyMediaOpts for caption and entities.

Example:

// Replace message media with a fileID
editedMsg, err := msg.EditMediaWithFileID(newFileID, &adapter.ReplyMediaOpts{
    Caption: "Updated media!",
})

func (*Message) EditReplyMarkup

func (m *Message) EditReplyMarkup(markup tg.ReplyMarkupClass) (*Message, error)

EditReplyMarkup edits only the reply markup of the message.

func (*Message) FileID

func (m *Message) FileID() string

FileID returns a formatted file ID string for any media in the message. This is a convenience method that calls FileID() on the appropriate media wrapper. Returns empty string if the message contains no media.

func (*Message) Game

func (m *Message) Game() *tg.MessageMediaGame

Game returns the game if message contains game media, nil otherwise.

func (*Message) Geo

func (m *Message) Geo() *tg.MessageMediaGeo

Geo returns the location if message contains geo media, nil otherwise.

func (*Message) GeoLive

func (m *Message) GeoLive() *tg.MessageMediaGeoLive

GeoLive returns the live location if message contains geo live media, nil otherwise.

func (*Message) GetFullUser

func (m *Message) GetFullUser() (*tg.UserFull, error)

GetFullUser fetches and returns the full user info of the message sender. Returns nil if the message has no sender or on error.

Example:

user, err := u.EffectiveMessage.GetFullUser()
user, err := u.EffectiveReply().GetFullUser()

func (*Message) GetUser

func (m *Message) GetUser() (*tg.User, error)

GetUser fetches and returns the full user info of the message sender. Returns nil if the message has no sender or on error.

Example:

user, err := u.EffectiveMessage.GetUser()
user, err := u.EffectiveReply().GetUser()

func (*Message) Giveaway

func (m *Message) Giveaway() *tg.MessageMediaGiveaway

Giveaway returns the giveaway if message contains giveaway media, nil otherwise.

func (*Message) GiveawayResults

func (m *Message) GiveawayResults() *tg.MessageMediaGiveawayResults

GiveawayResults returns the giveaway results if message contains giveaway results media, nil otherwise.

func (*Message) Invoice

func (m *Message) Invoice() *tg.MessageMediaInvoice

Invoice returns the invoice if message contains invoice media, nil otherwise.

func (*Message) IsForward

func (m *Message) IsForward() bool

IsForward returns true if the message was forwarded from another chat.

func (*Message) IsMedia

func (m *Message) IsMedia() bool

IsMedia returns true if the message contains any media.

func (*Message) IsOutgoing

func (m *Message) IsOutgoing() bool

IsOutgoing returns true if the message was sent by this client (self). It checks the native tg.Message.Out flag first, then falls back to comparing the sender's user ID with SelfID. This fallback is necessary because bot accounts always receive Out=false from Telegram's MTProto.

func (m *Message) Link() string

Link returns a clickable Telegram link to the message. Returns an empty string for private messages (no valid link format). For public channels/groups with username: https://t.me/username/msgID For private channels/groups: https://t.me/c/channelID/msgID

Example:

link := m.Link()
if link != "" {
	fmt.Printf("Message link: %s\n", link)
}

func (*Message) PaidMedia

func (m *Message) PaidMedia() *tg.MessageMediaPaidMedia

PaidMedia returns the paid media if message contains paid media, nil otherwise.

func (*Message) Photo

func (m *Message) Photo() *Photo

Photo returns the photo if message contains photo media, nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) Pin

func (m *Message) Pin() error

Pin pins this message in the chat.

func (*Message) Poll

func (m *Message) Poll() *tg.MessageMediaPoll

Poll returns the poll if message contains poll media, nil otherwise.

func (*Message) Reply

func (m *Message) Reply(text string, opts ...any) (*Message, error)

Reply sends a reply to this message. Opts can be *adapter.ReplyOpts or []tg.MessageEntityClass for backward compatibility

NOTE: By default, replies to this message. To reply to a different message, use ReplyOpts with ReplyMessageID set.

func (*Message) ReplyMedia

func (m *Message) ReplyMedia(media tg.InputMediaClass, caption string, opts ...any) (*Message, error)

ReplyMedia sends a media reply to this message. Accepts tg.InputMediaClass (e.g., &tg.InputMediaPhoto{}, &tg.InputMediaDocument{}). Opts can be *adapter.ReplyMediaOpts or []tg.MessageEntityClass for backward compatibility

NOTE: By default, replies to this message. To reply to a different message, use ReplyMediaOpts with ReplyMessageID set.

Example using InputMedia:

newMsg, err := msg.ReplyMedia(&tg.InputMediaPhoto{
    ID: &tg.InputPhoto{ID: photoID, AccessHash: accessHash},
}, "Photo caption")

For using fileID strings, see ReplyMediaWithFileID.

func (*Message) ReplyMediaWithFileID

func (m *Message) ReplyMediaWithFileID(fileID string, caption string, opts ...any) (*Message, error)

ReplyMediaWithFileID sends a media reply to this message using a fileID string. The fileID should be obtained from a previous Message's FileID(), Document().FileID(), or Photo().FileID() method. Opts can be *adapter.ReplyMediaOpts or []tg.MessageEntityClass for backward compatibility

Example:

fileID := photoMsg.FileID()
newMsg, err := originalMsg.ReplyMediaWithFileID(fileID, "Here's the media you requested")

func (*Message) SetRepliedToMessage

func (m *Message) SetRepliedToMessage(ctx context.Context, raw *tg.Client, p *storage.PeerStorage) error

SetRepliedToMessage populates the ReplyToMessage field by fetching the message being replied to. This is a lazy-loading operation that fetches the reply message from Telegram.

Parameters:

  • ctx: Context for the API call
  • raw: The raw Telegram client
  • p: Peer storage for resolving peer references

Returns an error if:

  • The message is not a reply (ReplyTo is not MessageReplyHeader)
  • The replied message no longer exists
  • The API call fails

func (*Message) Sticker

func (m *Message) Sticker() *Document

Sticker returns the document if message contains a sticker, nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) Story

func (m *Message) Story() *tg.MessageMediaStory

Story returns the story if message contains story media, nil otherwise.

func (*Message) Unpin

func (m *Message) Unpin() error

Unpin unpins this message from the chat.

func (*Message) UnpinAllMessages

func (m *Message) UnpinAllMessages() error

UnpinAllMessages unpins all messages in this message's chat.

func (*Message) UserID

func (m *Message) UserID() int64

UserID returns the user ID of the message sender. Returns 0 if the message has no sender or sender is not a user.

func (*Message) Venue

func (m *Message) Venue() *tg.MessageMediaVenue

Venue returns the venue if message contains venue media, nil otherwise.

func (*Message) Video

func (m *Message) Video() *Document

Video returns the document if message contains a video, nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) VideoNote

func (m *Message) VideoNote() *Document

VideoNote returns the document if message contains a video note (round video), nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) Voice

func (m *Message) Voice() *Document

Voice returns the document if message contains a voice note, nil otherwise. Returns a wrapper type with helper methods like FileID().

func (*Message) WebPage

func (m *Message) WebPage() *tg.MessageMediaWebPage

WebPage returns the webpage if message contains webpage media, nil otherwise.

type Participant

type Participant struct {
	User        *User
	Participant tg.ChannelParticipantClass
	Status      string
	Rights      *tg.ChatAdminRights
	Title       string
	UserID      int64
	ChatID      int64
}

Participant represents a chat/channel member with their details.

type Photo

type Photo struct {
	*tg.Photo
}

Photo wraps tg.Photo with helper methods. It provides a FileID() method that returns a base64url encoded file identifier compatible with the Bot API format.

func NewPhoto

func NewPhoto(photo *tg.Photo) *Photo

NewPhoto creates a new Photo wrapper from a tg.Photo. Returns nil if the input photo is nil.

func (*Photo) FileID

func (p *Photo) FileID() string

FileID returns an encoded Bot API file ID string for this photo. Uses the official github.com/gotd/td/fileid package for encoding. Returns empty string if the photo is nil.

Example:

photo := msg.Photo()
if photo != nil {
    fileID := photo.FileID()
    if fileID != "" {
        fmt.Printf("Photo FileID: %s\n", fileID)
    }
}

type User

type User struct {
	tg.User
	Ctx         context.Context
	RawClient   *tg.Client
	PeerStorage *storage.PeerStorage
	SelfID      int64
}

User implements EffectiveChat interface for tg.User chats.

func (*User) Block

func (u *User) Block() error

Block blocks this user.

func (*User) GetAccessHash

func (u *User) GetAccessHash() int64

GetAccessHash returns the access hash for API authentication.

func (*User) GetChat

func (u *User) GetChat() (tg.ChatClass, error)

GetChat returns the basic chat information for this user. Returns tg.ChatClass which can be type-asserted to *tg.User.

func (*User) GetChatMemberIn

func (u *User) GetChatMemberIn(chatID int64) (any, error)

GetChatMemberIn fetches this user's membership info in a specific chat. chatID can be a channel, chat, or user ID.

func (*User) GetID

func (u *User) GetID() int64

GetID returns the user ID.

func (*User) GetInputChannel

func (*User) GetInputChannel() tg.InputChannelClass

GetInputChannel returns the InputChannel for this peer. Always returns nil for User (users are not channels).

func (*User) GetInputPeer

func (v *User) GetInputPeer() tg.InputPeerClass

GetInputPeer returns the InputPeer for API calls.

func (*User) GetInputUser

func (v *User) GetInputUser() tg.InputUserClass

GetInputUser returns the InputUser for API calls.

func (*User) IsChannel

func (*User) IsChannel() bool

IsChannel returns true if this effective chat is a channel. Always returns false for User.

func (*User) IsChat

func (*User) IsChat() bool

IsChat returns true if this effective chat is a group chat. Always returns false for User.

func (*User) IsUser

func (*User) IsUser() bool

IsUser returns true if this effective chat is a user (private chat). Always returns true for User.

func (*User) Mention

func (u *User) Mention(args ...any) string

Mention generates an HTML mention link for this user.

Behavior: - No arguments: uses the user's ID and full name. - One argument:

  • int/int64 → overrides userID, keeps default name.
  • string → overrides name, keeps default userID.

- Two arguments: first is userID (int/int64), second is name (string). - Returns a string in the format: <a href='tg://user?id=USERID'>NAME</a>

func (*User) Raw

func (u *User) Raw() *tg.User

Raw returns the underlying tg.User struct.

func (*User) SendMedia

func (u *User) SendMedia(media tg.InputMediaClass, opts ...any) (*Message, error)

SendMedia sends media to this user. Opts can be:

  • string (caption parse mode): "HTML", "Markdown", "MarkdownV2", or ""
  • []tg.MessageEntityClass (raw caption entities)
  • struct with fields: Caption, ParseMode, Markup, Silent

func (*User) SendMessage

func (u *User) SendMessage(text string, opts ...any) (*Message, error)

SendMessage sends a message to this user. Opts can be:

  • string (parse mode): "HTML", "Markdown", "MarkdownV2", or ""
  • []tg.MessageEntityClass (raw entities for backward compatibility)
  • struct with fields: ParseMode, NoWebpage, Silent, Markup

func (*User) Unblock

func (u *User) Unblock() error

Unblock unblocks this user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL