tg

package module
v0.0.0-...-c2e8116 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 17 Imported by: 0

README

go-tg

Packages for accessing Telegram Bot API and create stateful bots

Documentation

Index

Constants

View Source
const (
	MinLiveLocationPeriod = time.Second * 60
	MaxLiveLocationPeriod = time.Hour * 24
)

Variables

View Source
var ErrUnsuccessfulInvoke = errors.New("unsuccessful invoke")

Functions

func Polling

func Polling(ctx context.Context, client *Client, handler Handler)

Polling updates.

Types

type Animation

type Animation struct {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `json:"file_unique_id"`

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

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

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

	// Optional. Animation thumbnail as defined by sender
	Thumb *PhotoSize `json:"thumb,omitempty"`

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

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

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

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

type AnimationOpts

type AnimationOpts struct {
	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb"`

	// Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the animation caption.
	ParseMode string `json:"parse_mode,omitempty"`

	// Optional. animation width
	Width int `json:"width,omitempty"`

	// Optional. animation height
	Height int `json:"height,omitempty"`

	// Optional. animation duration
	Duration Duration `json:"duration,omitempty"`

	// Optional. Pass True, if the uploaded animation is suitable for streaming
	SupportsStreaming bool `json:"supports_streaming,omitempty"`

	// Sends the message silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the message is a reply, ID of the original message
	ReplyToMessageID MessageID

	// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
	ReplyMarkup ReplyMarkup
}

type AnswerCallbackQueryOpts

type AnswerCallbackQueryOpts struct {
	// Optional. Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
	Text string

	// Optional. If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
	ShowAlert bool

	// Optional. URL that will be opened by the user's client.
	URL string

	// 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
}

type Audio

type Audio struct {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `json:"file_unique_id"`

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

	// Optional. Performer of the audio as defined by sender or by audio tags
	Performer string `json:"performer,omitempty"`

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

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

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

	// Optional. Thumbnail of the album cover to which the music file belongs
	Thumb *PhotoSize `json:"thumb,omitempty"`
}

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

type AudioOpts

type AudioOpts struct {
	// Optional. Caption of the audio to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the audio caption.
	ParseMode string `json:"parse_mode,omitempty"`

	// Optional. Duration if the audio in seconds.
	Duration Duration

	// Optional. Performer.
	Performer string

	// Optional. Title.
	Title string

	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb"`

	// Sends the message silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the message is a reply, ID of the original message
	ReplyToMessageID MessageID

	// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
	ReplyMarkup ReplyMarkup
}

type BotCommand

type BotCommand struct {
	// 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"`
}

BotCommand represents a bot command.

type CallbackGame

type CallbackGame struct{}

Optional. Description of the game that will be launched when the user presses the button.

type CallbackQuery

type CallbackQuery struct {
	// Unique identifier for this query
	ID CallbackQueryID `json:"id"`

	// Sender
	From *User `json:"from"`

	// 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,omitempty"`

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

	// 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,omitempty"`

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

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

CallbackQuery This object 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 CallbackQueryID

type CallbackQueryID string

CallbackQueryID unique ID.

type Chat

type Chat struct {
	// Unique identifier for this chat.
	ID ChatID `json:"id"`

	// 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,omitempty"`

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

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

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

	// Optional. Chat photo. Returned only in GetChat.
	Photo *ChatPhoto `json:"photo,omitempty"`

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

	// 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,omitempty"`

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

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

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

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

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

Chat object represents a chat.

func (Chat) IsChannel

func (c Chat) IsChannel() bool

IsChannel returns if the Chat is a channel.

func (Chat) IsGroup

func (c Chat) IsGroup() bool

IsGroup returns if the Chat is a group.

func (*Chat) IsPrivate

func (c *Chat) IsPrivate() bool

IsPrivate returns if the Chat is a private conversation.

func (Chat) IsSuperGroup

func (c Chat) IsSuperGroup() bool

IsSuperGroup returns if the Chat is a supergroup.

type ChatID

type ChatID int64

ChatID represents ID of Telegram chat.

func (ChatID) Peer

func (id ChatID) Peer() string

type ChatMember

type ChatMember struct {
	// Information about the user
	User *User `json:"user,omitempty"`

	// The member's status in the chat. Can be “creator”, “administrator”, “member”, “restricted”, “left” or “kicked”
	Status string `json:"status,omitempty"`

	// Optional. Owner and administrators only. Custom title for this user
	CustomTitle string `json:"custom_title,omitempty"`

	// Optional. Owner and administrators only. True, if the user's presence in the chat is hidden
	IsAnonymous bool `json:"is_anonymous,omitempty"`

	// Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
	CanBeEdited bool `json:"can_be_edited,omitempty"`

	// Optional. Administrators only. True, if the administrator can post in the channel; channels only
	CanPostMessages bool `json:"can_post_messages,omitempty"`

	// Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages; channels only
	CanEditMessages bool `json:"can_edit_messages,omitempty"`

	// Optional. Administrators only. True, if the administrator can delete messages of other users
	CanDeleteMessages bool `json:"can_delete_messages,omitempty"`

	// Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
	CanRestrictMembers bool `json:"can_restrict_members,omitempty"`

	// Optional. Administrators only. True, if the administrator can add new administrators
	// with a subset of their own privileges or demote administrators that he has promoted,
	// directly or indirectly (promoted by administrators that were appointed by the user)
	CanPromoteMembers bool `json:"can_promote_members,omitempty"`

	// Optional. Administrators and restricted only. True, if the user is allowed to change the chat title, photo and other settings
	CanChangeInfo bool `json:"can_change_info,omitempty"`

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

	// Optional. Administrators and restricted only. True, if the user is allowed to pin messages; groups and supergroups only
	CanPinMessages bool `json:"can_pin_messages,omitempty"`

	// Optional. Restricted only. True, if the user is a member of the chat at the moment of the request
	IsMember bool `json:"is_member,omitempty"`

	// Optional. Restricted only. True, if the user is allowed to send text messages, contacts, locations and venues
	CanSendMessages bool `json:"can_send_messages,omitempty"`

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

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

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

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

	// Optional. Restricted and kicked only. Date when restrictions will be lifted for this user; unix time
	UnitDate int `json:"unit_date,omitempty"`
}

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,omitempty"`

	// 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,omitempty"`

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

	// 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,omitempty"`

	// 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,omitempty"`

	// 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,omitempty"`

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

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

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 FileID can be used only for photo download and only for as long as the photo is not changed.
	SmallFileID FileID `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 FileID `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 FileID `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 FileID `json:"big_file_unique_id"`
}

ChatPhoto object represents a chat photo.

type Client

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

Client it's Telegram Bot API client.

func NewClient

func NewClient(token string, opts ...ClientOption) *Client

NewClient creates new Telegram Bot API client with provided token. Additional options can be specified using ClientOption.

func (*Client) AnswerCallbackQuery

func (client *Client) AnswerCallbackQuery(
	ctx context.Context,
	callbackQueryID CallbackQueryID,
	opts *AnswerCallbackQueryOpts,
) (bool, error)

func (*Client) DeleteMessage

func (client *Client) DeleteMessage(
	ctx context.Context,
	chat Peer,
	msg MessageID,
) (bool, error)

Use this method to delete a message, including service messages, with the following limitations: - A message can only be deleted if it was sent less than 48 hours ago. - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago. - Bots can delete outgoing messages in private chats, groups, and supergroups. - Bots can delete incoming messages in private chats. - Bots granted can_post_messages permissions can delete outgoing messages in channels. - If the bot is an administrator of a group, it can delete any message there. - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. Returns True on success.

func (*Client) Do

func (client *Client) Do(ctx context.Context, r *Request) (*Response, error)

Do Telegram Bot API request. Just execute request and return response as is.

func (*Client) EditLiveLocation

func (client *Client) EditLiveLocation(
	ctx context.Context,
	chat Peer,
	msg MessageID,
	location Location,
	opts *LocationOpts,
) (*Message, error)

EditLiveLocation this method edit live location messages. A location can be edited until its LivePeriod expires or editing is explicitly disabled by a call to StopMessageLiveLocation. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.

Only ReplyMarkup is usable from options.

func (*Client) EditMessageCaption

func (client *Client) EditMessageCaption(
	ctx context.Context,
	chat Peer,
	msg,
	inline MessageID,
	caption string,
	opts *TextOpts,
) (*Message, error)

func (*Client) EditMessageMedia

func (client *Client) EditMessageMedia(
	ctx context.Context,
	chat Peer,
	msg,
	inline MessageID,
	media InputMedia,
	replyMarkup ReplyMarkup,
) (*Message, error)

func (*Client) EditMessageReplyMarkup

func (client *Client) EditMessageReplyMarkup(
	ctx context.Context,
	chat Peer,
	msg,
	inline MessageID,
	replyMarkup ReplyMarkup,
) (*Message, error)

func (*Client) EditMessageText

func (client *Client) EditMessageText(
	ctx context.Context,
	chat Peer,
	msg,
	inline MessageID,
	text string,
	opts *TextOpts,
) (*Message, error)

func (*Client) ForwardMessage

func (client *Client) ForwardMessage(
	ctx context.Context,
	to Peer,
	from Peer,
	msg MessageID,
	opts *ForwardOpts,
) (*Message, error)

func (*Client) GetChat

func (client *Client) GetChat(ctx context.Context, peer Peer) (*Chat, error)

func (*Client) GetChatMember

func (client *Client) GetChatMember(ctx context.Context, chat Peer, user Peer) (*ChatMember, error)

func (*Client) GetChatMembersCount

func (client *Client) GetChatMembersCount(ctx context.Context, peer Peer) (int, error)

func (*Client) GetFile

func (client *Client) GetFile(ctx context.Context, id FileID) (*File, error)

func (*Client) GetMe

func (client *Client) GetMe(ctx context.Context) (*UserBot, error)

GetMe returns basic information about the bot in form of a UserBot object.

func (*Client) GetMyCommands

func (client *Client) GetMyCommands(ctx context.Context) ([]BotCommand, error)

GetMyCommands returns current list of the bot's commands.

func (*Client) GetUpdates

func (client *Client) GetUpdates(ctx context.Context, opts *PollingOptions) ([]*Update, error)

GetUpdates returns incoming updates using long polling.

func (*Client) GetUserProfilePhotos

func (client *Client) GetUserProfilePhotos(ctx context.Context, opts *GetUserProfilePhotosOptions) (*UserProfilePhotos, error)

func (*Client) GetWebhookInfo

func (client *Client) GetWebhookInfo(ctx context.Context) (*WebhookInfo, error)

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

func (*Client) Invoke

func (client *Client) Invoke(ctx context.Context, r *Request, dst interface{}) error

Invoke call to Telegram Bot API. Also handle unmarshalling of response to dst and errors.

func (*Client) SendAnimation

func (client *Client) SendAnimation(
	ctx context.Context,
	to Peer,
	animation *InputFile,
	opts *AnimationOpts,
) (*Message, error)

SendAnimation message. Opts contains optional parameters.

func (*Client) SendAudio

func (client *Client) SendAudio(
	ctx context.Context,
	to Peer,
	audio *InputFile,
	opts *AudioOpts,
) (*Message, error)

SendAudio message. Opts contains optional parameters.

func (*Client) SendDocument

func (client *Client) SendDocument(
	ctx context.Context,
	to Peer,
	document *InputFile,
	opts *DocumentOpts,
) (*Message, error)

SendDocument message. Opts contains optional parameters.

func (*Client) SendLocation

func (client *Client) SendLocation(
	ctx context.Context,
	to Peer,
	location Location,
	opts *LocationOpts,
) (*Message, error)

SendLocation message. Opts contains optional parameters.

func (*Client) SendMediaGroup

func (client *Client) SendMediaGroup(
	ctx context.Context,
	to Peer,
	group []InputMedia,
	opts *MediaGroupOpts,
) ([]*Message, error)

func (*Client) SendPhoto

func (client *Client) SendPhoto(
	ctx context.Context,
	to Peer,
	photo *InputFile,
	opts *PhotoOpts,
) (*Message, error)

SendPhoto message. Opts contains optional parameters.

func (*Client) SendText

func (client *Client) SendText(
	ctx context.Context,
	to Peer,
	text string,
	opts *TextOpts,
) (*Message, error)

SendText message. Opts contains optional parameters.

func (*Client) SendVideo

func (client *Client) SendVideo(
	ctx context.Context,
	to Peer,
	video *InputFile,
	opts *VideoOpts,
) (*Message, error)

SendVideo message. Opts contains optional parameters.

func (*Client) SetMyCommands

func (client *Client) SetMyCommands(ctx context.Context, cmds []BotCommand) error

SetMyCommands method change the list of the bot's commands. Returns True on success.

func (*Client) SetWebhook

func (client *Client) SetWebhook(ctx context.Context, opts *SetWebhookOptions) error

SetWebhook specify a url and receive incoming updates via an outgoing webhook.

type ClientOption

type ClientOption func(*Client)

ClientOption define type for customize client.

func WithDoer

func WithDoer(doer Doer) ClientOption

WithDoer sets client http doer.

type Contact

type Contact struct {
	// Contact's phone number
	PhoneNumber string `json:"phone_number"`

	// Contact's first name
	FirstName string `json:"first_name"`

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

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

	// Optional. Additional data about the contact in the form of a vCard
	VCard string `json:"v_card,omitempty"`
}

Contact object represents a phone contact.

type Dice

type Dice struct {
	// Emoji on which the dice throw animation is based
	Emoji string `json:"emoji"`

	// Value of the dice, 1-6 for currently supported base emoji
	Value int `json:"value"`
}

Dice object represents a dice with a random value from 1 to 6 for currently supported base emoji. 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 {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `json:"file_unique_id"`

	// Optional. Document thumbnail as defined by sender
	Thumb *PhotoSize `json:"thumb,omitempty"`

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

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

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

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

type DocumentOpts

type DocumentOpts struct {

	// Optional. Caption of the document to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the document caption.
	ParseMode string `json:"parse_mode,omitempty"`

	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb"`

	// Sends the message silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the message is a reply, ID of the original message
	ReplyToMessageID MessageID

	// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
	ReplyMarkup ReplyMarkup
}

type Doer

type Doer interface {
	// Do HTTP request.
	Do(r *http.Request) (*http.Response, error)
}

Doer define interface for mock client calls.

type Duration

type Duration int

Duration

type Error

type Error struct {
	Code        int
	Description string
}

Error represents Telegram Bot API

func (*Error) Error

func (err *Error) Error() string

type ErrorHandler

type ErrorHandler func(ctx context.Context, update *Update, err error)

type File

type File struct {
	// Identifier for this file, which can be used to download or reuse the file.
	FileID FileID `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. File size, if known.
	FileSize int `json:"file_size,omitempty"`

	// Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file.
	FilePath string `json:"file_path,omitempty"`
	// contains filtered or unexported fields
}

func (File) NewReader

func (f File) NewReader(ctx context.Context) (io.ReadCloser, error)

func (File) URL

func (f File) URL() string

type FileID

type FileID string

FileID it's ID of uploaded file.

type ForwardOpts

type ForwardOpts struct {
	DisableNotification bool `json:"disable_notification,omitempty"`
}

type Game

type Game struct {
	// Title of the game
	Title string `json:"title"`

	// Description of the game
	Description string `json:"description"`

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

	// 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,omitempty"`

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

	// Optional. Animation that will be displayed in the game message in chats. Upload via BotFather.
	Animation *Animation `json:"animation,omitempty"`
}

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

type GetUserProfilePhotosOptions

type GetUserProfilePhotosOptions struct {
	// Unique identifier of the target user.
	UserID UserID

	// Optional. Sequential number of the first photo to be returned. By default, all photos are returned.
	Offset *int

	// Optional. Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
	Limit *int
}

type Handler

type Handler interface {
	HandleUpdate(ctx context.Context, update *Update) error
}

Handler responds to Telegram Bot API update.

type HandlerFunc

type HandlerFunc func(ctx context.Context, update *Update) error

The HandlerFunc type is an adapter to allow the use of ordinary functions as bot handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

func (HandlerFunc) HandleUpdate

func (handler HandlerFunc) HandleUpdate(ctx context.Context, update *Update) error

HandleUpdate calls handler(ctx, update).

type InlineKeyboardButton

type InlineKeyboardButton struct {
	// 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. 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,omitempty"`

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

	// 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.
	//
	// Note: This offers an easy way for users to start using your bot
	// in inline mode when they are currently in a private chat with it.
	// Especially useful when combined with switch_pm… actions – in this case
	// the user will be automatically returned to the chat they switched from,
	// skipping the chat selection screen.
	SwitchInlineQuery string `json:"switch_inline_query,omitempty"`

	// 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.
	//
	// This offers a quick way for the user to open your bot in inline mode in the same chat
	// good for selecting something from multiple options.
	SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat,omitempty"`

	// 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,omitempty"`

	// 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,omitempty"`
}

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

func NewInlineKeyboardButtonCallbackData

func NewInlineKeyboardButtonCallbackData(text, cd string) InlineKeyboardButton

func NewInlineKeyboardButtonLoginURL

func NewInlineKeyboardButtonLoginURL(text string, login *LoginURL) InlineKeyboardButton

func NewInlineKeyboardButtonURL

func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton

type InlineKeyboardMarkup

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

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

func NewInlineKeyboardMarkup

func NewInlineKeyboardMarkup(rows ...InlineKeyboardRow) InlineKeyboardMarkup

type InlineKeyboardRow

type InlineKeyboardRow []InlineKeyboardButton

func NewInlineKeyboardRow

func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) InlineKeyboardRow

type InputFile

type InputFile struct {
	// Filename
	Name string

	// Body of file
	Body io.Reader
	// contains filtered or unexported fields
}

InputFile represents the file that should be uploaded to the telegram.

func NewInputFile

func NewInputFile(name string, body io.Reader) *InputFile

NewInputFile creates the InputFile from provided name and body reader.

func NewInputFileBytes

func NewInputFileBytes(name string, body []byte) *InputFile

NewInputFileBytes creates input file from provided name.

Example:

file := NewInputFileBytes("test.txt", []byte("test, test, test..."))

func NewInputFileLocal

func NewInputFileLocal(path string) (*InputFile, error)

NewInputFileLocal creates the InputFile from provided local file. This method just open file by provided path. So, you should close it AFTER send.

Example:

file, err := NewInputFileLocal("test.png")
if err != nil {
    return err
}
defer file.Close()

func NewInputFileLocalBuffer

func NewInputFileLocalBuffer(path string) (*InputFile, error)

NewInputFileLocalBuffer creates the InputFile from provided local file path. This function copy the file to the buffer in memory, so you do not need to close it.

func (*InputFile) Close

func (file *InputFile) Close() error

Close call close method on body if it implements io.ReadCloser, else - do nothing.

func (*InputFile) MarshalJSON

func (file *InputFile) MarshalJSON() ([]byte, error)

type InputMedia

type InputMedia interface {
	// contains filtered or unexported methods
}

type InputMediaAnimation

type InputMediaAnimation struct {
	Type string

	// File to send.
	Media *InputFile

	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb,omitempty"`

	// Optional. Caption of the video to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the video caption.
	ParseMode string `json:"parse_mode,omitempty"`

	// Optional. Video width
	Width int `json:"width,omitempty"`

	// Optional. Video height
	Height int `json:"height,omitempty"`

	// Optional. Video duration
	Duration Duration `json:"duration,omitempty"`
}

InputMediaAnimation an animation to be sent.

type InputMediaAudio

type InputMediaAudio struct {
	Type string

	// File to send.
	Media *InputFile

	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb,omitempty"`

	// Optional. Caption of the video to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the video caption.
	ParseMode string `json:"parse_mode,omitempty"`

	// Optional. Duration of the audio in seconds
	Duration Duration

	// Optional. Performer of the audio
	Performer int

	// Optional. Title of the audio
	Title string
}

InputMediaAudio an audio to be sent.

type InputMediaDocument

type InputMediaDocument struct {
	Type string

	// File to send.
	Media *InputFile

	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb,omitempty"`

	// Optional. Caption of the video to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the video caption.
	ParseMode string `json:"parse_mode,omitempty"`
}

InputMediaDocument a document to be sent.

type InputMediaPhoto

type InputMediaPhoto struct {
	Type string `json:"type,omitempty"`
	// File to send
	Media *InputFile `json:"media,omitempty"`

	// Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the photo caption.
	ParseMode string `json:"parse_mode,omitempty"`
}

InputMediaPhoto a photo to be sent.

type InputMediaVideo

type InputMediaVideo struct {
	Type string `json:"type,omitempty"`
	// File to send.
	Media *InputFile `json:"media,omitempty"`

	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb,omitempty"`

	// Optional. Caption of the video to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the video caption.
	ParseMode string `json:"parse_mode,omitempty"`

	// Optional. Video width
	Width int `json:"width,omitempty"`

	// Optional. Video height
	Height int `json:"height,omitempty"`

	// Optional. Video duration
	Duration Duration `json:"duration,omitempty"`

	// Optional. Pass True, if the uploaded video is suitable for streaming
	SupportsStreaming bool `json:"supports_streaming,omitempty"`
}

InputMediaVideo a video to be sent.

type KeyboardButton

type KeyboardButton struct {
	// Text of the button. If none of the optional fields are used,
	// it will be sent as a message when the button is pressed.
	Text string `json:"text"`

	// Optional. If True, the user's phone number will be sent as a contact when the button is pressed.
	// Available in private chats only.
	RequestContact bool `json:"request_contact,omitempty"`

	// Optional. If True, the user's current location will be sent when the button is pressed.
	// Available in private chats only.
	RequestLocation bool `json:"request_location,omitempty"`

	// Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed.
	// Available in private chats only.
	RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"`
}

KeyboardButton object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields RequestContact, RequestLocation, and RequestPoll are mutually exclusive.

type KeyboardButtonPollType

type KeyboardButtonPollType struct {
	// Optional. If quiz is passed, the user will be allowed to create only polls in the quiz mode. If regular is passed,
	// only regular polls will be allowed.
	// Otherwise, the user will be allowed to create a poll of any type.
	Type string `json:"type,omitempty"`
}

KeyboardButtonPollType object represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed.

type KeyboardRow

type KeyboardRow []KeyboardButton

func NewKeyboardRow

func NewKeyboardRow(buttons ...KeyboardButton) KeyboardRow

type Location

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

	// Latitude as defined by sender
	Latitude float64 `json:"latitude"`
}

