bot

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package bot implement the Telegram Bot API https://core.telegram.org/bots/api.

The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.

Index

Constants

View Source
const (
	ParseModeMarkdownV2 = "MarkdownV2"
	ParseModeHTML       = "HTML"
)

List of message parse mode.

View Source
const (
	// New incoming message of any kind — text, photo, sticker, etc.
	UpdateTypeMessage = "message"

	// New version of a message that is known to the bot and was edited.
	UpdateTypeEditedMessage = "edited_message"

	// New incoming channel post of any kind — text, photo, sticker, etc.
	UpdateTypeChannelPost = "channel_post"

	// New version of a channel post that is known to the bot and was
	// edited.
	UpdateTypeEditedChannelPost = "edited_channel_post"

	// New incoming inline query
	UpdateTypeInlineQuery = "inline_query"

	// The result of an inline query that was chosen by a user and sent to
	// their chat partner.
	UpdateTypeChosenInlineResult = "chosen_inline_result"

	// New incoming callback query.
	UpdateTypeCallbackQuery = "callback_query"

	// New incoming shipping query.
	// Only for invoices with flexible price.
	UpdateTypeShippingQuery = "shipping_query"

	// New incoming pre-checkout query.
	// Contains full information about checkout.
	UpdateTypePreCheckoutQuery = "pre_checkout_query"

	// New poll state.
	// Bots receive only updates about stopped polls and polls, which are
	// sent by the bot.
	UpdateTypePoll = "poll"

	// A user changed their answer in a non-anonymous poll.
	// Bots receive new votes only in polls that were sent by the bot
	// itself.
	UpdateTypePollAnswer = "poll_answer"
)

List of Update types.

This types can be used to set AllowedUpdates on Options.Webhook.

View Source
const (
	ChatTypeChannel    = "channel"
	ChatTypeGroup      = "group"
	ChatTypePrivate    = "private"
	ChatTypeSupergroup = "supergroup"
)

List of chat types.

View Source
const (
	EntityTypeMention       = "mention"       // @username
	EntityTypeHashtag       = "hashtag"       // #hashtag
	EntityTypeBotCommand    = "bot_command"   // /start@jobs_bot
	EntityTypeURL           = "url"           // https://x.y
	EntityTypeEmail         = "email"         // a@b.c
	EntityTypePhoneNumber   = "phone_number"  //+1-234
	EntityTypeBold          = "bold"          // bold text
	EntityTypeItalic        = "italic"        // italic text
	EntityTypeUnderline     = "underline"     // underlined text
	EntityTypeStrikethrough = "strikethrough" // strikethrough text
	EntityTypeCode          = "code"          // monowidth string
	EntityTypePre           = "pre"           // monowidth block
	EntityTypeTextLink      = "text_link"     // for clickable text URLs
	EntityTypeTextMention   = "text_mention"  // for users without usernames.
)

List of message entity types.

View Source
const (
	// EnvToken define the environment variable for setting the Telegram
	// Bot token.
	// The environment variable has higher priority than Options parameter
	// that passed in New() function.
	EnvToken = "TELEGRAM_TOKEN"

	// EnvWebhookURL define the environment variable for setting the
	// Telegram Webhook URL.
	// The environment variable has higher priority than Options parameter
	// that passed in New() function.
	EnvWebhookURL = "TELEGRAM_WEBHOOK_URL"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation Video

Animation represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).

type Audio

type Audio struct {
	// Optional. Performer of the audio as defined by sender or by audio
	// tags.
	Performer string `json:"performer"`

	// Optional. Title of the audio as defined by sender or by audio tags.
	Title string `json:"title"`

	Document

	// Duration of the audio in seconds as defined by sender.
	Duration int `json:"duration"`
}

Audio represents an audio file to be treated as music by the Telegram clients.

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot for Telegram using webHook.

func New

func New(opts Options) (bot *Bot, err error)

New create and initialize new Telegram bot.

func (*Bot) DeleteWebhook

func (bot *Bot) DeleteWebhook() (err error)

DeleteWebhook remove webhook integration if you decide to switch back to getUpdates. Returns True on success. Requires no parameters.

func (*Bot) GetMe

func (bot *Bot) GetMe() (user *User, err error)

GetMe A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object.

func (*Bot) GetMyCommands

func (bot *Bot) GetMyCommands() (cmds []Command, err error)

GetMyCommands get the current list of the bot's commands.

func (*Bot) GetWebhookInfo

func (bot *Bot) GetWebhookInfo() (webhookInfo *WebhookInfo, err error)

GetWebhookInfo get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.

func (*Bot) SendMessage

func (bot *Bot) SendMessage(parent *Message, parseMode, text string) (
	msg *Message, err error,
)

SendMessage send text messages using defined parse mode to specific user.

func (*Bot) SetMyCommands

func (bot *Bot) SetMyCommands(cmds []Command) (err error)

SetMyCommands change the list of the bot's commands.

The value of each Command in the list must be valid according to description in Command type; this is including length and characters.

func (*Bot) Start

func (bot *Bot) Start() (err error)

Start the Bot.

If the Webhook option is not nil it will start listening to updates through webhook.

func (*Bot) Stop

func (bot *Bot) Stop() (err error)

Stop the Bot.

type CallbackGame

type CallbackGame struct{}

CallbackGame A placeholder, currently holds no information.

type CallbackQuery

