botmsg

package
v0.77.8 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ChatActionTyping indicates the bot is typing a text message.
	ChatActionTyping = "typing"
	// ChatActionUploadPhoto indicates the bot is uploading a photo.
	ChatActionUploadPhoto = "upload_photo"
	// ChatActionRecordVideo indicates the bot is recording a video.
	ChatActionRecordVideo = "record_video"
	// ChatActionUploadVideo indicates the bot is uploading a video.
	ChatActionUploadVideo = "upload_video"
	// ChatActionRecordVoice indicates the bot is recording a voice message.
	ChatActionRecordVoice = "record_voice"
	// ChatActionUploadVoice indicates the bot is uploading a voice message.
	ChatActionUploadVoice = "upload_voice"
	// ChatActionUploadDocument indicates the bot is uploading a document.
	ChatActionUploadDocument = "upload_document"
	// ChatActionChooseSticker indicates the bot is choosing a sticker.
	ChatActionChooseSticker = "choose_sticker"
	// ChatActionFindLocation indicates the bot is finding a location.
	ChatActionFindLocation = "find_location"
)

Chat action values, per https://core.telegram.org/bots/api#sendchataction.

View Source
const NoMessageToSend = "<NO_MESSAGE_TO_SEND>"

NoMessageToSend returned explicitly if we don't want to reply to user intput

Variables

This section is empty.

Functions

This section is empty.

Types

type AnswerCallbackQuery added in v0.68.0

type AnswerCallbackQuery struct {
	CallbackQueryID string `json:"callback_query_id"` // Unique identifier for the query to be answered

	// Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
	Text string `json:"text,omitempty"`

	// If True, an alert will be shown by the client instead of a notification at the top of the chat screen
	ShowAlert bool `json:"show_alert,omitempty"`

	// URL that will be opened by the user's client.
	// If you have created a Game and accepted the conditions via @BotFather,
	// specify the URL that opens your game - note that this will only work
	// if the query comes from a callback_game button.
	//
	// Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
	URL string `json:"url,omitempty"`

	// The maximum amount of time in seconds that the result of the callback query may be cached client-side.
	// Telegram apps will support caching starting in version 3.14. Defaults to 0.
	CacheTime int `json:"cache_time,omitempty"`
}

AnswerCallbackQuery is modeled after https://core.telegram.org/bots/api#answercallbackquery

func (AnswerCallbackQuery) BotMessageType added in v0.68.0

func (AnswerCallbackQuery) BotMessageType() Type

func (AnswerCallbackQuery) Validate added in v0.68.0

func (v AnswerCallbackQuery) Validate() error

type Attachment

type Attachment interface {
	AttachmentType() AttachmentType
}

Attachment to a bot message

type AttachmentType

type AttachmentType int

AttachmentType to a bot message

const (
	// AttachmentTypeNone says there is no attachment
	AttachmentTypeNone AttachmentType = iota

	// AttachmentTypeAudio is for audio attachments
	AttachmentTypeAudio

	// AttachmentTypeFile is for file attachments
	AttachmentTypeFile

	// AttachmentTypeImage is for image attachments
	AttachmentTypeImage

	// AttachmentTypeVideo is for video attachments
	AttachmentTypeVideo
)

type BotAPISendMessageChannel

type BotAPISendMessageChannel string

BotAPISendMessageChannel specifies messenger channel

type BotMessage

type BotMessage interface {
	BotMessageType() Type
}

BotMessage is an output message from bot to user

type ChatAction added in v0.77.0

type ChatAction struct {
	// ChatID is the target chat. When empty, the adapter uses the current chat.
	ChatID string `json:"chat_id,omitempty"`
	// Action is the chat action to show, e.g. ChatActionTyping. Required.
	Action string `json:"action"`
}

ChatAction tells the messenger to show a chat action indicator (e.g. "typing") in the target chat for a few seconds. Modeled after https://core.telegram.org/bots/api#sendchataction.

It carries no text; send it as MessageFromBot{BotMessage: ChatAction{...}} via the responder. When ChatID is empty the platform adapter targets the current chat.

func (ChatAction) BotMessageType added in v0.77.0

func (ChatAction) BotMessageType() Type

BotMessageType implements BotMessage.

