telegram: github.com/bot-api/telegram Index | Files | Directories

package telegram

import "github.com/bot-api/telegram"

Index

Package Files

api.go api_17.go configs.go configs_edit.go configs_message.go constants.go errors.go helpers.go interfaces.go types.go types_inline.go utils.go

Constants

const (
    // APIEndpoint is the endpoint for all API methods,
    // with formatting for Sprintf.
    APIEndpoint = "https://api.telegram.org/bot%s/%s"
    // FileEndpoint is the endpoint for downloading a file from Telegram.
    FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
)
const (
    PrivateChatType    = "private"
    GroupChatType      = "group"
    SuperGroupChatType = "supergroup"
    ChannelChatType    = "channel"
)

Type of chat

const (
    ActionTyping         = "typing"
    ActionUploadPhoto    = "upload_photo"
    ActionRecordVideo    = "record_video"
    ActionUploadVideo    = "upload_video"
    ActionRecordAudio    = "record_audio"
    ActionUploadAudio    = "upload_audio"
    ActionUploadDocument = "upload_document"
    ActionFindLocation   = "find_location"
)

Type of action to broadcast.

Choose one, depending on what the user is about to receive:

typing for text messages
upload_photo for photos
record_video or upload_video for videos
record_audio or upload_audio for audio files
upload_document for general files
find_location for location data
const (
    MarkdownMode = "Markdown"
    HTMLMode     = "HTML"
)

Constant values for ParseMode in MessageCfg.

const (
    // @username
    MentionEntityType     = "mention"
    HashTagEntityType     = "hashtag"
    BotCommandEntityType  = "bot_command"
    URLEntityType         = "url"
    EmailEntityType       = "email"
    BoldEntityType        = "bold"         // bold text
    ItalicEntityType      = "italic"       // italic text
    CodeEntityType        = "code"         // monowidth string
    PreEntityType         = "pre"          // monowidth block
    TextLinkEntityType    = "text_link"    // for clickable text URLs
    TextMentionEntityType = "text_mention" // for users without usernames
)

EntityType constants helps to set type of entity in MessageEntity object

const (
    MemberStatus              = "member"
    CreatorMemberStatus       = "creator"
    AdministratorMemberStatus = "administrator"
    LeftMemberStatus          = "left"
    KickedMemberStatus        = "kicked"
)

ChatMember possible statuses

Variables

var DefaultDebugFunc = func(msg string, fields map[string]interface{}) {
    log.Printf("%s %v", msg, fields)
}

DefaultDebugFunc prints debug message to default logger

func GetUpdates Uses

func GetUpdates(
    ctx context.Context,
    api *API,
    cfg UpdateCfg,
    out chan<- Update) error

GetUpdates runs loop and requests updates from telegram. It breaks loop, close out channel and returns error if something happened during update cycle.

func IsAPIError Uses

func IsAPIError(err error) bool

IsAPIError checks if error is ApiError

func IsForbiddenError Uses

func IsForbiddenError(err error) bool

IsForbiddenError checks if error is forbidden

func IsRequiredError Uses

func IsRequiredError(err error) bool

IsRequiredError checks if error is RequiredError

func IsUnauthorizedError Uses

func IsUnauthorizedError(err error) bool

IsUnauthorizedError checks if error is unauthorized

func IsValidToken Uses

func IsValidToken(token string) bool

IsValidToken returns true if token is a valid telegram bot token

Token format is like: 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsawq

func IsValidationError Uses

func IsValidationError(err error) bool

IsValidationError checks if error is ValidationError

func NewHInlineKeyboard Uses

func NewHInlineKeyboard(prefix string, text []string, data []string) [][]InlineKeyboardButton

NewHInlineKeyboard creates inline keyboard with horizontal buttons only. [ first ] [ second ] [ third ]

func NewHKeyboard Uses

func NewHKeyboard(buttons ...string) [][]KeyboardButton

NewHKeyboard creates keyboard with horizontal buttons only. [ first ] [ second ] [ third ]

func NewKeyboard Uses

func NewKeyboard(buttons [][]string) [][]KeyboardButton

NewKeyboard creates keyboard by matrix i*j.

func NewVInlineKeyboard Uses

func NewVInlineKeyboard(prefix string, text []string, data []string) [][]InlineKeyboardButton

NewVInlineKeyboard creates inline keyboard with vertical buttons only [ first ] [ second ] [ third ]

func NewVKeyboard Uses

func NewVKeyboard(buttons ...string) [][]KeyboardButton

NewVKeyboard creates keyboard with vertical buttons only [ first ] [ second ] [ third ]

type API Uses

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

API implements Telegram bot API described on https://core.telegram.org/bots/api

func New Uses

func New(token string) *API

New returns API instance with default http client

func NewWithClient Uses

func NewWithClient(token string, client HTTPDoer) *API

NewWithClient returns API instance with custom http client

func (*API) AnswerCallbackQuery Uses

func (c *API) AnswerCallbackQuery(
    ctx context.Context,
    cfg AnswerCallbackCfg) (bool, error)

AnswerCallbackQuery sends a response to an inline query callback.

func (*API) AnswerInlineQuery Uses

func (c *API) AnswerInlineQuery(ctx context.Context, cfg AnswerInlineQueryCfg) (bool, error)

AnswerInlineQuery sends answers to an inline query. On success, True is returned. No more than 50 results per query are allowed.

func (*API) Debug Uses

func (c *API) Debug(val bool)

Debug enables sending debug messages to default log

func (*API) DebugFunc Uses

func (c *API) DebugFunc(f DebugFunc)

DebugFunc replaces default debug function

func (*API) DownloadFile Uses

func (c *API) DownloadFile(ctx context.Context, cfg FileCfg, w io.Writer) error

DownloadFile downloads file from telegram servers to w

Requires FileID

func (*API) Edit Uses

func (c *API) Edit(ctx context.Context, cfg Method) (*EditResult, error)

Edit method allows you to change an existing message in the message history instead of sending a new one with a result of an action. This is most useful for messages with inline keyboards using callback queries, but can also help reduce clutter in conversations with regular chat bots. Please note, that it is currently only possible to edit messages without reply_markup or with inline keyboards.

You can use this method directly or one of: EditMessageText, EditMessageCaption, EditMessageReplyMarkup,

func (*API) EditMessageCaption Uses

func (c *API) EditMessageCaption(
    ctx context.Context,
    cfg EditMessageCaptionCfg) (*EditResult, error)

EditMessageCaption modifies the caption of message. Use this method to edit only the caption of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

func (*API) EditMessageReplyMarkup Uses

func (c *API) EditMessageReplyMarkup(
    ctx context.Context,
    cfg EditMessageReplyMarkupCfg) (*EditResult, error)

EditMessageReplyMarkup modifies the reply markup of message. Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

func (*API) EditMessageText Uses

func (c *API) EditMessageText(
    ctx context.Context,
    cfg EditMessageTextCfg) (*EditResult, error)

EditMessageText modifies the text of message. Use this method to edit only the text of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

func (*API) ForwardMessage Uses

func (c *API) ForwardMessage(
    ctx context.Context,
    cfg ForwardMessageCfg) (*Message, error)

ForwardMessage forwards messages of any kind.

func (*API) GetChat Uses

func (c *API) GetChat(ctx context.Context, cfg GetChatCfg) (*Chat, error)

GetChat returns up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.

func (*API) GetChatAdministrators Uses

func (c *API) GetChatAdministrators(
    ctx context.Context,
    cfg GetChatAdministratorsCfg) ([]ChatMember, error)

GetChatAdministrators returns a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.

func (*API) GetChatMember Uses

func (c *API) GetChatMember(
    ctx context.Context,
    cfg GetChatMemberCfg) (*ChatMember, error)

GetChatMember returns information about a member of a chat.

func (*API) GetChatMembersCount Uses

func (c *API) GetChatMembersCount(
    ctx context.Context,
    cfg GetChatMembersCountCfg) (int, error)