type CallbackQuery struct {
	ID   string `json:"id"`   // Unique identifier for this query
	From *User  `json:"from"` // Sender

	// Optional. Message with the callback button that originated the
	// query. Note that message content and message date will not be
	// available if the message is too old.
	Message *Message `json:"message"`

	// Optional. Identifier of the message sent via the bot in inline
	// mode, that originated the query.
	InlineMessageID string `json:"inline_message_id"`

	// Global identifier, uniquely corresponding to the chat to which the
	// message with the callback button was sent. Useful for high scores
	// in games.
	ChatInstance string `json:"chat_instance"`

	// Optional. Data associated with the callback button.
	// Be aware that a bad client can send arbitrary data in this field.
	Data string `json:"data"`

	// Optional. Short name of a Game to be returned, serves as the unique
	// identifier for the game.
	GameShortName string `sjon:"game_short_name"`
}

CallbackQuery represents an incoming callback query from a callback button in an inline keyboard.

If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present.

type Chat

type Chat struct {
	// Optional. Default chat member permissions, for groups and
	// supergroups. Returned only in getChat.
	Permissions *ChatPermissions `json:"permissions"`

	// Optional. Chat photo. Returned only in getChat.
	Photo *ChatPhoto `json:"chat_photo"`

	// Optional. Pinned message, for groups, supergroups and channels.
	// Returned only in getChat.
	PinnedMesage *Message `json:"pinned_mesage"`

	// Type of chat, can be either “private”, “group”, “supergroup” or
	// “channel”.
	Type string `json:"type"`

	// Optional. Title, for supergroups, channels and group chats.
	Title string `json:"title"`

	// Optional. Username, for private chats, supergroups and channels if
	// available.
	Username string `json:"username"`

	// Optional. First name of the other party in a private chat.
	FirstName string `json:"first_name"`

	// Optional. Last name of the other party in a private chat.
	LastName string `json:"last_name"`

	// Optional. Description, for groups, supergroups and channel chats.
	// Returned only in getChat.
	Description string `json:"description"`

	// Optional. Chat invite link, for groups, supergroups and channel
	// chats.
	// Each administrator in a chat generates their own invite links, so
	// the bot must first generate the link using exportChatInviteLink.
	// Returned only in getChat.
	InviteLink string `json:"invite_link"`

	// Optional. For supergroups, name of group sticker set. Returned only
	// in getChat.
	StickerSetName string `json:"sticker_set_name"`

	// Unique identifier for this chat.
	//
	// This number may be greater than 32 bits and some programming
	// languages may have difficulty/silent defects in interpreting it.
	// But it is smaller than 52 bits, so a signed 64 bit integer or
	// double-precision float type are safe for storing this identifier.
	ID int64 `json:"id"`

	// Optional. For supergroups, the minimum allowed delay between
	// consecutive messages sent by each unpriviledged user. Returned only
	// in getChat.
	SlowModeDelay int `json:"slow_mode_delay"`

	// Optional. True, if the bot can change the group sticker set.
	// Returned only in getChat.
	CanSetStickerSet bool `json:"can_set_sticker_set"`
}

Chat represents a chat.

type ChatPermissions

type ChatPermissions struct {
	// Optional. True, if the user is allowed to send text messages,
	// contacts, locations and venues.
	CanSendMessages bool `json:"can_send_messages"`

	// Optional. True, if the user is allowed to send audios, documents,
	// photos, videos, video notes and voice notes, implies
	// can_send_messages.
	CanSendMediaMessages bool `json:"can_send_media_messages"`

	// Optional. True, if the user is allowed to send polls, implies
	// can_send_messages.
	CanSendPolls bool `json:"can_send_polls"`

	// Optional. True, if the user is allowed to send animations, games,
	// stickers and use inline bots, implies can_send_media_messages.
	CanSendOtherMessages bool `json:"can_send_other_messages"`

	// Optional. True, if the user is allowed to add web page previews to
	// their messages, implies can_send_media_messages.
	CanAddWebPagePreviews bool `json:"can_add_web_page_previews"`

	// Optional. True, if the user is allowed to change the chat title,
	// photo and other settings. Ignored in public supergroups.
	CanChangeInfo bool `json:"can_change_info"`

	// Optional. True, if the user is allowed to invite new users to the
	// chat.
	CanInviteUsers bool `json:"can_invite_users"`

	// Optional. True, if the user is allowed to pin messages. Ignored in
	// public supergroups.
	CanPinMessages bool `json:"can_pin_messages"`
}

ChatPermissions describes actions that a non-administrator user is allowed to take in a chat.

type ChatPhoto

type ChatPhoto struct {
	// File identifier of small (160x160) chat photo.
	// This file_id can be used only for photo download and only for as
	// long as the photo is not changed.
	SmallFileID string `json:"small_file_id"`

	// Unique file identifier of small (160x160) chat photo, which is
	// supposed to be the same over time and for different bots.
	// Can't be used to download or reuse the file.
	SmallFileUniqueID string `json:"small_file_unique_id"`

	// File identifier of big (640x640) chat photo.
	// This file_id can be used only for photo download and only for as
	// long as the photo is not changed.
	BigFileID string `json:"big_file_id"`

	// Unique file identifier of big (640x640) chat photo, which is
	// supposed to be the same over time and for different bots.
	// Can't be used to download or reuse the file.
	BigFileUniqueID string `json:"big_file_unique_id"`
}