Location object represents a point on the map.

type LocationOpts

type LocationOpts struct {
	// Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.
	LivePeriod time.Duration

	// Sends the message silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the message is a reply, ID of the original message
	ReplyToMessageID MessageID

	// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
	ReplyMarkup ReplyMarkup
}

type Logger

type Logger interface {
	Printf(format string, args ...interface{})
}

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.
	URL string `json:"url"`

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

	// 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.
	BotUsername Username `json:"bot_username,omitempty"`

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

LoginURL object 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 object describes the position on faces where a mask should be placed by default.

type MediaGroupOpts

type MediaGroupOpts struct {
	// Sends the messages silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the messages are a reply, ID of the original message
	ReplyToMessageID MessageID
}

type Message

type Message struct {
	// Unique message identifier inside this chat
	ID MessageID `json:"message_id"`

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

	// Date the message was sent in Unix time.
	Date UnixTime `json:"date"`

	// Conversation the message belongs to
	Chat Chat `json:"chat"`

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

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

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

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

	// 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,omitempty"`

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

	// 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.
	ReplyToMessage *Message `json:"reply_to_message,omitempty"`

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

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

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

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

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

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

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

	// 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,omitempty"`

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	// Optional. A member was removed from the group, information about them (this member may be the bot itself)
	LeftChatMember *User `json:"left_chat_member,omitempty"`

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

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

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

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

	// 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.
	SupergroupChatCreated bool `json:"supergroup_chat_created,omitempty"`

	// 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.
	ChannelChatCreated bool `json:"channel_chat_created,omitempty"`

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

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

	// 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,omitempty"`

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

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

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

	// Optional. Telegram Passport data
	PassportData json.RawMessage `json:"passport_data,omitempty"`

	// Optional. Optional. Inline keyboard attached to the message.
	// login_url buttons are represented as ordinary url buttons.
	ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
	// contains filtered or unexported fields
}