func (ChatAction) Validate added in v0.77.0

func (v ChatAction) Validate() error

Validate reports whether the chat action is well-formed.

type ChatIntID

type ChatIntID int64

ChatIntID returns botChat ID as unique integer

func (ChatIntID) ChatUID

func (chatUID ChatIntID) ChatUID() string

ChatUID returns botChat ID as unique string

type ChatUID

type ChatUID interface {
	ChatUID() string
}

ChatUID returns botChat ID as unique string

type Format

type Format int

Format specifies formatting of a text message to BOT (e.g. TypeText, HTML, MarkDown)

const (
	// FormatText is for text messages
	FormatText Format = iota
	// FormatHTML is for HTML messages
	FormatHTML
	// FormatMarkdown is for markdown messages
	FormatMarkdown
)

type MessageFromBot

type MessageFromBot struct {
	ResponseChannel BotAPISendMessageChannel `json:"-"` // For debug purposes
	ToChat          ChatUID                  `json:",omitempty"`

	// To be used with Telegram to edit an arbitrary message.
	// Do not use this field directly when you want to edit the callback message
	EditMessageIntID int `json:"editMessageIntID,omitempty"`

	// This is a shortcut to MessageFromBot{}.BotMessage = TextMessageFromBot{text: "abc"}
	TextMessageFromBot // TODO: This feels wrong and need to be refactored! Use BotMessage instead

	BotMessage   BotMessage   `json:",omitempty"`
	Presentation Presentation `json:"presentation,omitempty"`

	Analytics analytics.Message
}

MessageFromBot keeps all the details of answer from bot to user

type MessageUID

type MessageUID interface {
	UID() string
}

MessageUID is unique message ID as string

type Presentation added in v0.77.1

type Presentation struct {
	// PersistentBottomKeyboard identifies a reply keyboard that remains visible
	// after the message. Inline keyboards are not persistent bottom keyboards.
	PersistentBottomKeyboard bool `json:"persistentBottomKeyboard,omitempty"`
}

Presentation declares host-level presentation intent. It is optional so existing messages preserve their current platform-specific behaviour.

type TextMessageFromBot

type TextMessageFromBot struct {
	Text                  string         `json:",omitempty"`
	Format                Format         `json:",omitempty"`
	DisableWebPagePreview bool           `json:",omitempty"`
	DisableNotification   bool           `json:",omitempty"`
	Keyboard              botkb.Keyboard `json:",omitempty"`
	IsEdit                bool           `json:",omitempty"`
	EditMessageUID        MessageUID     `json:",omitempty"`
}

TextMessageFromBot is a text output message from bot to user

func (*TextMessageFromBot) BotEndpoint

func (m *TextMessageFromBot) BotEndpoint() string

func (*TextMessageFromBot) BotMessageType

func (m *TextMessageFromBot) BotMessageType() Type

BotMessageType returns if we want to send a new message or edit existing one

type Type

type Type int

Type defines a type of output message from bot to user

const (
	// TypeUndefined unknown type
	TypeUndefined Type = iota
	// TypeCallbackAnswer sends a callback answer
	TypeCallbackAnswer
	// BotMessageTypeInlineResults sends inline results
	BotMessageTypeInlineResults
	// TypeText sends text reply
	TypeText
	// TypeEditMessage edit previously sent message
	TypeEditMessage
	// TypeLeaveChat commands messenger to kick off bot from a botChat
	TypeLeaveChat
	// TypeExportChatInviteLink sends invite link
	TypeExportChatInviteLink

	TypeSendPhoto

	TypeSendInvoice
	TypeCreateInvoiceLink
	TypeAnswerPreCheckoutQuery

	TypeSetDescription
	TypeSetShortDescription
	TypeSetCommands

	// TypeChatAction shows a chat action indicator (e.g. "typing") in the target chat
	TypeChatAction

	// TypeSendRichMessage sends a native Telegram rich message.
	TypeSendRichMessage

	// TypeSendRichMessageDraft streams a temporary native Telegram rich-message draft.
	TypeSendRichMessageDraft

	// TypeEditRichMessage edits an existing native Telegram rich message.
	TypeEditRichMessage
)

Jump to

Keyboard shortcuts

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