ChatPhoto represents a chat photo.

type ChosenInlineResult

type ChosenInlineResult struct {
	// The unique identifier for the result that was chosen.
	ResultID string `json:"result_id"`

	// The user that chose the result.
	From *User `json:"from"`

	// The query that was used to obtain the result
	Query string `json:"query"`

	// Optional. Sender location, only for bots that require user
	// location.
	Location *Location `json:"location"`

	// Optional. Identifier of the sent inline message. Available only if
	// there is an inline keyboard attached to the message. Will be also
	// received in callback queries and can be used to edit the message.
	InlineMessageID string `json:"inline_message_id"`
}

ChosenInlineResult represents a result of an inline query that was chosen by the user and sent to their chat partner.

type Command

type Command struct {
	// Function that will be called when Bot receive the command.
	// Handler can read command and its arguments through Message.Command
	// and Message.CommandArgs.
	Handler UpdateHandler `json:"-"`

	// Text of the command, 1-32 characters. Can contain only lowercase
	// English letters, digits and underscores.
	Command string `json:"command"`

	// Description of the command, 3-256 characters.
	Description string `json:"description"`
}

Command represents a bot command.

type Contact

type Contact struct {
	PhoneNumber string `json:"phone_number"` // Contact's phone number.
	FirstName   string `json:"first_name"`   // Contact's first name.

	// Optional. Contact's last name.
	LastName string `json:"last_name"`

	// Optional. Additional data about the contact in the form of a vCard
	VCard string `json:"vcard"`

	// Optional. Contact's user identifier in Telegram
	UserID int64 `json:"user_id"`
}

Contact represents a phone contact.

type Dice

type Dice struct {
	Value int `json:"value"` // Value of the dice, 1-6
}

Dice represents a dice with random value from 1 to 6. (Yes, we're aware of the “proper” singular of die. But it's awkward, and we decided to help it change. One dice at a time!).

type Document

type Document struct {
	// Optional. Document thumbnail as defined by sender.
	Thumb *PhotoSize `json:"thumb"`

	// Identifier for this file, which can be used to download or reuse
	// the file.
	FileID string `json:"file_id"`

	// Unique identifier for this file, which is supposed to be the same
	// over time and for different bots. Can't be used to download or
	// reuse the file.
	FileUniqueID string `json:"file_unique_id"`

	// Optional. MIME type of the file as defined by sender.
	MimeType string `json:"mime_type"`

	// Optional. Original filename as defined by sender.
	FileName string `json:"file_name"`

	// Optional. File size.
	FileSize int `json:"file_size"`
}

Document represents a general file (as opposed to photos, voice messages and audio files).

type EncryptedCredentials

type EncryptedCredentials struct {
	// Base64-encoded encrypted JSON-serialized data with unique user's
	// payload, data hashes and secrets required for
	// EncryptedPassportElement decryption and authentication.
	Data string `json:"data"`

	// Base64-encoded data hash for data authentication
	Hash string `json:"hash"`

	// Base64-encoded secret, encrypted with the bot's public RSA key,
	// required for data decryption.
	Secret string `json:"secret"`
}

EncryptedCredentials contains data required for decrypting and authenticating EncryptedPassportElement.

type EncryptedPassportElement

type EncryptedPassportElement struct {
	// Optional. Encrypted file with the front side of the document,
	// provided by the user.
	// Available for “passport”, “driver_license”, “identity_card” and
	// “internal_passport”. The file can be decrypted and verified using
	// the accompanying EncryptedCredentials.
	FrontSide *PassportFile `json:"front_size"`

	// Optional. Encrypted file with the reverse side of the document,
	// provided by the user.
	// Available for “driver_license” and “identity_card”.
	// The file can be decrypted and verified using the accompanying
	// EncryptedCredentials.
	ReverseSide *PassportFile `json:"reverse_side"`

	// Optional. Encrypted file with the selfie of the user holding a
	// document, provided by the user; available for “passport”,
	// “driver_license”, “identity_card” and “internal_passport”.
	// The file can be decrypted and verified using the accompanying
	// EncryptedCredentials.
	Selfie *PassportFile `json:"selfie"`

	// Element type. One of “personal_details”, “passport”,
	// “driver_license”, “identity_card”, “internal_passport”, “address”,
	// “utility_bill”, “bank_statement”, “rental_agreement”,
	// “passport_registration”, “temporary_registration”, “phone_number”,
	// “email”.
	Type string `json:"type"`

	// Optional. Base64-encoded encrypted Telegram Passport element data
	// provided by the user, available for “personal_details”, “passport”,
	// “driver_license”, “identity_card”, “internal_passport” and
	// “address” types.
	// Can be decrypted and verified using the accompanying
	// EncryptedCredentials.
	Data string `json:"data"`

	// Optional. User's verified phone number, available only for
	// “phone_number” type.
	PhoneNumber string `json:"phone_number"`

	// Optional. User's verified email address, available only for “email”
	// type.
	Email string `json:"email"`

	// Optional. Array of encrypted files with documents provided by the
	// user, available for “utility_bill”, “bank_statement”,
	// “rental_agreement”, “passport_registration” and
	// “temporary_registration” types.
	// Files can be decrypted and verified using the accompanying
	// EncryptedCredentials.
	Files []PassportFile `json:"files"`

	// Optional. Array of encrypted files with translated versions of
	// documents provided by the user.
	// Available if requested for “passport”, “driver_license”,
	// “identity_card”, “internal_passport”, “utility_bill”,
	// “bank_statement”, “rental_agreement”, “passport_registration” and
	// “temporary_registration” types.
	//
	// Files can be decrypted and verified using the accompanying
	// EncryptedCredentials.
	Translation []PassportFile `json:"translation"`
}