GetChatMembersCount returns the number of members in a chat.

func (*API) GetFile Uses

func (c *API) GetFile(ctx context.Context, cfg FileCfg) (*File, error)

GetFile returns a File which can download a file from Telegram.

Requires FileID.

func (*API) GetMe Uses

func (c *API) GetMe(ctx context.Context) (*User, error)

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

func (*API) GetUpdates Uses

func (c *API) GetUpdates(
    ctx context.Context,
    cfg UpdateCfg) ([]Update, error)

GetUpdates requests incoming updates using long polling. This method will not work if an outgoing webhook is set up. In order to avoid getting duplicate updates, recalculate offset after each server response.

func (*API) GetUserProfilePhotos Uses

func (c *API) GetUserProfilePhotos(
    ctx context.Context,
    cfg UserProfilePhotosCfg) (*UserProfilePhotos, error)

GetUserProfilePhotos requests a list of profile pictures for a user.

func (*API) Invoke Uses

func (c *API) Invoke(ctx context.Context, m Method, dst interface{}) error

Invoke is a generic method that helps to make request to Telegram Api. Use particular methods instead (e.x. GetMe, GetUpdates etc). The only case when this method seems useful is when Telegram Api has method that still doesn't exist in this implementation.

func (*API) KickChatMember Uses

func (c *API) KickChatMember(
    ctx context.Context,
    cfg KickChatMemberCfg) (bool, error)

KickChatMember kicks a user from a group or a supergroup. In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the group for this to work. Returns True on success.

func (*API) LeaveChat Uses

func (c *API) LeaveChat(
    ctx context.Context,
    cfg LeaveChatCfg) (bool, error)

LeaveChat method helps your bot to leave a group, supergroup or channel. Returns True on success.

func (*API) Send Uses

func (c *API) Send(ctx context.Context, cfg Messenger) (*Message, error)

Send method sends message.

TODO m0sth8: rewrite this doc

func (*API) SendAudio Uses

func (c *API) SendAudio(
    ctx context.Context,
    cfg AudioCfg) (*Message, error)

SendAudio sends Audio.

func (*API) SendChatAction Uses

func (c *API) SendChatAction(ctx context.Context, cfg ChatActionCfg) error

SendChatAction tells the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).

func (*API) SendContact Uses

func (c *API) SendContact(
    ctx context.Context,
    cfg ContactCfg) (*Message, error)

SendContact sends phone contact message.

func (*API) SendDocument Uses

func (c *API) SendDocument(
    ctx context.Context,
    cfg DocumentCfg) (*Message, error)

SendDocument sends Document.

func (*API) SendMessage Uses

func (c *API) SendMessage(
    ctx context.Context,
    cfg MessageCfg) (*Message, error)

SendMessage sends text message.

func (*API) SendPhoto Uses

func (c *API) SendPhoto(
    ctx context.Context,
    cfg PhotoCfg) (*Message, error)

SendPhoto sends photo.

func (*API) SendSticker Uses

func (c *API) SendSticker(
    ctx context.Context,
    cfg StickerCfg) (*Message, error)

SendSticker sends message with sticker.

func (*API) SendVenue Uses

func (c *API) SendVenue(
    ctx context.Context,
    cfg VenueCfg) (*Message, error)

SendVenue sends venue message.

func (*API) SendVideo Uses

func (c *API) SendVideo(
    ctx context.Context,
    cfg VideoCfg) (*Message, error)

SendVideo sends Video.

func (*API) SendVoice Uses

func (c *API) SendVoice(
    ctx context.Context,
    cfg VoiceCfg) (*Message, error)

SendVoice sends Voice.

func (*API) SetWebhook Uses

func (c *API) SetWebhook(ctx context.Context, cfg WebhookCfg) error

SetWebhook sets a webhook. Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON‐serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts.

If this is set, GetUpdates will not get any data!

If you do not have a legitimate TLS certificate, you need to include your self signed certificate with the config.

func (*API) UnbanChatMember Uses

func (c *API) UnbanChatMember(
    ctx context.Context,
    cfg UnbanChatMemberCfg) (bool, error)

UnbanChatMember unbans a previously kicked user in a supergroup. The user will not return to the group automatically, but will be able to join via link, etc. The bot must be an administrator in the group for this to work. Returns True on success.

type APIError Uses

type APIError struct {
    Description string `json:"description"`
    // ErrorCode contents are subject to change in the future.
    ErrorCode int `json:"error_code"`
}

APIError contains error information from response

func (*APIError) Error Uses

func (e *APIError) Error() string

Error returns string representation for ApiError

type APIResponse Uses

type APIResponse struct {
    Ok          bool             `json:"ok"`
    Result      *json.RawMessage `json:"result"`
    ErrorCode   int              `json:"error_code,omitempty"`
    Description string           `json:"description,omitempty"`
}

APIResponse is a response from the Telegram API with the result stored raw.

type AnswerCallbackCfg Uses

type AnswerCallbackCfg struct {
    CallbackQueryID string `json:"callback_query_id"`
    Text            string `json:"text"`
    ShowAlert       bool   `json:"show_alert"`
}

AnswerCallbackCfg contains information on making a anserCallbackQuery response.

func NewAnswerCallback Uses

func NewAnswerCallback(id, text string) AnswerCallbackCfg

NewAnswerCallback creates a new callback message.

func NewAnswerCallbackWithAlert Uses

func NewAnswerCallbackWithAlert(id, text string) AnswerCallbackCfg

NewAnswerCallbackWithAlert creates a new callback message that alerts the user.

func (AnswerCallbackCfg) Name Uses

func (cfg AnswerCallbackCfg) Name() string

Name returns method name

func (AnswerCallbackCfg) Values Uses

func (cfg AnswerCallbackCfg) Values() (url.Values, error)

Values returns a url.Values representation of AnswerCallbackCfg. Returns a RequiredError if Action is empty.

type AnswerInlineQueryCfg Uses

type AnswerInlineQueryCfg struct {
    // Unique identifier for the answered query
    InlineQueryID string              `json:"inline_query_id"`
    Results       []InlineQueryResult `json:"results"`
    // The maximum amount of time in seconds
    // that the result of the inline query may be cached on the server.
    // Defaults to 300.
    CacheTime int `json:"cache_time,omitempty"`
    // Pass True, if results may be cached on the server side
    // only for the user that sent the query.
    // By default, results may be returned to any user
    // who sends the same query
    IsPersonal bool `json:"is_personal,omitempty"`
    // Pass the offset that a client should send in the next query
    // with the same text to receive more results.
    // Pass an empty string if there are no more results
    // or if you don‘t support pagination.
    // Offset length can’t exceed 64 bytes.
    NextOffset string `json:"next_offset,omitempty"`
    // If passed, clients will display a button with specified text
    // that switches the user to a private chat with the bot and
    // sends the bot a start message with the parameter switch_pm_parameter
    SwitchPMText string `json:"switch_pm_text,omitempty"`
    // Parameter for the start message sent to the bot
    // when user presses the switch button
    SwitchPMParameter string `json:"switch_pm_parameter"`
}

AnswerInlineQueryCfg contains information on making an InlineQuery response.

func (AnswerInlineQueryCfg) Name Uses

func (cfg AnswerInlineQueryCfg) Name() string

Name returns method name

func (AnswerInlineQueryCfg) Values Uses

func (cfg AnswerInlineQueryCfg) Values() (url.Values, error)

Values returns a url.Values representation of AnswerInlineQueryCfg. Returns a RequiredError if Action is empty.

type Audio Uses

type Audio struct {
    MetaFile

    // Duration of the recording in seconds as defined by sender.
    Duration int `json:"duration"`
    //  Performer of the audio as defined by sender
    // or by audio tags. Optional.
    Performer string `json:"performer,omitempty"`
    // Title of the audio as defined by sender
    // or by audio tags. Optional.
    Title string `json:"title,omitempty"`
    // MIMEType of the file as defined by sender. Optional.
    MIMEType string `json:"mime_type,omitempty"`
}

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