Message object represents a message.

func (*Message) AnswerLocation

func (msg *Message) AnswerLocation(ctx context.Context, location Location, opts *LocationOpts) (*Message, error)

AnswerLocation send location answer to this message.

func (*Message) AnswerPhoto

func (msg *Message) AnswerPhoto(ctx context.Context, photo *InputFile, opts *PhotoOpts) (*Message, error)

AnswerPhoto send photo answer to this message.

func (*Message) AnswerText

func (msg *Message) AnswerText(ctx context.Context, text string, opts *TextOpts) (*Message, error)

AnswerText send text answer to this message.

func (*Message) CommandArgs

func (msg *Message) CommandArgs() string

func (*Message) EditLiveLocation

func (msg *Message) EditLiveLocation(ctx context.Context, location Location, opts *LocationOpts) (*Message, error)

EditLiveLocation this method edit live location messages sent by the bot or via the bot (for inline bots). A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation.

From options, only ReplyMarkup is usable

func (*Message) IsCommand

func (msg *Message) IsCommand() bool

func (*Message) ReplyLocation

func (msg *Message) ReplyLocation(ctx context.Context, location Location, opts *LocationOpts) (*Message, error)

ReplyLocation send photo reply to this message. This message was quoted.

func (*Message) ReplyPhoto