EncryptedPassportElement contains information about documents or other Telegram Passport elements shared with the bot by the user.

type Game

type Game struct {
	// Optional. Animation that will be displayed in the game message in
	// chats. Upload via BotFather.
	Animation *Animation `json:"animation"`

	Title       string `json:"title"`       // Title of the game.
	Description string `json:"description"` // Description of the game.

	// Optional. Brief description of the game or high scores included in
	// the game message.
	// Can be automatically edited to include current high scores for the
	// game when the bot calls setGameScore, or manually edited using
	// editMessageText.
	// 0-4096 characters.
	Text string `json:"text"`

	// Photo that will be displayed in the game message in chats.
	Photo []PhotoSize `json:"photo"`

	// Optional. Special entities that appear in text, such as usernames,
	// URLs, bot commands, etc.
	TextEntities []MessageEntity `json:"text_entities"`
}

Game represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers.

type InlineKeyboardButton

type InlineKeyboardButton struct {
	// Optional. An HTTP URL used to automatically authorize the user. Can
	// be used as a replacement for the Telegram Login Widget.
	LoginURL *LoginURL `json:"login_url"`

	// Optional. Description of the game that will be launched when the
	// user presses the button.
	//
	// NOTE: This type of button must always be the first button in the
	// first row.
	CallbackGame *CallbackGame `json:"callback_game"`

	// Label text on the button.
	Text string `json:"text"`

	// Optional. HTTP or tg:// url to be opened when button is pressed.
	URL string `json:"url"`

	// Optional. Data to be sent in a callback query to the bot when
	// button is pressed, 1-64 bytes.
	CallbackData string `json:"callback_data"`

	// Optional. If set, pressing the button will prompt the user to
	// select one of their chats, open that chat and insert the bot‘s
	// username and the specified inline query in the input field. Can be
	// empty, in which case just the bot’s username will be inserted.
	SwitchInlineQuery string `json:"switch_inline_query"`

	// Optional. If set, pressing the button will insert the bot‘s
	// username and the specified inline query in the current chat's input
	// field. Can be empty, in which case only the bot’s username will be
	// inserted.
	SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat"`

	// Optional. Specify True, to send a Pay button.
	//
	// NOTE: This type of button must always be the first button in the
	// first row.
	Pay bool `json:"pay"`
}

InlineKeyboardButton represents one button of an inline keyboard. You must use exactly one of the optional fields.

type InlineKeyboardMarkup

type InlineKeyboardMarkup struct {
	// Array of button rows, each represented by an Array of
	// InlineKeyboardButton objects.
	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}

InlineKeyboardMarkup represents an inline keyboard that appears right next to the message it belongs to.

type InlineQuery

type InlineQuery struct {
	From *User `json:"from"` // Sender

	// Optional. Sender location, only for bots that request user
	// location.
	Location *Location `json:"location"`

	ID    string `json:"id"`    // Unique identifier for this qery
	Query string `json:"query"` // Text of the query (up to 256 characters).

	// Offset of the results to be returned, can be controlled by the bot.
	Offset string `json:"offset"`
}

InlineQuery represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results.

type Invoice

type Invoice struct {
	Title       string `json:"title"`       // Product name
	Description string `json:"description"` // Product description

	// Unique bot deep-linking parameter that can be used to generate
	// this invoice.
	StartParameter string `json:"start_parameter"`

	// Three-letter ISO 4217 currency code
	Currency string `json:"currency"`

	// Total price in the smallest units of the currency (integer, not
	// float/double). For example, for a price of US$ 1.45 pass amount =
	// 145. See the exp parameter in currencies.json, it shows the number
	// of digits past the decimal point for each currency (2 for the
	// majority of currencies).
	TotalAmount int `json:"total_amount"`
}

Invoice contains basic information about an invoice.

type Location

type Location struct {
	Longitude float64 `json:"longitude"` // Longitude as defined by sender.
	Latitude  float64 `json:"latitude"`  // Latitude as defined by sender.
}

Location represents a point on the map.

type LoginURL

type LoginURL struct {
	// An HTTP URL to be opened with user authorization data added to the
	// query string when the button is pressed. If the user refuses to
	// provide authorization data, the original URL without information
	// about the user will be opened. The data added is the same as
	// described in Receiving authorization data.
	//
	// NOTE: You must always check the hash of the received data to verify
	// the authentication and the integrity of the data as described in
	// Checking authorization.
	URL string `json:"url"`

	// Optional. New text of the button in forwarded messages.
	ForwardText string `json:"forward_text"`

	// Optional. Username of a bot, which will be used for user
	// authorization. See Setting up a bot for more details. If not
	// specified, the current bot's username will be assumed. The url's
	// domain must be the same as the domain linked with the bot. See
	// Linking your domain to the bot for more details.
	BotUsername string `json:"bot_username"`

	// Optional. Pass True to request the permission for your bot to send
	// messages to the user.
	RequestWriteAccess bool `json:"request_write_access"`
}

LoginURL represents a parameter of the inline keyboard button used to automatically authorize a user. Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram. All the user needs to do is tap/click a button and confirm that they want to log in.

