Skip to content

Message

Every handler receives a *goroku.Message.

Fields

FieldTypeMeaning
IDint64Message ID
ChatIDint64Chat it was sent in
SenderIDint64Sender's user ID. 0 when the sender is not a user — anonymous admins and channel-signed posts
SenderChannelIDint64Channel the message was sent as, 0 when a user sent it
SenderIsChannelboolSender is a channel, not a user
TextstringText with formatting applied
RawTextstringText exactly as typed
Entities[]tg.MessageEntityClassFormatting entities
OutboolSent by this account
Mediatg.MessageMediaClassAttachment, nil when absent
IsPrivateboolPrivate chat
IsGroupboolGroup chat
IsChannelboolChannel
ReplyToMsgIDint64Replied-to message, 0 when none
IsForwardedboolForwarded from elsewhere
FwdFromtg.MessageFwdHeaderForward header
ViaBotIDint64Inline bot used, 0 when none
AnsweredboolWhether the handler already answered
Client*CustomTelegramClientClient that received it

Arguments

Args() string

Everything after the command word, trimmed. Inner spacing preserved.

go
// .say hello  there
msg.Args() // "hello  there"

ArgsList() []string

Args split on whitespace. nil when empty.

Arg(i int) string

The i-th argument, or "" when out of range. Never panics.

ArgsOrReply() string

Args(), falling back to the replied-to message's text when empty. "" when there is neither.

go
code := msg.ArgsOrReply()
if code == "" {
	return msg.Answer("❌ Send text or reply to a message")
}

All four are safe on a nil receiver.

Replying

Answer(text string, opts ...MsgOption) error

Edits your own message, or replies when someone else invoked the command. The default choice.

Reply(text string, opts ...MsgOption) error

Always sends a new message as a reply.

Edit(text string, opts ...MsgOption) error

Always edits this message.

Delete() error

Deletes this message.

Options

OptionEffect
WithNoWebpage(bool)Suppress the link preview
WithReplyTo(int64)Reply to a message, or post into a forum topic
WithInvertMedia(bool)Preview above the text
WithWebPageMedia(url string, optional, forceLarge bool)Force a preview
go
msg.Answer("no preview", goroku.WithNoWebpage(true))

Other methods

GetReplyMessage() (*Message, error)

Fetches the replied-to message. Returns nil, nil when there is none.

Context() context.Context

Cancelled when the bot shuts down. Pass it to slow work.

GetChatID() / GetID() / GetReplyToMsgID() int64

Nil-safe accessors.

IsOut() bool

Whether this account sent the message.

Released under the GNU AGPL v3 License.