Documentation
¶
Index ¶
- func InputMediaFromFileID(fileIDStr string, caption string) (tg.InputMediaClass, error)
- type AnswerOpts
- type Channel
- func (u *Channel) GetAccessHash() int64
- func (c *Channel) GetChat() (tg.ChatClass, error)
- func (c *Channel) GetChatInviteLink(req ...*tg.MessagesExportChatInviteRequest) (*tg.ExportedChatInviteClass, error)
- func (c *Channel) GetChatMember(userID int64) (tg.ChannelParticipantClass, error)
- func (c *Channel) GetChatMembers(opts ...*functions.GetChatMembersOpts) ([]*Participant, error)
- func (u *Channel) GetID() int64
- func (v *Channel) GetInputChannel() tg.InputChannelClass
- func (v *Channel) GetInputPeer() tg.InputPeerClass
- func (*Channel) GetInputUser() tg.InputUserClass
- func (*Channel) IsChannel() bool
- func (*Channel) IsChat() bool
- func (*Channel) IsUser() bool
- func (c *Channel) Raw() *tg.Channel
- func (c *Channel) SendMedia(media tg.InputMediaClass, opts ...any) (*Message, error)
- func (c *Channel) SendMessage(text string, opts ...any) (*Message, error)
- type Chat
- func (*Chat) GetAccessHash() int64
- func (c *Chat) GetChat() (tg.ChatClass, error)
- func (c *Chat) GetChatInviteLink(req ...*tg.MessagesExportChatInviteRequest) (*tg.ExportedChatInviteClass, error)
- func (c *Chat) GetChatMembers(opts ...*functions.GetChatMembersOpts) ([]*Participant, error)
- func (u *Chat) GetID() int64
- func (*Chat) GetInputChannel() tg.InputChannelClass
- func (v *Chat) GetInputPeer() tg.InputPeerClass
- func (*Chat) GetInputUser() tg.InputUserClass
- func (*Chat) IsChannel() bool
- func (*Chat) IsChat() bool
- func (*Chat) IsUser() bool
- func (c *Chat) Raw() *tg.Chat
- type ChosenInlineResult
- func (cir *ChosenInlineResult) GetGeo() tg.GeoPointClass
- func (cir *ChosenInlineResult) GetInlineMessageID() tg.InputBotInlineMessageIDClass
- func (cir *ChosenInlineResult) GetUser() *User
- func (cir *ChosenInlineResult) GetUserID() int64
- func (cir *ChosenInlineResult) HasGeo() bool
- func (cir *ChosenInlineResult) HasInlineMessageID() bool
- func (cir *ChosenInlineResult) Query() string
- func (cir *ChosenInlineResult) Raw() *tg.UpdateBotInlineSend
- func (cir *ChosenInlineResult) ResultID() string
- type Document
- type EffectiveChat
- type EmptyUC
- func (*EmptyUC) GetAccessHash() int64
- func (*EmptyUC) GetID() int64
- func (*EmptyUC) GetInputChannel() tg.InputChannelClass
- func (*EmptyUC) GetInputPeer() tg.InputPeerClass
- func (*EmptyUC) GetInputUser() tg.InputUserClass
- func (*EmptyUC) IsChannel() bool
- func (*EmptyUC) IsChat() bool
- func (*EmptyUC) IsUser() bool
- type InlineQuery
- func (iq *InlineQuery) Answer(results []tg.InputBotInlineResultClass, opts *AnswerOpts) (bool, error)
- func (iq *InlineQuery) AnswerWithGallery(results []tg.InputBotInlineResultClass, opts *AnswerOpts) (bool, error)
- func (iq *InlineQuery) GetGeo() tg.GeoPointClass
- func (iq *InlineQuery) GetOffset() string
- func (iq *InlineQuery) GetPeerType() tg.InlineQueryPeerTypeClass
- func (iq *InlineQuery) GetQueryID() int64
- func (iq *InlineQuery) GetUser() *User
- func (iq *InlineQuery) GetUserID() int64
- func (iq *InlineQuery) HasGeo() bool
- func (iq *InlineQuery) IsFromBotPM() bool
- func (iq *InlineQuery) IsFromChannel() bool
- func (iq *InlineQuery) IsFromGroupChat() bool
- func (iq *InlineQuery) IsFromPrivateChat() bool
- func (iq *InlineQuery) IsFromSameBotPM() bool
- func (iq *InlineQuery) IsFromSupergroup() bool
- func (iq *InlineQuery) Query() string
- func (iq *InlineQuery) Raw() *tg.UpdateBotInlineQuery
- type Message
- func (m *Message) Animation() *Document
- func (m *Message) Audio() *Document
- func (m *Message) Contact() *tg.MessageMediaContact
- func (m *Message) Delete() error
- func (m *Message) Dice() *tg.MessageMediaDice
- func (m *Message) Document() *Document
- func (m *Message) Download(path string) (string, tg.StorageFileTypeClass, error)
- func (m *Message) DownloadBytes() ([]byte, tg.StorageFileTypeClass, error)
- func (m *Message) Edit(text string, opts ...any) (*Message, error)
- func (m *Message) EditCaption(caption string, opts ...any) (*Message, error)
- func (m *Message) EditMedia(media tg.InputMediaClass, opts ...any) (*Message, error)
- func (m *Message) EditMediaWithFileID(fileID string, opts ...any) (*Message, error)
- func (m *Message) EditReplyMarkup(markup tg.ReplyMarkupClass) (*Message, error)
- func (m *Message) FileID() string
- func (m *Message) Game() *tg.MessageMediaGame
- func (m *Message) Geo() *tg.MessageMediaGeo
- func (m *Message) GeoLive() *tg.MessageMediaGeoLive
- func (m *Message) GetFullUser() (*tg.UserFull, error)
- func (m *Message) GetUser() (*tg.User, error)
- func (m *Message) Giveaway() *tg.MessageMediaGiveaway
- func (m *Message) GiveawayResults() *tg.MessageMediaGiveawayResults
- func (m *Message) Invoice() *tg.MessageMediaInvoice
- func (m *Message) IsForward() bool
- func (m *Message) IsMedia() bool
- func (m *Message) IsOutgoing() bool
- func (m *Message) Link() string
- func (m *Message) PaidMedia() *tg.MessageMediaPaidMedia
- func (m *Message) Photo() *Photo
- func (m *Message) Pin() error
- func (m *Message) Poll() *tg.MessageMediaPoll
- func (m *Message) Reply(text string, opts ...any) (*Message, error)
- func (m *Message) ReplyMedia(media tg.InputMediaClass, caption string, opts ...any) (*Message, error)
- func (m *Message) ReplyMediaWithFileID(fileID string, caption string, opts ...any) (*Message, error)
- func (m *Message) SetRepliedToMessage(ctx context.Context, raw *tg.Client, p *storage.PeerStorage) error
- func (m *Message) Sticker() *Document
- func (m *Message) Story() *tg.MessageMediaStory
- func (m *Message) Unpin() error
- func (m *Message) UnpinAllMessages() error
- func (m *Message) UserID() int64
- func (m *Message) Venue() *tg.MessageMediaVenue
- func (m *Message) Video() *Document
- func (m *Message) VideoNote() *Document
- func (m *Message) Voice() *Document
- func (m *Message) WebPage() *tg.MessageMediaWebPage
- type Participant
- type Photo
- type User
- func (u *User) Block() error
- func (u *User) GetAccessHash() int64
- func (u *User) GetChat() (tg.ChatClass, error)
- func (u *User) GetChatMemberIn(chatID int64) (any, error)
- func (u *User) GetID() int64
- func (*User) GetInputChannel() tg.InputChannelClass
- func (v *User) GetInputPeer() tg.InputPeerClass
- func (v *User) GetInputUser() tg.InputUserClass
- func (*User) IsChannel() bool
- func (*User) IsChat() bool
- func (*User) IsUser() bool
- func (u *User) Mention(args ...any) string
- func (u *User) Raw() *tg.User
- func (u *User) SendMedia(media tg.InputMediaClass, opts ...any) (*Message, error)
- func (u *User) SendMessage(text string, opts ...any) (*Message, error)
- func (u *User) Unblock() error
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 ¶
GetAccessHash returns the access hash for API authentication.
func (*Channel) GetChat ¶
GetChat returns the basic chat information for this channel. Returns tg.ChatClass which can be type-asserted to *tg.Channel.
func (*Channel) GetChatInviteLink ¶
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 ¶
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 ¶
IsChannel returns true if this effective chat is a channel. Always returns true for Channel.
func (*Channel) IsChat ¶
IsChat returns true if this effective chat is a group chat. Always returns false for Channel.
func (*Channel) IsUser ¶
IsUser returns true if this effective chat is a user (private chat). Always returns false for Channel.
func (*Channel) SendMedia ¶
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 ¶
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 ¶
GetAccessHash returns the access hash for API authentication. Always returns 0 for Chat (group chats don't use access hashes).
func (*Chat) GetChat ¶
GetChat returns the basic chat information for this chat. Returns tg.ChatClass which can be type-asserted to *tg.Chat.
func (*Chat) GetChatInviteLink ¶
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 ¶
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 ¶
IsChannel returns true if this effective chat is a channel. Always returns false for Chat.
func (*Chat) IsChat ¶
IsChat returns true if this effective chat is a group chat. Always returns true for Chat.
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 ¶
func (cir *ChosenInlineResult) Raw() *tg.UpdateBotInlineSend
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 ¶
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 ¶
NewDocument creates a new Document wrapper from a tg.Document. Returns nil if the input document is nil.
func (*Document) FileID ¶
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 ¶
GetAccessHash returns the access hash for API authentication. 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 ¶
IsChannel returns true if this effective chat is a channel. 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 ¶
Animation returns the document if message contains an animation (GIF), nil otherwise. Returns a wrapper type with helper methods like FileID().
func (*Message) Audio ¶
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) Dice ¶
func (m *Message) Dice() *tg.MessageMediaDice
Dice returns the dice if message contains dice media, nil otherwise.
func (*Message) Document ¶
Document returns the document if message contains document media, nil otherwise. Returns a wrapper type with helper methods like FileID().
func (*Message) Download ¶
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 ¶
Edit edits the message text. Opts can be:
- *adapter.ReplyOpts - from ext package
- []tg.MessageEntityClass - raw entities for backward compatibility
func (*Message) EditCaption ¶
EditCaption edits the caption of a media message. Opts can be *adapter.ReplyOpts or []tg.MessageEntityClass for backward compatibility
func (*Message) EditMedia ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) IsOutgoing ¶
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 (*Message) Link ¶
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 ¶
Photo returns the photo if message contains photo media, nil otherwise. Returns a wrapper type with helper methods like FileID().
func (*Message) Poll ¶
func (m *Message) Poll() *tg.MessageMediaPoll
Poll returns the poll if message contains poll media, nil otherwise.
func (*Message) Reply ¶
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 ¶
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) UnpinAllMessages ¶
UnpinAllMessages unpins all messages in this message's chat.
func (*Message) UserID ¶
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 ¶
Video returns the document if message contains a video, nil otherwise. Returns a wrapper type with helper methods like FileID().
func (*Message) VideoNote ¶
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 ¶
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 ¶
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 ¶
NewPhoto creates a new Photo wrapper from a tg.Photo. Returns nil if the input photo is nil.
func (*Photo) FileID ¶
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) GetAccessHash ¶
GetAccessHash returns the access hash for API authentication.
func (*User) GetChat ¶
GetChat returns the basic chat information for this user. Returns tg.ChatClass which can be type-asserted to *tg.User.
func (*User) GetChatMemberIn ¶
GetChatMemberIn fetches this user's membership info in a specific chat. chatID can be a channel, chat, or 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 ¶
IsChannel returns true if this effective chat is a channel. Always returns false for User.
func (*User) IsChat ¶
IsChat returns true if this effective chat is a group chat. Always returns false for User.
func (*User) IsUser ¶
IsUser returns true if this effective chat is a user (private chat). Always returns true for User.
func (*User) Mention ¶
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) SendMedia ¶
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 ¶
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