type MaskPosition

type MaskPosition struct {
	// The part of the face relative to which the mask should be placed.
	// One of “forehead”, “eyes”, “mouth”, or “chin”.
	Point string `json:"point"`

	// Shift by X-axis measured in widths of the mask scaled to the face
	// size, from left to right.
	// For example, choosing -1.0 will place mask just to the left of the
	// default mask position.
	XShift float64 `json:"x_shift"`

	// Shift by Y-axis measured in heights of the mask scaled to the face
	// size, from top to bottom.
	// For example, 1.0 will place the mask just below the default mask
	// position.
	YShift float64 `json:"y_shift"`

	// Mask scaling coefficient. For example, 2.0 means double size.
	Scale float64 `json:"scale"`
}

MaskPosition describes the position on faces where a mask should be placed by default.

type Message

type Message struct {
	// Chat contains conversation the message belongs to.
	Chat *Chat `json:"chat"`

	// Optional. Sender, empty for messages sent to channels.
	From *User `json:"from"`

	// Optional. For replies, the original message.
	// Note that the Message object in this field will not contain further
	// reply_to_message fields even if it itself is a reply.
	ReplyTo *Message `json:"reply_to_message"`

	// Optional. Message is an audio file, information about the file
	Audio *Audio `json:"audio"`

	// Optional. Message is a general file, information about the file.
	Document *Document `json:"document"`

	// Optional. Message is an animation, information about the animation.
	// For backward compatibility, when this field is set, the document
	// field will also be set.
	Animation *Animation `json:"animation"`

	// Optional. Message is a game, information about the game.
	Game *Game `json:"game"`

	// Optional. Message is a sticker, information about the sticker.
	Sticker *Sticker `json:"sticker"`

	// Optional. Message is a video, information about the video.
	Video *Video `json:"video"`

	// Optional. Message is a voice message, information about the file.
	Voice *Voice `json:"voice"`

	// Optional. Message is a video note, information about the video
	// message.
	VideoNote *VideoNote `json:"video_note"`

	// Optional. Message is a shared contact, information about the
	// contact.
	Contact *Contact `json:"contact"`

	// Optional. Message is a shared location, information about the
	// location.
	Location *Location `json:"location"`

	// Optional. Message is a venue, information about the venue.
	Venue *Venue `json:"venue"`

	// Optional. Message is a native poll, information about the poll.
	Poll *Poll `json:"poll"`

	// Optional. Message is a dice with random value from 1 to 6.
	Dice *Dice `json:"dice"`

	// Optional. Specified message was pinned.
	// Note that the Message object in this field will not contain further
	// reply_to_message fields even if it is itself a reply.
	PinnedMessage *Message `json:"pinned_message"`

	// Optional. Message is an invoice for a payment, information about
	// the invoice.
	Invoice *Invoice `json:"invoice"`

	// Optional. Message is a service message about a successful payment,
	// information about the payment.
	SuccessfulPayment *SuccessfulPayment `json:"successful_payment"`

	// Optional. Telegram Passport data.
	PassportData *PassportData `json:"passport_data"`

	// Optional. Inline keyboard attached to the message.
	ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup"`

	// Optional. The unique identifier of a media message group this
	// message belongs to.
	MediaGroupID string `json:"media_group_id"`

	// Optional. Signature of the post author for messages in channels.
	AuthorSignature string `json:"author_signature"`

	// Optional. For text messages, the actual UTF-8 text of the message,
	// 0-4096 characters.
	Text string `json:"text"`

	// Optional. Caption for the animation, audio, document, photo, video
	// or voice, 0-1024 characters.
	Caption string `json:"caption"`

	// Optional. A chat title was changed to this value.
	NewChatTitle string `json:"new_chat_title"`

	// Optional. The domain name of the website on which the user has
	// logged in.
	ConnectedWebsite string `json:"connected_website"`

	Command     string // It will contains the Command name.
	CommandArgs string // It will contains the Command arguments.

	// Optional. For text messages, special entities like usernames, URLs,
	// bot commands, etc. that appear in the text.
	Entities []MessageEntity `json:"entities"`

	// Optional. Message is a photo, available sizes of the photo.
	Photo []PhotoSize `json:"photo"`

	// Optional. For messages with a caption, special entities like
	// usernames, URLs, bot commands, etc. that appear in the caption.
	CaptionEntities []MessageEntity `json:"caption_entities"`

	// Optional. New members that were added to the group or supergroup
	// and information about them (the bot itself may be one of these
	// members).
	NewMembers []*User `json:"new_chat_members"`

	// Optional. A member was removed from the group, information about
	// them (this member may be the bot itself).
	LeftMembers []*User `json:"left_chat_members"`

	// Optional. A chat photo was change to this value.
	NewChatPhoto []PhotoSize `json:"new_chat_photo"`

	MessageForward

	// Optional. The group has been migrated to a supergroup with the
	// specified identifier.
	MigrateToChatID int64 `json:"migrate_to_chat_id"`

	// Optional. The supergroup has been migrated from a group with the
	// specified identifier.
	MigrateFromChatID int64 `json:"migrate_from_chat_id"`

	ID   int `json:"message_id"` // Unique message identifier inside this chat.
	Date int `json:"date"`       // Date the message was sent in Unix time.

	// Optional. Date the message was last edited in Unix time
	EditDate int `json:"edit_date"`

	// Optional. Service message: the chat photo was deleted.
	IsChatPhotoDeleted bool `json:"delete_chat_photo"`

	// Optional. Service message: the group has been created.
	IsGroupChatCreated bool `json:"group_chat_created"`

	// Optional. Service message: the supergroup has been created. This
	// field can‘t be received in a message coming through updates,
	// because bot can’t be a member of a supergroup when it is created.
	// It can only be found in reply_to_message if someone replies to a
	// very first message in a directly created supergroup.
	IsSupergroupChatCreated bool `json:"supergroup_chat_created"`

	// Optional. Service message: the channel has been created.
	// This field can‘t be received in a message coming through updates,
	// because bot can’t be a member of a channel when it is created.
	// It can only be found in reply_to_message if someone replies to a
	// very first message in a channel.
	IsChannelChatCreated bool `json:"channel_chat_created"`
}