type AudioCfg Uses

type AudioCfg struct {
    BaseFile
    Duration  int
    Performer string
    Title     string
}

AudioCfg contains information about a SendAudio request. Use it to send information about an audio Implements Filer and Messenger interfaces.

func (AudioCfg) Field Uses

func (cfg AudioCfg) Field() string

Field returns name for audio file data

func (AudioCfg) Name Uses

func (cfg AudioCfg) Name() string

Name returns method name

func (AudioCfg) Values Uses

func (cfg AudioCfg) Values() (url.Values, error)

Values returns a url.Values representation of AudioCfg.

type BaseChat Uses

type BaseChat struct {
    // Unique identifier for the target chat
    ID  int64
    // Username of the target channel (in the format @channelusername)
    ChannelUsername string
}

BaseChat describes chat settings. It's an abstract type.

You must set ID or ChannelUsername.

func (*BaseChat) SetChatID Uses

func (c *BaseChat) SetChatID(id int64)

SetChatID sets new chat id

func (BaseChat) Values Uses

func (c BaseChat) Values() (url.Values, error)

Values returns RequiredError if neither ID or ChannelUsername are empty. Prefers ChannelUsername if both ID and ChannelUsername are not empty.

type BaseEdit Uses

type BaseEdit struct {
    // Required if inline_message_id is not specified.
    // Unique identifier for the target chat or
    // username of the target channel (in the format @channelusername)
    ChatID          int64
    ChannelUsername string
    // Required if inline_message_id is not specified.
    // Unique identifier of the sent message
    MessageID int64
    // Required if chat_id and message_id are not specified.
    // Identifier of the inline message
    InlineMessageID string
    // Only InlineKeyboardMarkup supported right now.
    ReplyMarkup ReplyMarkup
}

BaseEdit is base type of all chat edits.

func (BaseEdit) Values Uses

func (m BaseEdit) Values() (url.Values, error)

Values returns a url.Values representation of BaseEdit.

type BaseFile Uses

type BaseFile struct {
    BaseMessage
    FileID    string
    MimeType  string
    InputFile InputFile
}

BaseFile describes file settings. It's an abstract type.

func (BaseFile) Exist Uses

func (b BaseFile) Exist() bool

Exist returns true if file exists on telegram servers

func (BaseFile) File Uses

func (b BaseFile) File() InputFile

File returns InputFile object that are used to create request

func (BaseFile) GetFileID Uses

func (b BaseFile) GetFileID() string

GetFileID returns fileID if it's exist

func (*BaseFile) Reset Uses

func (b *BaseFile) Reset(i InputFile)

Reset method removes FileID and sets new InputFile

func (BaseFile) Values Uses

func (b BaseFile) Values() (url.Values, error)

Values returns a url.Values representation of BaseFile.

type BaseInlineQueryResult Uses

type BaseInlineQueryResult struct {
    Type                string              `json:"type"` // required
    ID                  string              `json:"id"`   // required
    InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
    // ReplyMarkup supports only InlineKeyboardMarkup for InlineQueryResult
    ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
}

BaseInlineQueryResult is a base class for InlineQueryResult

type BaseMessage Uses

type BaseMessage struct {
    BaseChat
    // If the message is a reply, ID of the original message
    ReplyToMessageID int64
    // Additional interface options.
    // A JSON-serialized object for a custom reply keyboard,
    // instructions to hide keyboard or to force a reply from the user.
    ReplyMarkup ReplyMarkup
    // Sends the message silently.
    // iOS users will not receive a notification,
    // Android users will receive a notification with no sound.
    // Other apps coming soon.
    DisableNotification bool
}

BaseMessage is a base type for all message config types. Implements Messenger interface.

func (BaseMessage) Message Uses

func (BaseMessage) Message() *Message

Message returns instance of *Message type.

func (BaseMessage) Values Uses

func (m BaseMessage) Values() (url.Values, error)

Values returns url.Values representation of BaseMessage

type CallbackQuery Uses

type CallbackQuery struct {
    // Unique identifier for this query
    ID  string `json:"id"`
    // Sender
    From *User `json:"from"`
    // 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. Optional.
    Message *Message `json:"message,omitempty"`
    // Identifier of the message sent via the bot in inline mode,
    // that originated the query. Optional.
    InlineMessageID string `json:"inline_message_id,omitempty"`
    // Data associated with the callback button.
    // Be aware that a bad client can send arbitrary data in this field
    Data string `json:"data"`
}

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 presented. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be presented.

type Chat Uses

type Chat struct {
    // ID is a Unique identifier for this chat, not exceeding 1e13 by absolute value.
    ID  int64 `json:"id"`
    // Type of chat, can be either “private”, “group”, "supergroup" or “channel”
    Type string `json:"type"`

    Title     string `json:"title,omitempty"`
    FirstName string `json:"first_name,omitempty"`
    LastName  string `json:"last_name,omitempty"`
    Username  string `json:"username,omitempty"`
}

Chat object represents a Telegram user, bot or group chat. Title for channels and group chats

type ChatActionCfg Uses

type ChatActionCfg struct {
    BaseChat
    // Type of action to broadcast.
    // Choose one, depending on what the user is about to receive:
    // typing for text messages, upload_photo for photos,
    // record_video or upload_video for videos,
    // record_audio or upload_audio for audio files,
    // upload_document for general files,
    // find_location for location data.
    // Use one of constants: ActionTyping, ActionFindLocation, etc
    Action string
}

ChatActionCfg contains information about a SendChatAction request. Action field is required.

func NewChatAction Uses

func NewChatAction(chatID int64, action string) ChatActionCfg

NewChatAction sets a chat action. Actions last for 5 seconds, or until your next action.

chatID is where to send it, action should be set via Action constants.

func (ChatActionCfg) Name Uses

func (cfg ChatActionCfg) Name() string

Name returns method name

func (ChatActionCfg) Values Uses

func (cfg ChatActionCfg) Values() (url.Values, error)

Values returns a url.Values representation of ChatActionCfg. Returns a RequiredError if Action is empty.

type ChatMember Uses

type ChatMember struct {
    // Information about the user.
    User User `json:"user"`
    // The member's status in the chat.
    // One of MemberStatus constants.
    Status string `json:"status"`
}

ChatMember object contains information about one member of the chat.

type ChosenInlineResult Uses

type ChosenInlineResult struct {
    // ResultID is a unique identifier for the result that was chosen.
    ResultID string `json:"result_id"`
    // From is a user that chose the result.
    From User `json:"from"`
    // Query is used to obtain the result.
    Query string `json:"query"`
}

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

type Contact Uses

type Contact struct {
    PhoneNumber string `json:"phone_number"`
    FirstName   string `json:"first_name"`

    // UserID is a contact's user identifier in Telegram. Optional.
    UserID   int64  `json:"user_id,omitempty"`
    LastName string `json:"last_name,omitempty"`
}

Contact object represents a phone contact of Telegram user

func (Contact) Values Uses

func (c Contact) Values() url.Values

Values returns a url.Values representation of Contact object.

type ContactCfg Uses

type ContactCfg struct {
    BaseMessage
    Contact
}

ContactCfg contains information about a SendContact request. Use it to send information about a venue Implements Messenger interface.

func (ContactCfg) Name Uses

func (cfg ContactCfg) Name() string

Name returns method name

func (ContactCfg) Values Uses

func (cfg ContactCfg) Values() (url.Values, error)

Values returns a url.Values representation of ContactCfg. Returns RequiredError if Text is empty.

type DebugFunc Uses

type DebugFunc func(msg string, fields map[string]interface{})

DebugFunc describes function for debugging.

type Document Uses

