Message Methods
client.OnMessage(func(ctx *telegram.Context, msg *types.Message) {
reply, err := msg.Reply("Got it!")
reply.React("👍")
}, tg.Command("start"))If a message was not created by a client (e.g., constructed manually), calling any bound method returns types.ErrNoBinder.
Text
Reply
Sends a text message in the same chat, quoting this message.
func (m *Message) Reply(text string, opts ...*params.SendMessage) (*Message, error)reply, err := msg.Reply("Hello!", ¶ms.SendMessage{ParseMode: params.HTML})Send
Sends a text message in the same chat without replying.
func (m *Message) Send(text string, opts ...*params.SendMessage) (*Message, error)Answer
Sends a text message without replying. Alias for Send; named for callback/query contexts.
func (m *Message) Answer(text string, opts ...*params.SendMessage) (*Message, error)ReplyText
Alias for Reply.
func (m *Message) ReplyText(text string, opts ...*params.SendMessage) (*Message, error)Edit
Modifies the text of this message. Only messages sent by the current user can be edited.
func (m *Message) Edit(text string, opts ...*params.EditMessage) (*Message, error)edited, err := msg.Edit("<i>Updated</i>", ¶ms.EditMessage{ParseMode: params.HTML})EditText
Alias for Edit.
func (m *Message) EditText(text string, opts ...*params.EditMessage) (*Message, error)Media
ReplyMedia / SendMedia / AnswerMedia
Sends media to the same chat. ReplyMedia quotes this message; SendMedia/AnswerMedia do not.
func (m *Message) ReplyMedia(media tg.InputMediaClass, caption string, opts ...*params.SendMessage) (*Message, error)
func (m *Message) SendMedia(media tg.InputMediaClass, caption string, opts ...*params.SendMessage) (*Message, error)
func (m *Message) AnswerMedia(media tg.InputMediaClass, caption string, opts ...*params.SendMessage) (*Message, error)EditMedia
Replaces the media content of this message.
func (m *Message) EditMedia(media tg.InputMediaClass) (*Message, error)EditCaption
Changes the caption of this media message.
func (m *Message) EditCaption(caption string, opts ...*params.EditMessage) (*Message, error)EditReplyMarkup
Changes only the inline keyboard of this message.
func (m *Message) EditReplyMarkup(markup tg.ReplyMarkupClass) (*Message, error)File Upload
Each media type has a Reply* variant (quotes this message) and an Answer* variant (no reply). All accept an *types.InputFile for the file to upload.
Photo
func (m *Message) ReplyPhoto(file *InputFile, caption string, opts ...*params.SendPhoto) (*Message, error)
func (m *Message) AnswerPhoto(file *InputFile, caption string, opts ...*params.SendPhoto) (*Message, error)Audio
func (m *Message) ReplyAudio(file *InputFile, caption string, opts ...*params.SendAudio) (*Message, error)
func (m *Message) AnswerAudio(file *InputFile, caption string, opts ...*params.SendAudio) (*Message, error)Video
func (m *Message) ReplyVideo(file *InputFile, caption string, opts ...*params.SendVideo) (*Message, error)
func (m *Message) AnswerVideo(file *InputFile, caption string, opts ...*params.SendVideo) (*Message, error)Document
func (m *Message) ReplyDocument(file *InputFile, caption string, opts ...*params.SendDocument) (*Message, error)
func (m *Message) AnswerDocument(file *InputFile, caption string, opts ...*params.SendDocument) (*Message, error)Animation
func (m *Message) ReplyAnimation(file *InputFile, caption string, opts ...*params.SendAnimation) (*Message, error)
func (m *Message) AnswerAnimation(file *InputFile, caption string, opts ...*params.SendAnimation) (*Message, error)Voice
func (m *Message) ReplyVoice(file *InputFile, caption string, opts ...*params.SendVoice) (*Message, error)
func (m *Message) AnswerVoice(file *InputFile, caption string, opts ...*params.SendVoice) (*Message, error)Video Note
func (m *Message) ReplyVideoNote(file *InputFile, opts ...*params.SendVideoNote) (*Message, error)
func (m *Message) AnswerVideoNote(file *InputFile, opts ...*params.SendVideoNote) (*Message, error)Sticker
func (m *Message) ReplySticker(file *InputFile, opts ...*params.SendSticker) (*Message, error)
func (m *Message) AnswerSticker(file *InputFile, opts ...*params.SendSticker) (*Message, error)Cached Media
func (m *Message) ReplyCachedMedia(file *InputFile, caption string, opts ...*params.SendDocument) (*Message, error)
func (m *Message) AnswerCachedMedia(file *InputFile, caption string, opts ...*params.SendDocument) (*Message, error)Media Group (Album)
func (m *Message) ReplyMediaGroup(media []tg.InputMediaClass, opts ...*params.SendMediaGroup) ([]*Message, error)
func (m *Message) AnswerMediaGroup(media []tg.InputMediaClass, opts ...*params.SendMediaGroup) ([]*Message, error)Structured Messages
Contact
func (m *Message) ReplyContact(phone, firstName, lastName string, opts ...*params.SendContact) (*Message, error)
func (m *Message) AnswerContact(phone, firstName, lastName string, opts ...*params.SendContact) (*Message, error)Location
func (m *Message) ReplyLocation(lat, lng float64, opts ...*params.SendLocation) (*Message, error)
func (m *Message) AnswerLocation(lat, lng float64, opts ...*params.SendLocation) (*Message, error)Venue
func (m *Message) ReplyVenue(lat, lng float64, title, address string, opts ...*params.SendVenue) (*Message, error)
func (m *Message) AnswerVenue(lat, lng float64, title, address string, opts ...*params.SendVenue) (*Message, error)Poll
func (m *Message) ReplyPoll(question string, options []string, opts ...*params.SendPoll) (*Message, error)
func (m *Message) AnswerPoll(question string, options []string, opts ...*params.SendPoll) (*Message, error)Dice
func (m *Message) ReplyDice(emoji string, opts ...*params.SendDice) (*Message, error)
func (m *Message) AnswerDice(emoji string, opts ...*params.SendDice) (*Message, error)Supported emojis: 🎲, 🎯, 🏀, ⚽, 🎰, 🎳.
Game
func (m *Message) ReplyGame(gameShortName string, opts ...*params.SendGame) (*Message, error)
func (m *Message) AnswerGame(gameShortName string, opts ...*params.SendGame) (*Message, error)Checklist
func (m *Message) ReplyChecklist(checklist *tg.InputMediaTodo, opts ...*params.SendChecklist) (*Message, error)
func (m *Message) AnswerChecklist(checklist *tg.InputMediaTodo, opts ...*params.SendChecklist) (*Message, error)
func (m *Message) EditChecklist(checklist *tg.InputMediaTodo, opts ...*params.EditMessage) (*Message, error)Chat Action
func (m *Message) ReplyChatAction(action tg.SendMessageActionClass) errormsg.ReplyChatAction(&tg.SendMessageTypingAction{})Inline Bot Result
func (m *Message) ReplyInlineBotResult(queryID int64, resultID string, opts ...*params.SendInlineBotResult) (*Message, error)
func (m *Message) AnswerInlineBotResult(queryID int64, resultID string, opts ...*params.SendInlineBotResult) (*Message, error)Forward & Copy
Forward
Forwards this message to another chat.
func (m *Message) Forward(chatID int64, opts ...*params.ForwardMessages) (*Message, error)fwd, err := msg.Forward(targetChatID, ¶ms.ForwardMessages{DropAuthor: true})Copy
Copies this message into another chat without the forward header. Returns the new message ID.
func (m *Message) Copy(chatID int64, opts ...*params.CopyMessage) (int64, error)CopyMediaGroup
Copies all messages in this message's album into another chat.
func (m *Message) CopyMediaGroup(chatID int64) ([]*Message, error)GetMediaGroup
Retrieves all messages that belong to the same album as this message.
func (m *Message) GetMediaGroup() ([]*Message, error)Reactions & Voting
React
Adds emoji reactions to this message.
func (m *Message) React(emojis ...string) errormsg.React("👍", "❤️")Vote
Casts a vote in a poll message.
func (m *Message) Vote(options [][]byte) errorRetractVote
Withdraws the current user's vote in a poll.
func (m *Message) RetractVote() errorPin & Read
Pin
Pins this message in the chat.
func (m *Message) Pin(opts ...*params.PinMessage) errormsg.Pin(¶ms.PinMessage{Silent: true})Unpin
Removes this message from the pinned list.
func (m *Message) Unpin(opts ...*params.PinMessage) errorRead
Marks this message (and all before it) as read.
func (m *Message) Read() errorView
Alias for Read.
func (m *Message) View() errorDelete
Removes this message from the chat. Returns the number of messages deleted.
func (m *Message) Delete(opts ...*params.DeleteMessages) (int, error)count, err := msg.Delete(¶ms.DeleteMessages{Revoke: true})Download
Download
Downloads the media attached to this message as raw bytes.
func (m *Message) Download(opts ...*params.Download) ([]byte, error)data, err := msg.Download()
os.WriteFile("photo.jpg", data, 0644)DownloadTo
Downloads media to a file path. Returns the absolute path of the saved file.
func (m *Message) DownloadTo(fileName string, progress params.ProgressFunc) (string, error)path, err := msg.DownloadTo("/tmp/photo.jpg", nil)
path, err := msg.DownloadTo("", nil) // auto-generated in ./downloads/
path, err := msg.DownloadTo("/tmp/media/", nil) // auto-generates filenameStub Methods (Not Yet Implemented)
These methods exist in the API but return BoundStub errors:
| Method | Description |
|---|---|
EditLiveLocation(lat, lng) | Update live location |
StopLiveLocation() | Stop live location sharing |
Click(buttonIndex) | Simulate button press |
Pay() | Initiate payment |
ReplyPaidMedia(caption, opts) | Send paid media |
AnswerPaidMedia(caption, opts) | Send paid media (no reply) |
ReplyInvoice(title, desc, opts) | Send invoice |
AnswerInvoice(title, desc, opts) | Send invoice (no reply) |
AcceptGiftPurchaseOffer() | Accept gift offer |
RejectGiftPurchaseOffer() | Reject gift offer |
Summarize() | Generate message summary |
CallbackQuery Methods
Callback queries also have bound methods. All return ErrNoBinder if not created by a client.
Answer / AnswerAlert / AnswerURL
func (c *CallbackQuery) Answer(text string) error
func (c *CallbackQuery) AnswerAlert(text string) error
func (c *CallbackQuery) AnswerURL(url string) errorReply
Sends a text message in the callback's originating chat.
func (c *CallbackQuery) Reply(text string) (*Message, error)EditMessage / EditMessageText
Edits the text of the message the callback button is on.
func (c *CallbackQuery) EditMessage(text string, opts ...*params.EditMessage) (*Message, bool, error)
func (c *CallbackQuery) EditMessageText(text string, opts ...*params.EditMessage) (*Message, bool, error)Returns (message, isInline, error). isInline is true if the message was sent via inline mode.
EditCaption / EditMessageCaption
func (c *CallbackQuery) EditCaption(caption string, opts ...*params.EditMessage) (*Message, error)
func (c *CallbackQuery) EditMessageCaption(caption string, opts ...*params.EditMessage) (*Message, bool, error)EditMedia / EditMessageMedia
func (c *CallbackQuery) EditMedia(media tg.InputMediaClass) (*Message, error)
func (c *CallbackQuery) EditMessageMedia(media tg.InputMediaClass) (*Message, bool, error)EditReplyMarkup / EditMessageReplyMarkup
func (c *CallbackQuery) EditReplyMarkup(markup tg.ReplyMarkupClass) (*Message, error)
func (c *CallbackQuery) EditMessageReplyMarkup(markup tg.ReplyMarkupClass) (*Message, bool, error)Delete
func (c *CallbackQuery) Delete() (int, error)InlineQuery Methods
Inline queries have bound methods for answering inline queries. All return ErrNoBinder if not created by a client.
Answer
func (iq *InlineQuery) Answer(results []tg.InputBotInlineResultClass, opts ...*params.InlineQuery) errorAnswerResults
Accepts builder-pattern results.
func (iq *InlineQuery) AnswerResults(results []InlineResultBuilder, opts ...*params.InlineQuery) errorAnswerArticle / AnswerArticles
func (iq *InlineQuery) AnswerArticle(id, title, text string, opts ...*params.InlineQuery) error
func (iq *InlineQuery) AnswerArticles(articles []*InlineArticle, opts ...*params.InlineQuery) errorAnswerPhoto / AnswerPhotos
func (iq *InlineQuery) AnswerPhoto(id string, photoID, accessHash int64, text string, opts ...*params.InlineQuery) error
func (iq *InlineQuery) AnswerPhotos(photos []*InlinePhoto, opts ...*params.InlineQuery) errorAnswerDocument / AnswerDocuments
func (iq *InlineQuery) AnswerDocument(id string, docID, accessHash int64, text string, opts ...*params.InlineQuery) error
func (iq *InlineQuery) AnswerDocuments(docs []*InlineDocument, opts ...*params.InlineQuery) errorAnswerGame
func (iq *InlineQuery) AnswerGame(id, shortName string, opts ...*params.InlineQuery) error