Message represents a message.

type MessageEntity

type MessageEntity struct {
	// Optional. For “text_mention” only, the mentioned user.
	User *User `json:"user"`

	// Type of the entity.
	Type string `json:"type"`

	// Optional. For “text_link” only, url that will be opened after user
	// taps on the text.
	URL string `json:"url"`

	// Optional. For “pre” only, the programming language of the entity
	// text.
	Language string `json:"language"`

	// Offset in UTF-16 code units to the start of the entity.
	Offset int `json:"offset"`

	// Length of the entity in UTF-16 code units.
	Length int `json:"length"`
}

MessageEntity represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.

type MessageForward

type MessageForward struct {
	// Optional. For forwarded messages, sender of the original message.
	ForwardFrom *User `json:"forward_from"`

	// Optional. For messages forwarded from channels, information about
	// the original channel.
	ForwardChat *Chat `json:"forward_from_chat"`

	// Optional. For messages forwarded from channels, signature of the post
	// author if present.
	ForwardSignature string `json:"forward_signature"`

	// Optional. Sender's name for messages forwarded from users who
	// disallow adding a link to their account in forwarded messages.
	ForwardSenderName string `json:"forward_sender_name"`

	// Optional. For messages forwarded from channels, identifier of the
	// original message in the channel.
	ForwardID int64 `json:"forward_from_message_id"`

	// Optional. For forwarded messages, date the original message was
	// sent in Unix time.
	ForwardDate int64 `json:"forward_date"`
}

MessageForward define the content for forwarded message.

type Options

type Options struct {
	// Required.  The function that will be called when Bot receiving
	// Updates.
	HandleUpdate UpdateHandler

	// Optional.  Set this options if the Bot want to receive updates
	// using Webhook.
	Webhook *Webhook

	// Required.  Your Bot authentication token.
	// This option will be overridden by environment variable
	// TELEGRAM_TOKEN.
	Token string
}

Options to create new Bot.

type OrderInfo

type OrderInfo struct {
	// Optional. User shipping address
	ShippingAddress *ShippingAddress `json:"shipping_address"`

	// Optional. User name
	Name string `json:"name"`

	// Optional. User's phone number
	PhoneNumber string `json:"phone_number"`

	// Optional. User email
	Email string `json:"email"`
}

OrderInfo represents information about an order.

type PassportData

type PassportData struct {
	// Encrypted credentials required to decrypt the data.
	Credentials EncryptedCredentials
}

PassportData contains information about Telegram Passport data shared with the bot by the user.

type PassportFile

type PassportFile struct {
	// Identifier for this file, which can be used to download or reuse
	// the file.
	FileID string `json:"file_id"`

	// Unique identifier for this file, which is supposed to be the same
	// over time and for different bots. Can't be used to download or
	// reuse the file.
	FileUniqueID string `json:"file_unique_id"`

	// File size.
	FileSize int `json:"file_size"`

	// Unix time when the file was uploaded.
	FileDate int `json:"file_date"`
}

PassportFile represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.

type PhotoSize

type PhotoSize struct {
	// Identifier for this file, which can be used to download or reuse
	// the file.
	FileID string `json:"file_id"`

	// Unique identifier for this file, which is supposed to be the same
	// over time and for different bots. Can't be used to download or
	// reuse the file.
	FileUniqueID string `json:"file_unique_id"`

	// Photo width.
	Width int `json:"width"`

	// Photo height.
	Height int `json:"height"`

	// Optional. File size.
	FileSize int `json:"file_size"`
}

PhotoSize represents one size of a photo or a file / sticker thumbnail.

type Poll

type Poll struct {
	// Unique poll identifier
	ID string `json:"id"`

	// Poll type, currently can be “regular” or “quiz”.
	Type string `json:"type"`

	// Poll question, 1-255 characters.
	Question string `json:"question"`

	// List of poll options.
	Options []PollOption `json:"options"`

	// Optional. 0-based identifier of the correct answer option.
	// Available only for polls in the quiz mode, which are closed, or was
	// sent (not forwarded) by the bot or to the private chat with the
	// bot.
	CorrectOptionID int `json:"correct_option_id"`

	// Total number of users that voted in the poll.
	TotalVoterCount int `json:"total_voter_count"`

	// True, if the poll is closed.
	IsClosed bool `json:"is_closed"`

	// True, if the poll is anonymous.
	IsAnonymous bool `json:"is_anonymous"`

	// True, if the poll allows multiple answers.
	AllowsMultipleAnswers bool `json:"allow_multiple_answers"`
}