func (msg *Message) ReplyPhoto(ctx context.Context, photo *InputFile, opts *PhotoOpts) (*Message, error)

ReplyText send photo reply to this message. This message was quoted.

func (*Message) ReplyText

func (msg *Message) ReplyText(ctx context.Context, text string, opts *TextOpts) (*Message, error)

ReplyText send text reply to this message. This message was quoted.

type MessageEntity

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

	// 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"`

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

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

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

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

type MessageID

type MessageID int

MessageID unique message identifier inside this chat

type Peer

type Peer interface {
	Peer() string
}

Peer define generic interface for Telegram chat ID.

type PhotoOpts

type PhotoOpts struct {
	// Photo caption (may also be used when resending photos by file_id), 0-1024 characters after entities parsing
	Caption string

	// Mode for parsing entities in the photo caption. See formatting options for more details.
	ParseMode string

	// Sends the message silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the message is a reply, ID of the original message
	ReplyToMessageID MessageID

	// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
	ReplyMarkup ReplyMarkup
}

type PhotoSize

type PhotoSize struct {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `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 object represents one size of a photo or a file / sticker thumbnail.

type PhotoSizeSlice

type PhotoSizeSlice []PhotoSize

type Poll

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

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

	// List of poll options
	Options []PollOption

	// 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"`

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

	// True, if the poll allows multiple answers
	AllowsMultipleAnswers bool `json:"allows_multiple_answers"`

	// 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,omitempty"`

	// Optional. Text that is shown when a user chooses an incorrect answer or taps
	// on the lamp icon in a quiz-style poll, 0-200 characters
	Explanation string `json:"explanation,omitempty"`

	// Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
	ExplanationEntities []MessageEntity `json:"explanation_entities,omitempty"`

	// Optional. Amount of time in seconds the poll will be active after creation.
	OpenPeriod Duration `json:"open_period,omitempty"`

	// Optional. Point in time (Unix timestamp) when the poll will be automatically closed
	CloseDate UnixTime `json:"close_date,omitempty"`
}