type Document struct {
    MetaFile

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

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

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

Document object represents a general file (as opposed to Photo or Audio). Telegram users can send files of any type of up to 1.5 GB in size.

type DocumentCfg Uses

type DocumentCfg struct {
    BaseFile
}

DocumentCfg contains information about a SendDocument request. Use it to send information about a documents Implements Filer and Messenger interfaces.

func (DocumentCfg) Field Uses

func (cfg DocumentCfg) Field() string

Field returns name for document file data

func (DocumentCfg) Name Uses

func (cfg DocumentCfg) Name() string

Name returns method name

func (DocumentCfg) Values Uses

func (cfg DocumentCfg) Values() (url.Values, error)

Values returns a url.Values representation of DocumentCfg.

type EditMessageCaptionCfg Uses

type EditMessageCaptionCfg struct {
    BaseEdit
    // New caption of the message
    Caption string
}

EditMessageCaptionCfg allows you to modify the caption of a message.

func NewEditMessageCaption Uses

func NewEditMessageCaption(chatID, messageID int64, caption string) EditMessageCaptionCfg

NewEditMessageCaption allows you to edit the caption of a message.

func (EditMessageCaptionCfg) Name Uses

func (EditMessageCaptionCfg) Name() string

Name returns method name

func (EditMessageCaptionCfg) Values Uses

func (cfg EditMessageCaptionCfg) Values() (url.Values, error)

Values returns a url.Values representation of EditMessageCaptionCfg.

type EditMessageReplyMarkupCfg Uses

type EditMessageReplyMarkupCfg struct {
    BaseEdit
}

EditMessageReplyMarkupCfg allows you to modify the reply markup of a message.

func NewEditMessageReplyMarkup Uses

func NewEditMessageReplyMarkup(chatID, messageID int64, replyMarkup *InlineKeyboardMarkup) EditMessageReplyMarkupCfg

NewEditMessageReplyMarkup allows you to edit the inline keyboard markup.

func (EditMessageReplyMarkupCfg) Name Uses

func (EditMessageReplyMarkupCfg) Name() string

Name returns method name

func (EditMessageReplyMarkupCfg) Values Uses

func (cfg EditMessageReplyMarkupCfg) Values() (url.Values, error)

Values returns a url.Values representation of EditMessageReplyMarkupCfg.

type EditMessageTextCfg Uses

type EditMessageTextCfg struct {
    BaseEdit
    // New text of the message
    Text string
    // Send Markdown or HTML, if you want Telegram apps
    // to show bold, italic, fixed-width text
    // or inline URLs in your bot's message. Optional.
    ParseMode string
    // Disables link previews for links in this message. Optional.
    DisableWebPagePreview bool
}

EditMessageTextCfg allows you to modify the text in a message.

func NewEditMessageText Uses

func NewEditMessageText(chatID, messageID int64, text string) EditMessageTextCfg

NewEditMessageText allows you to edit the text of a message.

func (EditMessageTextCfg) Name Uses

func (EditMessageTextCfg) Name() string

Name returns method name

func (EditMessageTextCfg) Values Uses

func (cfg EditMessageTextCfg) Values() (url.Values, error)

Values returns a url.Values representation of EditMessageTextCfg.

type EditResult Uses

type EditResult struct {
    Message *Message
    Ok      bool
}

EditResult is an option type, because telegram may return bool or Message

func (*EditResult) UnmarshalJSON Uses

func (e *EditResult) UnmarshalJSON(data []byte) error

UnmarshalJSON helps to parse EditResult. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

type File Uses

type File struct {
    MetaFile
    // FilePath is a relative path to file.
    // Use https://api.telegram.org/file/bot<token>/<file_path>
    // to get the file.
    FilePath string `json:"file_path,omitempty"`

    // Link is inserted by Api client after GetFile request
    Link string `json:"link"`
}

File object represents any sort of file. The file can be downloaded via the Link. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling GetFile. Maximum file size to download is 20 MB.

type FileCfg Uses

type FileCfg struct {
    FileID string
}

FileCfg has information about a file hosted on Telegram.

func (FileCfg) Name Uses

func (cfg FileCfg) Name() string

Name returns method name

func (FileCfg) Values Uses

func (cfg FileCfg) Values() (url.Values, error)

Values returns a url.Values representation of FileCfg.

type Filer Uses

type Filer interface {
    // Field name for file data
    Field() string
    // File data
    File() InputFile
    // Exist returns true if file exists on telegram servers
    Exist() bool
    // Reset removes FileID and sets new InputFile
    // Reset(InputFile)
    // GetFileID returns fileID if it's exist
    GetFileID() string
}

Filer is any config type that can be sent that includes a file.

type ForceReply Uses

type ForceReply struct {
    MarkReplyMarkup

    ForceReply bool `json:"force_reply"`
    Selective  bool `json:"selective"` // optional
}

ForceReply allows the Bot to have users directly reply to it without additional interaction. Implements ReplyMarkup interface.

type ForwardMessageCfg Uses

type ForwardMessageCfg struct {
    BaseChat
    // Unique identifier for the chat where the original message was sent
    FromChat BaseChat
    // Unique message identifier
    MessageID int64
    // Sends the message silently.
    // iOS users will not receive a notification,
    // Android users will receive a notification with no sound.
    // Other apps coming soon.
    DisableNotification bool
}

ForwardMessageCfg contains information about a ForwardMessage request. Use it to forward messages of any kind Implements Messenger interface.

func NewForwardMessage Uses

func NewForwardMessage(chatID, fromChatID, messageID int64) ForwardMessageCfg

NewForwardMessage creates a new Message.

chatID is where to send it, text is the message text.

func (ForwardMessageCfg) Message Uses

func (ForwardMessageCfg) Message() *Message

Message returns instance of *Message type.

func (ForwardMessageCfg) Name Uses

func (cfg ForwardMessageCfg) Name() string

Name returns method name

func (ForwardMessageCfg) Values Uses

func (cfg ForwardMessageCfg) Values() (url.Values, error)

Values returns a url.Values representation of MessageCfg. Returns RequiredError if Text is empty.

type GetChatAdministratorsCfg Uses

type GetChatAdministratorsCfg struct {
    BaseChat
}

GetChatAdministratorsCfg contains information about a getChat request.

func (GetChatAdministratorsCfg) Name Uses

func (cfg GetChatAdministratorsCfg) Name() string

Name returns method name

func (GetChatAdministratorsCfg) Values Uses

func (cfg GetChatAdministratorsCfg) Values() (url.Values, error)

Values returns a url.Values representation of GetChatCfg. Returns RequiredError if Chat is not set.

type GetChatCfg Uses

type GetChatCfg struct {
    BaseChat
}

GetChatCfg contains information about a getChat request.

func (GetChatCfg) Name Uses

func (cfg GetChatCfg) Name() string

Name returns method name

func (GetChatCfg) Values Uses

func (cfg GetChatCfg) Values() (url.Values, error)

Values returns a url.Values representation of GetChatCfg. Returns RequiredError if Chat is not set.

type GetChatMemberCfg Uses

type GetChatMemberCfg struct {
    BaseChat
    UserID int64 `json:"user_id"`
}

GetChatMemberCfg contains information about a getChatMember request.

func (GetChatMemberCfg) Name Uses

func (cfg GetChatMemberCfg) Name() string

Name returns method name

func (GetChatMemberCfg) Values Uses

func (cfg GetChatMemberCfg) Values() (url.Values, error)

Values returns a url.Values representation of GetChatMemberCfg. Returns RequiredError if Chat or UserID are not set.

type GetChatMembersCountCfg Uses

type GetChatMembersCountCfg struct {
    BaseChat
}

GetChatMembersCountCfg contains information about a getChatMemberCount request.

func (GetChatMembersCountCfg) Name Uses

func (cfg GetChatMembersCountCfg) Name() string

Name returns method name

func (GetChatMembersCountCfg) Values Uses

func (cfg GetChatMembersCountCfg) Values() (url.Values, error)

Values returns a url.Values representation of GetChatMembersCountCfg. Returns RequiredError if Chat is not set.

type HTTPDoer Uses

type HTTPDoer interface {
    Do(*http.Request) (*http.Response, error)
}

HTTPDoer interface helps to test api

type InlineKeyboardButton Uses

type InlineKeyboardButton struct {
    // Label text on the button
    Text string `json:"text"`
    // HTTP url to be opened when button is pressed. Optional.
    URL string `json:"url,omitempty"`
    // Data to be sent in a callback query to the bot
    // when button is pressed. Optional.
    CallbackData string `json:"callback_data,omitempty"`
    // 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.
    // Optional.
    //
    // 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"`
}

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

Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will display unsupported message.

type InlineKeyboardMarkup Uses

type InlineKeyboardMarkup struct {
    MarkReplyMarkup

    InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}

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

Warning: Inline keyboards are currently being tested and are only available in one‐on‐one chats (i.e., user‐bot or user‐user in the case of inline bots). Note: This will only work in Telegram versions released after 9 April, 2016. Older clients will display unsupported message.

type InlineQuery Uses

type InlineQuery struct {
    // ID is a unique identifier for this query.
    ID  string `json:"id"`
    // From is a sender.
    From User `json:"from"`
    // Sender location, only for bots that request user location.
    // Optional.
    Location *Location `json:"location,omitempty"`
    // Query is a text of the query.
    Query string `json:"query"`
    // Offset of the results to be returned, can be controlled by the bot.
    Offset string `json:"offset"`
}

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

type InlineQueryResult Uses

type InlineQueryResult interface {
    // InlineQueryResult is a fake method that helps to identify implementations
    InlineQueryResult()
}

InlineQueryResult interface represents one result of an inline query. Telegram clients currently support results of the following 19 types:

- InlineQueryResultCachedAudio - InlineQueryResultCachedDocument - InlineQueryResultCachedGif - InlineQueryResultCachedMpeg4Gif - InlineQueryResultCachedPhoto - InlineQueryResultCachedSticker - InlineQueryResultCachedVideo - InlineQueryResultCachedVoice - InlineQueryResultArticle - InlineQueryResultAudio - InlineQueryResultContact - InlineQueryResultDocument - InlineQueryResultGif - InlineQueryResultLocation - InlineQueryResultMpeg4Gif - InlineQueryResultPhoto - InlineQueryResultVenue - InlineQueryResultVideo - InlineQueryResultVoice

type InlineQueryResultArticle Uses

type InlineQueryResultArticle struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb

    Title string `json:"title"` // required
    URL   string `json:"url,omitempty"`
    // Optional. Pass True, if you don't want the URL
    // to be shown in the message
    HideURL     bool   `json:"hide_url,omitempty"`
    Description string `json:"description,omitempty"`
}

