Message
Every handler receives a *goroku.Message.
Fields
| Field | Type | Meaning |
|---|---|---|
ID | int64 | Message ID |
ChatID | int64 | Chat it was sent in |
SenderID | int64 | Sender's user ID. 0 when the sender is not a user — anonymous admins and channel-signed posts |
SenderChannelID | int64 | Channel the message was sent as, 0 when a user sent it |
SenderIsChannel | bool | Sender is a channel, not a user |
Text | string | Text with formatting applied |
RawText | string | Text exactly as typed |
Entities | []tg.MessageEntityClass | Formatting entities |
Out | bool | Sent by this account |
Media | tg.MessageMediaClass | Attachment, nil when absent |
IsPrivate | bool | Private chat |
IsGroup | bool | Group chat |
IsChannel | bool | Channel |
ReplyToMsgID | int64 | Replied-to message, 0 when none |
IsForwarded | bool | Forwarded from elsewhere |
FwdFrom | tg.MessageFwdHeader | Forward header |
ViaBotID | int64 | Inline bot used, 0 when none |
Answered | bool | Whether the handler already answered |
Client | *CustomTelegramClient | Client 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
| Option | Effect |
|---|---|
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.