Poll object 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 object represents an answer of a user in a non-anonymous poll.

type PollID

type PollID string

PollID it's unique poll identifier

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 object contains information about one answer option in a poll.

type Poller

type Poller struct {
	// Client represents Telegram Bot API client.
	Client *Client

	// Handler represents Update handler.
	Handler Handler

	// Options contains options using for polling.
	Options PollingOptions

	// ErrorLogger used for logging polling errors.
	ErrorLogger Logger

	// ErrorHandler called ever
	ErrorHandler ErrorHandler

	// HandlerTimeout define time to process update.
	HandlerTimeout time.Duration

	// Delay before next request if error happened.
	RetryAfter time.Duration
	// contains filtered or unexported fields
}

Poller listen to updates using long polling.

func (*Poller) Run

func (poller *Poller) Run(ctx context.Context)

Run polling until stopped.

type PollingOptions

type PollingOptions struct {
	// Identifier of the first update to be returned.
	// Must be greater by one than the highest among the identifiers of previously received updates.
	// By default, updates starting with the earliest unconfirmed update are returned.
	// An update is considered confirmed as soon as GetUpdates is called with an offset higher than its UpdateID.
	// The negative offset can be specified to retrieve updates
	// starting from -offset update from the end of the updates queue. All previous updates will forgotten.
	Offset UpdateID

	// Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.
	Limit int

	// Timeout in seconds for long polling.
	// Defaults to 0, i.e. usual short polling.
	// Should be positive, short polling should be used for testing purposes only.
	Timeout time.Duration

	// A list of the update types you want your bot to receive.
	// For example, specify []string{"message", "edited_channel_post", "callback_query"}
	// to only receive updates of these types.
	// See Update for a complete list of available update types.
	// Specify an empty list to receive all updates regardless of type (default).
	// If not specified, the previous setting will be used.
	// Please note that this parameter doesn't affect updates created before the call to the getUpdates,
	// so unwanted updates may be received for a short period of time.
	AllowedUpdates []string
}