Poll contains information about a poll.

type PollAnswer

type PollAnswer struct {
	// Unique poll identifier
	PollID string `json:"poll_id"`

	// The user, who changed the answer to the poll.
	User *User `json:"user"`

	// 0-based identifiers of answer options, chosen by the user. May be
	// empty if the user retracted their vote.
	OptionIDs []int `json:"option_ids"`
}

PollAnswer represents an answer of a user in a non-anonymous poll.

type PollOption

type PollOption struct {
	// Option text, 1-100 characters.
	Text string `json:"text"`

	// Number of users that voted for this option.
	VoterCount int `json:"voter_count"`
}

PollOption contains information about one answer option in a poll.

type PreCheckoutQuery

type PreCheckoutQuery struct {
	// User who sent the query.
	From *User `json:"from"`

	// Optional. Order info provided by the user.
	OrderInfo *OrderInfo `json:"order_info"`

	// Unique query identifier.
	ID string `json:"id"`

	// Three-letter ISO 4217 currency code.
	Currency string `json:"currency"`

	// Bot specified invoice payload.
	InvoicePayload string `json:"invoice_payload"`

	// Optional. Identifier of the shipping option chosen by the user.
	ShippingOptionID string `json:"shipping_option_id"`

	// Total price in the smallest units of the currency (integer, not
	// float/double).
	// For example, for a price of US$ 1.45 pass amount = 145.
	// See the exp parameter in currencies.json, it shows the number
	// of digits past the decimal point for each currency (2 for the
	// majority of currencies).
	TotalAmount int `json:"total_amount"`
}

PreCheckoutQuery contains information about an incoming pre-checkout query.

type ShippingAddress

type ShippingAddress struct {
	// ISO 3166-1 alpha-2 country code.
	CountryCode string `json:"country_code"`

	// State, if applicable.
	State string `json:"state"`

	// City.
	City string `json:"city"`

	// First line for the address.
	StreetLine1 string `json:"street_line1"`

	// Second line for the address.
	StreetLine2 string `json:"street_line2"`

	// Address post code.
	PostCode string `json:"post_code"`
}

ShippingAddress represents a shipping address.

type ShippingQuery

type ShippingQuery struct {
	// User who sent the query.
	From *User `json:"from"`

	// User specified shipping address.
	ShippingAddress *ShippingAddress `json:"shipping_address"`

	// Unique query identifier.
	ID string `json:"id"`

	// Bot specified invoice payload.
	InvoicePayload string `json:"invoice_payload"`
}

ShippingQuery contains information about an incoming shipping query.

type Sticker

type Sticker struct {
	// Optional. For mask stickers, the position where the mask should be
	// placed.
	MaskPosition *MaskPosition `json:"mask_position"`

	// Optional. Emoji associated with the sticker.
	Emoji string `json:"emoji"`

	// Optional. Name of the sticker set to which the sticker belongs.
	SetName string `json:"set_name"`

	Document

	// Sticker width.
	Width int `json:"width"`

	// Sticker height.
	Height int `json:"height"`

	// True, if the sticker is animated.
	IsAnimated bool `json:"is_animated"`
}

Sticker represents a sticker.

type SuccessfulPayment