InlineQueryResultArticle is an inline query response article.

func NewInlineQueryResultArticle Uses

func NewInlineQueryResultArticle(id, title, messageText string) *InlineQueryResultArticle

NewInlineQueryResultArticle creates a new inline query article.

type InlineQueryResultAudio Uses

type InlineQueryResultAudio struct {
    MarkInlineQueryResult
    BaseInlineQueryResult

    AudioURL      string `json:"audio_url"` // required
    Title         string `json:"title"`     // required
    Performer     string `json:"performer"`
    AudioDuration int    `json:"audio_duration"`
}

InlineQueryResultAudio is an inline query response audio.

type InlineQueryResultContact Uses

type InlineQueryResultContact struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb
    Contact
}

InlineQueryResultContact represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact.

type InlineQueryResultDocument Uses

type InlineQueryResultDocument struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb

    DocumentURL string `json:"document_url"` // required
    // Mime type of the content of the file,
    // either “application/pdf” or “application/zip”
    MimeType string `json:"mime_type"` // required
    // Title for the result
    Title string `json:"title"` // required
    // Optional. Caption of the document to be sent, 0-200 characters
    Caption string `json:"caption,omitempty"`
    // Optional. Short description of the result
    Description string `json:"description,omitempty"`
}

InlineQueryResultDocument is an inline query response document.

type InlineQueryResultGIF Uses

type InlineQueryResultGIF struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb

    // A valid URL for the GIF file. File size must not exceed 1MB
    GifURL    string `json:"gif_url"` // required
    GifWidth  int    `json:"gif_width,omitempty"`
    GifHeight int    `json:"gif_height,omitempty"`
    Title     string `json:"title,omitempty"`
    Caption   string `json:"caption,omitempty"`
}

InlineQueryResultGIF is an inline query response GIF.

type InlineQueryResultLocation Uses

type InlineQueryResultLocation struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb

    Latitude  float64 `json:"latitude"`  // required
    Longitude float64 `json:"longitude"` // required
    Title     string  `json:"title"`     // required
}

InlineQueryResultLocation is an inline query response location.

type InlineQueryResultMPEG4GIF Uses

type InlineQueryResultMPEG4GIF struct {
    MarkInlineQueryResult
    BaseInlineQueryResult

    MPEG4URL    string `json:"mpeg4_url"` // required
    MPEG4Width  int    `json:"mpeg4_width,omitempty"`
    MPEG4Height int    `json:"mpeg4_height,omitempty"`
    Title       string `json:"title,omitempty"`
    Caption     string `json:"caption,omitempty"`
}

InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.

type InlineQueryResultPhoto Uses

type InlineQueryResultPhoto struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb

    PhotoURL    string `json:"photo_url"` // required
    PhotoWidth  int    `json:"photo_width,omitempty"`
    PhotoHeight int    `json:"photo_height,omitempty"`
    MimeType    string `json:"mime_type,omitempty"`
    Title       string `json:"title,omitempty"`
    Description string `json:"description,omitempty"`
    Caption     string `json:"caption,omitempty"`
}

InlineQueryResultPhoto is an inline query response photo.

type InlineQueryResultVenue Uses

type InlineQueryResultVenue struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb
    Venue
}

InlineQueryResultVenue represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue.

type InlineQueryResultVideo Uses

type InlineQueryResultVideo struct {
    MarkInlineQueryResult
    BaseInlineQueryResult
    InlineThumb

    VideoURL      string `json:"video_url"` // required
    MimeType      string `json:"mime_type"` // required
    Title         string `json:"title,omitempty"`
    Caption       string `json:"caption,omitempty"`
    VideoWidth    int    `json:"video_width,omitempty"`
    VideoHeight   int    `json:"video_height,omitempty"`
    VideoDuration int    `json:"video_duration,omitempty"`
    Description   string `json:"description,omitempty"`
}

InlineQueryResultVideo is an inline query response video.

type InlineQueryResultVoice Uses

type InlineQueryResultVoice struct {
    MarkInlineQueryResult
    BaseInlineQueryResult

    VoiceURL string `json:"voice_url"` // required
    Title    string `json:"title"`     // required
    Duration int    `json:"voice_duration,omitempty"`
}

InlineQueryResultVoice is an inline query response voice.

type InlineThumb Uses

type InlineThumb struct {
    ThumbURL    string `json:"thumb_url,omitempty"`
    ThumbWidth  int    `json:"thumb_width,omitempty"`
    ThumbHeight int    `json:"thumb_height,omitempty"`
}

InlineThumb struct helps to describe thumbnail.

type InputContactMessageContent Uses

type InputContactMessageContent struct {
    MarkInputMessageContent
    Contact
}

InputContactMessageContent contains a contact for displaying as an inline query result. Implements InputMessageContent

type InputFile Uses

type InputFile interface {
    Reader() io.Reader
    Name() string
}

InputFile describes interface for input files.

func NewBytesFile Uses

func NewBytesFile(filename string, data []byte) InputFile

NewBytesFile takes byte slice and returns InputFile.

func NewInputFile Uses

func NewInputFile(filename string, r io.Reader) InputFile

NewInputFile takes Reader object and returns InputFile.

type InputLocationMessageContent Uses

type InputLocationMessageContent struct {
    MarkInputMessageContent
    Location
}

InputLocationMessageContent contains a location for displaying as an inline query result. Implements InputMessageContent