type ReplyKeyboardMarkup

type ReplyKeyboardMarkup struct {
	// Array of button rows, each represented by an Array of KeyboardButton objects
	Keyboard []KeyboardRow `json:"keyboard"`

	// Optional. Requests clients to resize the keyboard vertically for optimal fit
	// (e.g., make the keyboard smaller if there are just two rows of buttons).
	// Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
	ResizeKeyboard bool `json:"resize_keyboard,omitempty"`

	// Optional. Requests clients to hide the keyboard as soon as it's been used.
	// The keyboard will still be available, but clients will automatically display the usual
	// letter-keyboard in the chat – the user can press a special button in the input field to see
	// the custom keyboard again. Defaults to false.
	OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`

	// Optional. Use this parameter if you want to show the keyboard to specific users only.
	// Targets:
	//  1) users that are @mentioned in the text of the Message object;
	//  2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
	//
	// Example: A user requests to change the bot‘s language,
	// bot replies to the request with a keyboard to select the new language.
	// Other users in the group don’t see the keyboard.
	Selective bool `json:"selective,omitempty"`
}

ReplyKeyboardMarkup object represents a custom keyboard with reply options.

func NewReplyKeyboardMarkup

func NewReplyKeyboardMarkup(rows ...KeyboardRow) ReplyKeyboardMarkup

type ReplyKeyboardRemove

type ReplyKeyboardRemove struct {
	// Requests clients to remove the custom keyboard. User will not be able to summon this keyboard;
	// if you want to hide the keyboard from sight but keep it accessible,
	// use one_time_keyboard in ReplyKeyboardMarkup.
	RemoveKeyboard bool `json:"remove_keyboard"`

	// Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets:
	// 1) users that are @mentioned in the text of the Message object;
	// 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
	//
	// Example: A user votes in a poll, bot returns confirmation message in reply to the vote
	// and removes the keyboard for that user, while still showing the keyboard with poll options
	// to users who haven't voted yet.
	Selective bool `json:"selective,omitempty"`
}

ReplyKeyboardRemove Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).

type ReplyMarkup

type ReplyMarkup interface {
	// contains filtered or unexported methods
}

type Request

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

Request represents RPC request to Telegram Bot API. It contains following info: method, token, parameters, files.

func NewRequest

func NewRequest(method string) *Request

NewRequest creates request with provided method.

func (*Request) Method

func (r *Request) Method() string

Method returns request method.

func (*Request) SetFloat64

func (r *Request) SetFloat64(k string, v float64)

SetFloat sets request float argument k to value v.

func (*Request) SetInputFile

func (r *Request) SetInputFile(k string, file *InputFile) (addr string)

SetInputFile add file to request

func (*Request) SetInt

func (r *Request) SetInt(k string, v int)

SetInt sets request int argument k to value v.

func (*Request) SetJSON

func (r *Request) SetJSON(k string, v interface{}) error

SetJSON value k.

func (*Request) SetOptBool

func (r *Request) SetOptBool(k string, v bool)

func (*Request) SetOptDuration

func (r *Request) SetOptDuration(k string, v time.Duration)

func (*Request) SetOptInt

func (r *Request) SetOptInt(k string, v int)

SetOptInt sets request int argument k to value v, if v is not zero.

func (*Request) SetOptInt64

func (r *Request) SetOptInt64(k string, v int64)

func (*Request) SetOptJSON

func (r *Request) SetOptJSON(k string, v interface{}) error

SetOptJSON value k.

func (*Request) SetOptString

func (r *Request) SetOptString(k, v string)

SetOptString sets request string argument, if value is not zero.

func (*Request) SetPeer

func (r *Request) SetPeer(k string, v Peer)

func (*Request) SetString

func (r *Request) SetString(k, v string)

SetString sets request string argument.

func (*Request) SetToken

func (r *Request) SetToken(token string)

SetToken sets request token.

func (*Request) Token

func (r *Request) Token() string

Token returns request token.

type Response

type Response struct {
	// If equals true, the request was successful
	// and the result of the query can be found in the Result field.
	OK bool `json:"ok"`

	// Telegram Bot API method.
	Method string `json:"-"`

	// Result of request in case of success.
	Result json.RawMessage `json:"result"`

	// Description of response/error
	Description string `json:"description"`

	// Error code from Telegram.
	ErrorCode int `json:"error_code"`

	// Contains information about why a request was unsuccessful.
	Parameters *ResponseParameters `json:"parameters"`
}

Response represents Telegram Bot API response.

func (*Response) UnmarshalResult

func (response *Response) UnmarshalResult(dst interface{}) error

type ResponseParameters

type ResponseParameters struct {
	// The group has been migrated to a supergroup with the specified identifier.
	MigrateToChatID ChatID

	// Optional. In case of exceeding flood control,
	// the time left to wait before request can be repeated.
	RetryAfter int
}

ResponseParameters contains information about why a request was unsuccessful.

type SetWebhookOptions

type SetWebhookOptions struct {
	// HTTPS url to send updates to. Use an empty string to remove webhook integration.
	URL string

	// 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

	// A list of the update types you want your bot to receive.
	// For example, specify []string{"message", "edited_channel_post", "callback_query"}
	// to only receive updates of these types.
	// See Update for a complete list of available update types.
	// Specify an empty list to receive all updates regardless of type (default).
	// If not specified, the previous setting will be used.
	// Please note that this parameter doesn't affect updates created before the call to the getUpdates,
	// so unwanted updates may be received for a short period of time.
	AllowedUpdates []string
}

type Sticker

type Sticker struct {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `json:"file_unique_id"`

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

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

	// True, if the sticker is animated
	IsAnimated int `json:"is_animated"`

	// Optional. Sticker thumbnail in the .WEBP or .JPG format
	Thumb *PhotoSize `json:"thumb,omitempty"`

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

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

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

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

Sticker object represents a sticker.

type TextOpts

type TextOpts struct {
	// Mode for parsing entities in the message text.
	ParseMode string

	// Disables link previews for links in this message
	DisableWebPagePreview bool

	// Sends the message silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the message is a reply, ID of the original message
	ReplyToMessageID MessageID

	// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
	ReplyMarkup ReplyMarkup
}

TextOpts contains optional parameters for SendText method.

type UnixTime

type UnixTime int64

UnixTime represents Unix timestamp.

type Update

type Update struct {
	// Update unique ID
	ID UpdateID `json:"update_id"`

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

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

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

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

	// Optional. New incoming inline query
	InlineQuery json.RawMessage `json:"inline_query,omitempty"`

	// Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
	ChosenInlineResult json.RawMessage `json:"chosen_inline_result,omitempty"`

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

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

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

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

	// 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,omitempty"`

	// Client contains client who received this update.
	// Use BindClient to propagate binding to child fields.
	Client *Client `json:"-"`
}

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