type SuccessfulPayment struct {
	// Optional. Order info provided by the user.
	OrderInfo *OrderInfo `json:"order_info"`

	// Three-letter ISO 4217 currency code.
	Currency string `json:"currency"`

	// Bot specified invoice payload.
	InvoicePayload string `json:"invoice_payload"`

	// Optional. Identifier of the shipping option chosen by the user.
	ShippingOptionID string `json:"shipping_option_id"`

	// Telegram payment identifier.
	TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`

	// Provider payment identifier.
	ProviderPaymentChargeID string `json:"provider_payment_charge_id"`

	// Total price in the smallest units of the currency (integer, not
	// float/double). For example, for a price of US$ 1.45 pass amount =
	// 145. See the exp parameter in currencies.json, it shows the number
	// of digits past the decimal point for each currency (2 for the
	// majority of currencies).
	TotalAmount int `json:"total_amount"`
}

SuccessfulPayment contains basic information about a successful payment.

type Update

type Update struct {
	// Optional. New incoming message of any kind — text, photo, sticker,
	// etc.
	Message *Message `json:"Message"`

	// Optional. New version of a message that is known to the bot and was
	// edited.
	EditedMessage *Message `json:"edited_message"`

	// Optional. New incoming channel post of any kind — text, photo,
	// sticker, etc..
	ChannelPost *Message `json:"channel_post"`

	// Optional. New version of a channel post that is known to the bot
	// and was edited.
	EditedChannelPost *Message `json:"edited_channel_post"`

	// Optional. New incoming inline query.
	InlineQuery *InlineQuery `json:"inline_query"`

	// Optional. The result of an inline query that was chosen by a user
	// and sent to their chat partner.
	// Please see our documentation on the feedback collecting for details
	// on how to enable these updates for your bot.
	ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`

	// Optional. New incoming callback query.
	CallbackQuery *CallbackQuery `json:"callback_query"`

	// Optional. New incoming shipping query. Only for invoices with
	// flexible price.
	ShippingQuery *ShippingQuery `json:"shipping_query"`

	// Optional. New incoming pre-checkout query. Contains full
	// information about checkout.
	PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`

	// Optional. New poll state. Bots receive only updates about stopped
	// polls and polls, which are sent by the bot.
	Poll *Poll `json:"poll"`

	// Optional. A user changed their answer in a non-anonymous poll. Bots
	// receive new votes only in polls that were sent by the bot itself.
	PollAnswer *PollAnswer `json:"poll_answer"`

	// The update‘s unique identifier.
	// Update identifiers start from a certain positive number and
	// increase sequentially.
	// This ID becomes especially handy if you’re using Webhooks, since it
	// allows you to ignore repeated updates or to restore the correct
	// update sequence, should they get out of order.
	// If there are no new updates for at least a week, then identifier of
	// the next update will be chosen randomly instead of sequentially.
	ID int64 `json:"update_id"`
}

Update an object represents an incoming update. At most one of the optional parameters can be present in any given update.

type UpdateHandler

type UpdateHandler func(update Update)

UpdateHandler define the handler when Bot receiving updates.

type User

type User struct {
	// User‘s or bot’s first name.
	FirstName string `json:"first_name"`

	// Optional. User‘s or bot’s last name.
	LastName string `json:"last_name"`

	// Optional. User‘s or bot’s username.
	Username string `json:"username"`

	// Optional. IETF language tag of the user's language.
	LanguageCode string `json:"language_code"`

	// Unique identifier for this user or bot
	ID int `json:"id"`

	// True, if this user is a bot
	IsBot bool `json:"is_bot"`

	// Optional. True, if the bot can be invited to groups. Returned only
	// in getMe.
	CanJoinGroups bool `json:"can_join_groups"`

	// Optional. True, if privacy mode is disabled for the bot. Returned
	// only in getMe.
	CanReadAllGroupMessages bool `json:"can_read_all_group_messages"`

	// Optional. True, if the bot supports inline queries. Returned only
	// in getMe.
	SupportsInlineQueries bool `json:"supports_inline_queries"`
}

User represents a Telegram user or bot.

type Venue

type Venue struct {
	// Name of the venue.
	Title string `json:"title"`

	// Address of the venue.
	Address string `json:"address"`

	// Optional. Foursquare identifier of the venue.
	FoursquareID string `json:"foursquare_id"`

	// Optional. Foursquare type of the venue. (For example,
	// “arts_entertainment/default”, “arts_entertainment/aquarium” or
	// “food/icecream”).
	FoursquareType string `json:"foursquare_type"`

	// Venue location.
	Location Location `json:"location"`
}

Venue represents a venue.

type Video

type Video struct {
	Document

	Width  int `json:"width"`  // Video width as defined by sender.
	Height int `json:"height"` // Video height as defined by sender.

	// Duration of the video in seconds as defined by sender.
	Duration int `json:"duration"`
}

Video represents a video file.

type VideoNote

type VideoNote struct {
	Document

	// Video width and height (diameter of the video message) as defined
	// by sender.
	Length int `json:"length"`

	// Duration of the video in seconds as defined by sender.
	Duration int `json:"duration"`
}

VideoNote represents a video message (available in Telegram apps as of v.4.0).

type Voice

type Voice Audio

Voice represents a voice note.

type Webhook

type Webhook struct {
	// Optional.  The certificate for Bot server when listening for
	// Webhook.
	ListenCertificate *tls.Certificate

	// HTTPS url to send updates to.
	// This option will be overridden by environment variable
	// TELEGRAM_WEBHOOK_URL.
	URL string

	// Optional.  The address and port where the Bot will listen for
	// Webhook in the following format "<address>:<port>".
	// Default to ":80" if ListenCertificate is nil or ":443" if not nil.
	ListenAddress string

	// Optional. Upload your public key certificate so that the root
	// certificate in use can be checked.
	Certificate []byte

	// Optional. A JSON-serialized list of the update types you want your
	// bot to receive.
	// For example, specify ["message", "edited_channel_post",
	// "callback_query"] to only receive updates of these types.
	//
	// Specify an empty list to receive all updates regardless of type
	// (default). If not specified, the previous setting will be used.
	AllowedUpdates []string

	// Optional.
	// Maximum allowed number of simultaneous HTTPS connections
	// to the webhook for update delivery, 1-100.
	// Defaults to 40.
	// Use lower values to limit the load on your bot‘s server, and higher
	// values to increase your bot’s throughput.
	MaxConnections int
}

Webhook contains options to set Webhook to receive updates.

type WebhookInfo

type WebhookInfo struct {
	// Webhook URL, may be empty if webhook is not set up.
	URL string `json:"url"`

	// Optional. Error message in human-readable format for the most
	// recent error that happened when trying to deliver an update via
	// webhook.
	LastErrorMessage string `json:"last_error_message"`

	// Optional. A list of update types the bot is subscribed to. Defaults
	// to all update types.
	AllowedUpdates []string `json:"allowed_updates"`

	// Number of updates awaiting delivery
	PendingUpdateCount int `json:"pending_update_count"`

	// Optional. Unix time for the most recent error that happened when
	// trying to deliver an update via webhook.
	LastErrorDate int `json:"last_error_date"`

	// Optional. Maximum allowed number of simultaneous HTTPS connections
	// to the webhook for update delivery.
	MaxConnections int `json:"max_connections"`

	// True, if a custom certificate was provided for webhook certificate
	// checks.
	HasCustomCertificate bool `json:"has_custom_certificate"`
}

WebhookInfo contains information about the current status of a webhook.

Jump to

Keyboard shortcuts

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