type InputMessageContent Uses

type InputMessageContent interface {
    // MessageContent is a fake method that helps to identify implementations
    InputMessageContent()
}

InputMessageContent interface represents the content of a message to be sent as a result of an inline query. Telegram clients currently support the following 4 types:

- InputTextMessageContent
- InputLocationMessageContent
- InputVenueMessageContent
- InputContactMessageContent

type InputTextMessageContent Uses

type InputTextMessageContent struct {
    MarkInputMessageContent

    // Text of the message to be sent, 1‐4096 characters
    MessageText string `json:"message_text"`
    // Send Markdown or HTML, if you want Telegram apps to show
    // bold, italic, fixed‐width text or inline URLs in your bot's message.
    // Use Mode constants. Optional.
    ParseMode string `json:"parse_mode,omitempty"`
    // Disables link previews for links in this message.
    DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
}

InputTextMessageContent represents the content of a text message to be sent as the result of an inline query.

type InputVenueMessageContent Uses

type InputVenueMessageContent struct {
    MarkInputMessageContent
    Venue
}

InputVenueMessageContent contains a venue for displaying as an inline query result. Implements InputMessageContent

type KeyboardButton Uses

type KeyboardButton struct {
    // Text of the button. If none of the optional fields are used,
    // it will be sent to the bot as a message when the button is pressed
    Text string `json:"text"`
    // If true, the user's phone number will be sent as a contact
    // when the button is pressed. Available in private chats only.
    // Optional.
    RequestContact bool `json:"request_contact,omitempty"`
    // If true, the user's current location will be sent
    // when the button is pressed. Available in private chats only.
    // Optional.
    RequestLocation bool `json:"request_location,omitempty"`
}

KeyboardButton object represents one button of the reply keyboard. Optional fields are mutually exclusive.

Note: request_contact and request_location options will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them.

type KickChatMemberCfg Uses

type KickChatMemberCfg struct {
    BaseChat
    UserID int64 `json:"user_id"`
}

KickChatMemberCfg contains information about a kickChatMember request.

func (KickChatMemberCfg) Name Uses

func (cfg KickChatMemberCfg) Name() string

Name returns method name

func (KickChatMemberCfg) Values Uses

func (cfg KickChatMemberCfg) Values() (url.Values, error)

Values returns a url.Values representation of KickChatMemberCfg. Returns RequiredError if Chat or UserID are not set.

type LeaveChatCfg Uses

type LeaveChatCfg struct {
    BaseChat
}

LeaveChatCfg contains information about a leaveChat request.

func (LeaveChatCfg) Name Uses

func (cfg LeaveChatCfg) Name() string

Name returns method name

func (LeaveChatCfg) Values Uses

func (cfg LeaveChatCfg) Values() (url.Values, error)

Values returns a url.Values representation of LeaveChatCfg. Returns RequiredError if Chat is not set.

type Location Uses

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

Location object represents geographic position.

func (Location) Values Uses

func (l Location) Values() url.Values

Values returns a url.Values representation of Location object.

type LocationCfg Uses

type LocationCfg struct {
    BaseMessage
    Location
}

LocationCfg contains information about a SendLocation request.

func NewLocation Uses

func NewLocation(chatID int64, lat float64, lon float64) LocationCfg

NewLocation shares your location.

chatID is where to send it, latitude and longitude are coordinates.

func (LocationCfg) Name Uses

func (cfg LocationCfg) Name() string

Name method returns Telegram API method name for sending Location.

func (LocationCfg) Values Uses

func (cfg LocationCfg) Values() (url.Values, error)

Values returns a url.Values representation of LocationCfg.

type MarkInlineQueryResult Uses

type MarkInlineQueryResult struct{}

A MarkInlineQueryResult implements InlineQueryResult interface. You can mark your structures with this object.

func (MarkInlineQueryResult) InlineQueryResult Uses

func (MarkInlineQueryResult) InlineQueryResult()

InlineQueryResult is a fake method that helps to identify implementations

type MarkInputMessageContent Uses

type MarkInputMessageContent struct{}

A MarkInputMessageContent implements InputMessageContent interface. You can mark your structures with this object.

func (MarkInputMessageContent) InputMessageContent Uses

func (MarkInputMessageContent) InputMessageContent()

InputMessageContent is a fake method that helps to identify implementations

type MarkReplyMarkup Uses

type MarkReplyMarkup struct{}

A MarkReplyMarkup implements ReplyMarkup interface. You can mark your structures with this object.

func (MarkReplyMarkup) ReplyMarkup Uses

func (MarkReplyMarkup) ReplyMarkup()

ReplyMarkup is a fake method that helps to identify implementations

type MeCfg Uses

type MeCfg struct{}

MeCfg contains information about a getMe request.

func (MeCfg) Name Uses

func (cfg MeCfg) Name() string

Name returns method name

func (MeCfg) Values Uses

func (cfg MeCfg) Values() (url.Values, error)

Values for getMe is empty

type Message Uses

type Message struct {
    // MessageID is a unique message identifier.
    MessageID int64 `json:"message_id"`

    // From is a sender, can be empty for messages sent to channels.
    // Optional.
    From *User `json:"from,omitempty"`
    // Date  the message was sent in Unix time.
    Date int `json:"date"`
    // Chat is a conversation the message belongs to.
    Chat Chat `json:"chat"`

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

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

    // ForwardDate is a unixtime of the original message
    // for forwarded messages. Optional.
    ForwardDate int `json:"forward_date"`

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

    // Date the message was last edited in Unix time
    // Zero value means object wasn't edited.
    // Optional.
    EditDate int `json:"edit_date,omitempty"`

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

    // Text is an actual UTF-8 text of the message for a text message,
    // 0-4096 characters. Optional.
    Text string `json:"text,omitempty"`

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

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

    // Photo has a slice of available sizes of photo. Optional.
    Photo []PhotoSize `json:"photo,omitempty"`

    // Sticker has information about the sticker. Optional.
    Sticker *Sticker `json:"sticker,omitempty"`

    // For a video, information about it.
    Video *Video `json:"video,omitempty"`

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

    // Caption for the document, photo or video, 0‐200 characters
    Caption string `json:"caption,omitempty"`

    // For a contact, contact information itself.
    Contact *Contact `json:"contact,omitempty"`

    // For a location, its longitude and latitude.
    Location *Location `json:"location,omitempty"`

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

    // NewChatMember has an information about a new member
    // that was added to the group
    // (this member may be the bot itself). Optional.
    NewChatMember *User `json:"new_chat_member,omitempty"`

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

    // For a service message, represents a new title
    // for chat this message came from.
    //
    // Sender would lead to a User, capable of change.
    NewChatTitle string `json:"new_chat_title,omitempty"`

    // For a service message, represents all available
    // thumbnails of new chat photo.
    //
    // Sender would lead to a User, capable of change.
    NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"`

    // For a service message, true if chat photo just
    // got removed.
    //
    // Sender would lead to a User, capable of change.
    DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"`

    // For a service message, true if group has been created.
    //
    // You would receive such a message if you are one of
    // initial group chat members.
    //
    // Sender would lead to creator of the chat.
    GroupChatCreated bool `json:"group_chat_created,omitempty"`

    // For a service message, true if super group has been created.
    //
    // You would receive such a message if you are one of
    // initial group chat members.
    //
    // Sender would lead to creator of the chat.
    SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"`

    // For a service message, true if channel has been created.
    //
    // You would receive such a message if you are one of
    // initial channel administrators.
    //
    // Sender would lead to creator of the chat.
    ChannelChatCreated bool `json:"channel_chat_created,omitempty"`

    // For a service message, the destination (super group) you
    // migrated to.
    //
    // You would receive such a message when your chat has migrated
    // to a super group.
    //
    // Sender would lead to creator of the migration.
    MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`

    // For a service message, the Origin (normal group) you migrated
    // from.
    //
    // You would receive such a message when your chat has migrated
    // to a super group.
    //
    // Sender would lead to creator of the migration.
    MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"`
    // 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"`
}