func (*Update) BindClient

func (update *Update) BindClient(client *Client)

BindClient set Update and child struct client.

type UpdateID

type UpdateID int

UpdateID 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.

type User

type User struct {
	// Unique identifier for this user or bot
	ID UserID `json:"id"`

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

	// 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,omitempty"`

	// Optional. User's or bot's username
	Username Username `json:"username,omitempty"`

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

User represents Telegram user.

type UserBot

type UserBot struct {
	User `json:"-"`

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

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

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

UserBot represents Telegram bot user info.

func (*UserBot) UnmarshalJSON

func (userBot *UserBot) UnmarshalJSON(data []byte) error

type UserID

type UserID int64

UserID it's unique user ID in Telegram.

func (UserID) Peer

func (id UserID) Peer() string

Peer implements Peer interface.

type UserProfilePhotos

type UserProfilePhotos struct {
	// Total number of profile pictures the target user has.
	TotalCount int `json:"total_count,omitempty"`

	// Requested profile pictures (in up to 4 sizes each).
	Photos []PhotoSizeSlice `json:"photos,omitempty"`
}

type Username

type Username string

Username it's Telegram username.

func (Username) Peer

func (un Username) Peer() string

func (Username) String

func (un Username) String() string

type Venue

type Venue struct {
	// Venue location
	Location Location `json:"location"`

	// 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,omitempty"`

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

Venue object represents a venue.

type Video

type Video struct {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `json:"file_unique_id"`

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

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

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

	// Optional. Video thumbnail
	Thumb *PhotoSize `json:"thumb,omitempty"`

	// Optional. Mime type of a file as defined by sender
	MIMEType string `json:"mime_type,omitempty"`

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

Video object represents a video file.

type VideoNote

type VideoNote struct {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `json:"file_unique_id"`

	// 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 Duration `json:"duration"`

	// Optional. Video thumbnail
	Thumb *PhotoSize `json:"thumb,omitempty"`

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

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

type VideoOpts

type VideoOpts struct {
	// Optional. Caption of the video to be sent, 0-1024 characters after entities parsing
	Caption string `json:"caption,omitempty"`

	// Optional. Mode for parsing entities in the video caption.
	ParseMode string `json:"parse_mode,omitempty"`

	// Optional. Video width
	Width int `json:"width,omitempty"`

	// Optional. Video height
	Height int `json:"height,omitempty"`

	// Optional. Video duration
	Duration Duration `json:"duration,omitempty"`

	// Optional. Pass True, if the uploaded video is suitable for streaming
	SupportsStreaming bool `json:"supports_streaming,omitempty"`

	// Optional. Thumbnail of the file sent. Can be ignored if thumbnail generation
	// for the file is supported server-side.
	// The thumbnail should be in JPEG format and less than 200 kB in size.
	// A thumbnail‘s width and height should not exceed 320.
	// Ignored if the file is not uploaded using multipart/form-data.
	// Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
	// if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
	Thumb *InputFile `json:"thumb"`

	// Sends the message silently. Users will receive a notification with no sound.
	DisableNotification bool

	// If the message is a reply, ID of the original message
	ReplyToMessageID MessageID

	// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
	ReplyMarkup ReplyMarkup
}

type Voice

type Voice struct {
	// Identifier for this file, which can be used to download or reuse the file
	FileID FileID `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 FileID `json:"file_unique_id"`

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

	// Optional. Mime type of a file as defined by sender
	MIMEType string `json:"mime_type,omitempty"`

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

Voice object represents a voice note.

type WebhookInfo

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

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

	// 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 UnixTime `json:"last_error_date,omitempty"`

	// 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,omitempty"`

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

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

Contains information about the current status of a webhook.

Directories

Path Synopsis
examples
iss

Jump to

Keyboard shortcuts

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