Message object represents a message.

func (*Message) Command Uses

func (m *Message) Command() (string, string)

Command checks if the message was a command and if it was, returns the command and agrument. If the Message was not a command, it returns an empty strings.

If the command contains the at bot syntax, it removes the bot name.

func (*Message) IsCommand Uses

func (m *Message) IsCommand() bool

IsCommand returns true if message starts with '/'.

type MessageCfg Uses

type MessageCfg struct {
    BaseMessage
    Text string
    // Send Markdown or HTML, if you want Telegram apps to show
    // bold, italic, fixed-width text or inline URLs in your bot's message.
    // Use one of constants: ModeHTML, ModeMarkdown.
    ParseMode string
    // Disables link previews for links in this message.
    DisableWebPagePreview bool
}

MessageCfg contains information about a SendMessage request. Use it to send text messages. Implements Messenger interface.

func NewMessage Uses

func NewMessage(chatID int64, text string) MessageCfg

NewMessage creates a new Message.

chatID is where to send it, text is the message text.

func NewMessagef Uses

func NewMessagef(chatID int64, text string, args ...interface{}) MessageCfg

NewMessagef creates a new Message with formatting.

chatID is where to send it, text is the message text

func (MessageCfg) Name Uses

func (cfg MessageCfg) Name() string

Name returns method name

func (MessageCfg) Values Uses

func (cfg MessageCfg) Values() (url.Values, error)

Values returns a url.Values representation of MessageCfg. Returns RequiredError if Text is empty.

type MessageEntity Uses

type MessageEntity struct {
    // Type of the entity. One of mention ( @username ), hashtag,
    // bot_command, url, email, bold (bold text),
    // italic (italic text), code (monowidth string),
    // pre (monowidth block), text_link (for clickable text URLs),
    // text_mention (for users without usernames)
    // Use constants SomethingEntityType instead of string.
    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"`
    // For “text_link” only, url that will be opened
    // after user taps on the text. Optional
    URL string `json:"url,omitempty"`
    // For “text_mention” only, the mentioned user. Optional.
    User *User `json:"user,omitempty"`
}

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

type Messenger Uses

type Messenger interface {
    Method
    Message() *Message
}

Messenger is a virtual interface to distinct methods that return Message from others.BaseMessage

func CloneMessage Uses

func CloneMessage(msg *Message, baseMessage *BaseMessage) Messenger

CloneMessage convert message to Messenger type to send it to another chat. It supports only data message: Text, Sticker, Audio, Photo, Location, Contact, Audio, Voice, Document.

type MetaFile Uses

type MetaFile struct {
    // FileID is a Unique identifier for this file.
    FileID string `json:"file_id"`
    // FileSize is a size of file if known. Optional.
    FileSize int `json:"file_size,omitempty"`
}

MetaFile represents meta information about file.

type Method Uses

type Method interface {
    // method name
    Name() string
    // method params
    Values() (url.Values, error)
}

Method describes interface for Telegram API request

Every method is https://api.telegram.org/bot<token>/METHOD_NAME Values are passed as application/x-www-form-urlencoded for usual request and multipart/form-data when files are uploaded.

type PhotoCfg Uses

type PhotoCfg struct {
    BaseFile
    Caption string
}

PhotoCfg contains information about a SendPhoto request. Use it to send information about a venue Implements Filer and Messenger interfaces.

func NewPhotoShare Uses

func NewPhotoShare(chatID int64, fileID string) PhotoCfg

NewPhotoShare creates a new photo uploader.

chatID is where to send it

func NewPhotoUpload Uses

func NewPhotoUpload(chatID int64, inputFile InputFile) PhotoCfg

NewPhotoUpload creates a new photo uploader.

chatID is where to send it, inputFile is a file representation.

func (PhotoCfg) Field Uses

func (cfg PhotoCfg) Field() string

Field returns name for photo file data

func (PhotoCfg) Name Uses

func (cfg PhotoCfg) Name() string

Name returns method name

func (PhotoCfg) Values Uses

func (cfg PhotoCfg) Values() (url.Values, error)

Values returns a url.Values representation of PhotoCfg.

type PhotoSize Uses

type PhotoSize struct {
    MetaFile
    Size
}

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

type ReplyKeyboardHide Uses

type ReplyKeyboardHide struct {
    MarkReplyMarkup

    HideKeyboard bool `json:"hide_keyboard"`
    Selective    bool `json:"selective"` // optional
}

ReplyKeyboardHide tells Telegram clients to hide the current custom keyboard and display the default letter-keyboard. Implements ReplyMarkup interface.

type ReplyKeyboardMarkup Uses

type ReplyKeyboardMarkup struct {
    MarkReplyMarkup

    // Array of button rows, each represented by an Array of Strings
    Keyboard [][]KeyboardButton `json:"keyboard"`
    // 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"`
    // 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"`
    // 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.
    Selective bool `json:"selective,omitempty"`
}

ReplyKeyboardMarkup represents a custom keyboard with reply options. Implements ReplyMarkup interface.

type ReplyMarkup Uses

type ReplyMarkup interface {
    // ReplyMarkup is a fake method that helps to identify implementations
    ReplyMarkup()
}

ReplyMarkup describes interface for reply_markup keyboards.

type RequiredError Uses

type RequiredError struct {
    Fields []string
}

RequiredError tells if fields are required but were not filled

func NewRequiredError Uses

func NewRequiredError(fields ...string) *RequiredError

NewRequiredError creates RequireError

func (*RequiredError) Error Uses

func (e *RequiredError) Error() string

Error returns string representation for RequiredError

type Size Uses

type Size struct {
    Width  int `json:"width"`
    Height int `json:"height"`
}

Size object represent size information.

type Sticker Uses

type Sticker struct {
    MetaFile
    Size // Sticker width and height

    // Sticker thumbnail in .webp or .jpg format. Optional.
    Thumb *PhotoSize `json:"thumb,omitempty"`
    // Emoji associated with the sticker. Optional.
    Emoji string `json:"emoji,omitempty"`
}

Sticker object represents a WebP image, so-called sticker.

type StickerCfg Uses

type StickerCfg struct {
    BaseFile
}

StickerCfg contains information about a SendSticker request. Implements Filer and Messenger interfaces.

func (StickerCfg) Field Uses

func (cfg StickerCfg) Field() string

Field returns name for sticker file data

func (StickerCfg) Name Uses

func (cfg StickerCfg) Name() string

Name method returns Telegram API method name for sending Sticker.

func (StickerCfg) Values Uses

func (cfg StickerCfg) Values() (url.Values, error)

Values returns a url.Values representation of StickerCfg.

type UnbanChatMemberCfg Uses

type UnbanChatMemberCfg struct {
    BaseChat
    UserID int64 `json:"user_id"`
}

UnbanChatMemberCfg contains information about a unbanChatMember request.

func (UnbanChatMemberCfg) Name Uses

func (cfg UnbanChatMemberCfg) Name() string

Name returns method name

func (UnbanChatMemberCfg) Values Uses

func (cfg UnbanChatMemberCfg) Values() (url.Values, error)

Values returns a url.Values representation of UnbanChatMemberCfg. Returns RequiredError if Chat or UserID are not set.

type Update Uses

type Update struct {
    // UpdateID is the update‘s unique identifier.
    // Update identifiers start from a certain positive number
    // and increase sequentially
    UpdateID int64 `json:"update_id"`
    // Message is a new incoming message of any kind:
    // text, photo, sticker, etc. Optional.
    Message *Message `json:"message,omitempty"`
    // New version of a message that is known to the bot and was edited.
    // Optional.
    EditedMessage *Message `json:"edited_message,omitempty"`
    // InlineQuery is a new incoming inline query. Optional.
    InlineQuery *InlineQuery `json:"inline_query,omitempty"`
    // ChosenInlineResult is a result of an inline query
    // that was chosen by a user and sent to their chat partner. Optional.
    ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
    // CallbackQuery is a new incoming callback query. Optional.
    CallbackQuery *CallbackQuery `json:"callback_query,omitempty"`
}

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

func (Update) Chat Uses

func (u Update) Chat() (chat *Chat)

Chat takes chat from Message and CallbackQuery

func (Update) From Uses

func (u Update) From() (from *User)

From takes User from Message, CallbackQuery, InlineQuery or ChosenInlineResult

func (Update) HasMessage Uses

func (u Update) HasMessage() bool

HasMessage returns true if update object contains Message field

func (Update) IsEdited Uses

func (u Update) IsEdited() bool

IsEdited returns true if update object contains EditedMessage field

type UpdateCfg Uses

type UpdateCfg 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 update_id. 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 int64
    // 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
    Timeout int
}

UpdateCfg contains information about a getUpdates request.

func NewUpdate Uses

func NewUpdate(offset int64) UpdateCfg

NewUpdate gets updates since the last Offset with Timeout 30 seconds

offset is the last Update ID to include. You likely want to set this to the last Update ID plus 1. 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.

func (UpdateCfg) Name Uses

func (cfg UpdateCfg) Name() string

Name returns method name

func (UpdateCfg) Values Uses

func (cfg UpdateCfg) Values() (url.Values, error)

Values returns getUpdate params. It returns error if Limit is not between 0 and 100. Zero params are not included to request.

type User Uses

type User struct {
    // ID is a unique identifier for this user or bot.
    ID  int64 `json:"id"`
    // FirstName is a user‘s or bot’s first name
    FirstName string `json:"first_name"`
    // LastName is a user‘s or bot’s last name. Optional.
    LastName string `json:"last_name,omitempty"`
    // Username is a user‘s or bot’s username. Optional.
    Username string `json:"username,omitempty"`
}

User object represents a Telegram user or bot.

object represents a group chat if Title is empty.

type UserProfilePhotos Uses

type UserProfilePhotos struct {
    // Total number of profile pictures the target user has
    TotalCount int `json:"total_count"`
    // Requested profile pictures (in up to 4 sizes each)
    Photos [][]PhotoSize `json:"photos"`
}

UserProfilePhotos contains a set of user profile pictures.

type UserProfilePhotosCfg Uses

type UserProfilePhotosCfg struct {
    UserID int64
    // Sequential number of the first photo to be returned.
    // By default, all photos are returned.
    Offset int
    // Limits the number of photos to be retrieved.
    // Values between 1—100 are accepted. Defaults to 100.
    Limit int
}

UserProfilePhotosCfg contains information about a GetUserProfilePhotos request.

func NewUserProfilePhotos Uses

func NewUserProfilePhotos(userID int64) UserProfilePhotosCfg

NewUserProfilePhotos gets user profile photos.

userID is the ID of the user you wish to get profile photos from.

func (UserProfilePhotosCfg) Name Uses

func (cfg UserProfilePhotosCfg) Name() string

Name returns method name

func (UserProfilePhotosCfg) Values Uses

func (cfg UserProfilePhotosCfg) Values() (url.Values, error)

Values returns a url.Values representation of UserProfilePhotosCfg. Returns RequiredError if UserID is empty.

type ValidationError Uses

type ValidationError struct {
    // Field name
    Field       string `json:"field"`
    Description string `json:"description"`
}

ValidationError tells if field has wrong value

func NewValidationError Uses

func NewValidationError(field string, description string) *ValidationError

NewValidationError creates ValidationError

func (*ValidationError) Error Uses

func (e *ValidationError) Error() string

Error returns string representation for ValidationError

type Venue Uses

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"`
    // Foursquare identifier of the venue. Optional.
    FoursquareID string `json:"foursquare_id,omitempty"`
}

Venue object represents a venue.

func (Venue) Values Uses

func (venue Venue) Values() url.Values

Values returns a url.Values representation of Venue object.

type VenueCfg Uses

type VenueCfg struct {
    BaseMessage
    Venue
}

VenueCfg contains information about a SendVenue request. Use it to send information about a venue Implements Messenger interface.

func (VenueCfg) Name Uses

func (cfg VenueCfg) Name() string

Name returns method name

func (VenueCfg) Values Uses

func (cfg VenueCfg) Values() (url.Values, error)

Values returns a url.Values representation of VenueCfg. Returns RequiredError if Text is empty.

type Video Uses

type Video struct {
    MetaFile
    Size

    // Duration of the recording in seconds as defined by sender.
    Duration int `json:"duration"`
    // MIMEType of the file as defined by sender. Optional.
    MIMEType string `json:"mime_type,omitempty"`
    // Video thumbnail. Optional.
    Thumb *PhotoSize `json:"thumb,omitempty"`
}

Video object represents an MP4-encoded video.

type VideoCfg Uses

type VideoCfg struct {
    BaseFile
    Duration int
    Caption  string
}

VideoCfg contains information about a SendVideo request. Use it to send information about a video Implements Filer and Messenger interfaces.

func (VideoCfg) Field Uses

func (cfg VideoCfg) Field() string

Field returns name for video file data

func (VideoCfg) Name Uses

func (cfg VideoCfg) Name() string

Name returns method name

func (VideoCfg) Values Uses

func (cfg VideoCfg) Values() (url.Values, error)

Values returns a url.Values representation of VideoCfg.

type Voice Uses

type Voice struct {
    MetaFile

    // Duration of the recording in seconds as defined by sender.
    Duration int `json:"duration"`
    // MIMEType of the file as defined by sender. Optional.
    MIMEType string `json:"mime_type,omitempty"`
}

Voice object represents a voice note.

type VoiceCfg Uses

type VoiceCfg struct {
    BaseFile
    Duration int
}

VoiceCfg contains information about a SendVoice request. Use it to send information about a venue Implements Filer and Messenger interfaces.

func (VoiceCfg) Field Uses

func (cfg VoiceCfg) Field() string

Field returns name for voice file data

func (VoiceCfg) Name Uses

func (cfg VoiceCfg) Name() string

Name returns method name

func (VoiceCfg) Values Uses

func (cfg VoiceCfg) Values() (url.Values, error)

Values returns a url.Values representation of VoiceCfg.

type WebhookCfg Uses

type WebhookCfg struct {
    URL string
    // self generated TLS certificate
    Certificate InputFile
}

WebhookCfg contains information about a SetWebhook request. Implements Method and Filer interface

func NewWebhook Uses

func NewWebhook(link string) WebhookCfg

NewWebhook creates a new webhook.

link is the url parsable link you wish to get the updates.

func NewWebhookWithCert Uses

func NewWebhookWithCert(link string, file InputFile) WebhookCfg

NewWebhookWithCert creates a new webhook with a certificate.

link is the url you wish to get webhooks, file contains a string to a file, FileReader, or FileBytes.

func (WebhookCfg) Exist Uses

func (cfg WebhookCfg) Exist() bool

Exist is true if we don't have a certificate to upload. It's kind of confusing.

func (WebhookCfg) Field Uses

func (cfg WebhookCfg) Field() string

Field returns name for webhook file data

func (WebhookCfg) File Uses

func (cfg WebhookCfg) File() InputFile

File returns certificate data

func (*WebhookCfg) GetFileID Uses

func (cfg *WebhookCfg) GetFileID() string

GetFileID for webhook is always empty

func (WebhookCfg) Name Uses

func (cfg WebhookCfg) Name() string

Name method returns Telegram API method name for sending Location.

func (*WebhookCfg) Reset Uses

func (cfg *WebhookCfg) Reset(i InputFile)

Reset method sets new Certificate

func (WebhookCfg) Values Uses

func (cfg WebhookCfg) Values() (url.Values, error)

Values returns a url.Values representation of Webhook config.

Directories

PathSynopsis
telebot
testutils

Package telegram imports 13 packages (graph) and is imported by 5 packages. Updated 2017-01-16. Refresh now. Tools for package owners.