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

package tgbotapi

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

Package tgbotapi has functions and types used for interacting with the Telegram Bot API.

Index

Examples

Package Files

bot.go configs.go helpers.go types.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"
)

Telegram constants

const (
    ChatTyping         = "typing"
    ChatUploadPhoto    = "upload_photo"
    ChatRecordVideo    = "record_video"
    ChatUploadVideo    = "upload_video"
    ChatRecordAudio    = "record_audio"
    ChatUploadAudio    = "upload_audio"
    ChatUploadDocument = "upload_document"
    ChatFindLocation   = "find_location"
)

Constant values for ChatActions

const (
    ModeMarkdown = "Markdown"
    ModeHTML     = "HTML"
)

Constant values for ParseMode in MessageConfig

const (
    // ErrBadFileType happens when you pass an unknown type
    ErrBadFileType = "bad file type"
    ErrBadURL      = "bad or empty url"
)

Library errors

const (
    // ErrAPIForbidden happens when a token is bad
    ErrAPIForbidden = "forbidden"
)

API errors

func NewInlineKeyboardRow Uses

func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) []InlineKeyboardButton

NewInlineKeyboardRow creates an inline keyboard row with buttons.

func NewKeyboardButtonRow Uses

func NewKeyboardButtonRow(buttons ...KeyboardButton) []KeyboardButton

NewKeyboardButtonRow creates a row of keyboard buttons.

type APIResponse Uses

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

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

type Animation Uses

type Animation struct {
    FileID   string    `json:"file_id"`
    Thumb    PhotoSize `json:"thumb"`
    FileName string    `json:"file_name"`
    MimeType string    `json:"mime_type"`
    FileSize int       `json:"file_size"`
}

Animation is a GIF animation demonstrating the game.

type Audio Uses

type Audio struct {
    FileID    string `json:"file_id"`
    Duration  int    `json:"duration"`
    Performer string `json:"performer"` // optional
    Title     string `json:"title"`     // optional
    MimeType  string `json:"mime_type"` // optional
    FileSize  int    `json:"file_size"` // optional
}

Audio contains information about audio.

type AudioConfig Uses

type AudioConfig struct {
    BaseFile
    Caption   string
    Duration  int
    Performer string
    Title     string
}

AudioConfig contains information about a SendAudio request.

func NewAudioShare Uses

func NewAudioShare(chatID int64, fileID string) AudioConfig

NewAudioShare shares an existing audio file. You may use this to reshare an existing audio file without reuploading it.

chatID is where to send it, fileID is the ID of the audio already uploaded.

func NewAudioUpload Uses

func NewAudioUpload(chatID int64, file interface{}) AudioConfig

NewAudioUpload creates a new audio uploader.

chatID is where to send it, file is a string path to the file, FileReader, or FileBytes.

type BaseChat Uses

type BaseChat struct {
    ChatID              int64 // required
    ChannelUsername     string
    ReplyToMessageID    int
    ReplyMarkup         interface{}
    DisableNotification bool
}

BaseChat is base type for all chat config types.

type BaseEdit Uses

type BaseEdit struct {
    ChatID          int64
    ChannelUsername string
    MessageID       int
    InlineMessageID string
    ReplyMarkup     *InlineKeyboardMarkup
}

BaseEdit is base type of all chat edits.

type BaseFile Uses

type BaseFile struct {
    BaseChat
    File        interface{}
    FileID      string
    UseExisting bool
    MimeType    string
    FileSize    int
}

BaseFile is a base type for all file config types.

type BotAPI Uses

type BotAPI struct {
    Token  string `json:"token"`
    Debug  bool   `json:"debug"`
    Buffer int    `json:"buffer"`

    Self   User         `json:"-"`
    Client *http.Client `json:"-"`
}

BotAPI allows you to interact with the Telegram Bot API.

func NewBotAPI Uses

func NewBotAPI(token string) (*BotAPI, error)

NewBotAPI creates a new BotAPI instance.

It requires a token, provided by @BotFather on Telegram.

Code:

bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
if err != nil {
    log.Panic(err)
}

bot.Debug = true

log.Printf("Authorized on account %s", bot.Self.UserName)

u := tgbotapi.NewUpdate(0)
u.Timeout = 60

updates, err := bot.GetUpdatesChan(u)

// Optional: wait for updates and clear them if you don't want to handle
// a large backlog of old messages
time.Sleep(time.Millisecond * 500)
updates.Clear()

for update := range updates {
    if update.Message == nil {
        continue
    }

    log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)

    msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
    msg.ReplyToMessageID = update.Message.MessageID

    bot.Send(msg)
}

func NewBotAPIWithClient Uses

func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error)

NewBotAPIWithClient creates a new BotAPI instance and allows you to pass a http.Client.

It requires a token, provided by @BotFather on Telegram.

func (*BotAPI) AnswerCallbackQuery Uses

func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, error)

AnswerCallbackQuery sends a response to an inline query callback.

func (*BotAPI) AnswerInlineQuery Uses

func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error)

AnswerInlineQuery sends a response to an inline query.

Note that you must respond to an inline query within 30 seconds.

func (*BotAPI) AnswerPreCheckoutQuery Uses

func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error)

AnswerPreCheckoutQuery allows you to reply to Update with pre_checkout_query.

func (*BotAPI) AnswerShippingQuery Uses

func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error)

AnswerShippingQuery allows you to reply to Update with shipping_query parameter.

func (*BotAPI) DeleteMessage Uses

func (bot *BotAPI) DeleteMessage(config DeleteMessageConfig) (APIResponse, error)

DeleteMessage deletes a message in a chat

func (*BotAPI) GetChat Uses

func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error)

GetChat gets information about a chat.

func (*BotAPI) GetChatAdministrators Uses

func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error)

GetChatAdministrators gets a list of administrators in the chat.

If none have been appointed, only the creator will be returned. Bots are not shown, even if they are an administrator.

func (*BotAPI) GetChatMember Uses

func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error)

GetChatMember gets a specific chat member.

func (*BotAPI) GetChatMembersCount Uses

func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error)

GetChatMembersCount gets the number of users in a chat.

func (*BotAPI) GetFile Uses

func (bot *BotAPI) GetFile(config FileConfig) (File, error)

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

Requires FileID.

func (*BotAPI) GetFileDirectURL Uses

func (bot *BotAPI) GetFileDirectURL(fileID string) (string, error)

GetFileDirectURL returns direct URL to file

It requires the FileID.

func (*BotAPI) GetGameHighScores Uses

func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error)

GetGameHighScores allows you to get the high scores for a game.

func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error)

GetInviteLink get InviteLink for a chat

func (*BotAPI) GetMe Uses

func (bot *BotAPI) GetMe() (User, error)

GetMe fetches the currently authenticated bot.

This method is called upon creation to validate the token, and so you may get this data from BotAPI.Self without the need for another request.

func (*BotAPI) GetUpdates Uses

func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error)

GetUpdates fetches updates. If a WebHook is set, this will not return any data!

Offset, Limit, and Timeout are optional. To avoid stale items, set Offset to one higher than the previous item. Set Timeout to a large number to reduce requests so you can get updates instantly instead of having to wait between requests.

func (*BotAPI) GetUpdatesChan Uses

func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error)

GetUpdatesChan starts and returns a channel for getting updates.

func (*BotAPI) GetUserProfilePhotos Uses

func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserProfilePhotos, error)

GetUserProfilePhotos gets a user's profile photos.

It requires UserID. Offset and Limit are optional.

func (*BotAPI) GetWebhookInfo Uses

func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error)

GetWebhookInfo allows you to fetch information about a webhook and if one currently is set, along with pending update count and error messages.

func (*BotAPI) IsMessageToMe Uses

func (bot *BotAPI) IsMessageToMe(message Message) bool

IsMessageToMe returns true if message directed to this bot.

It requires the Message.

func (*BotAPI) KickChatMember Uses

func (bot *BotAPI) KickChatMember(config KickChatMemberConfig) (APIResponse, error)

KickChatMember kicks a user from a chat. Note that this only will work in supergroups, and requires the bot to be an admin. Also note they will be unable to rejoin until they are unbanned.

func (*BotAPI) LeaveChat Uses

func (bot *BotAPI) LeaveChat(config ChatConfig) (APIResponse, error)

LeaveChat makes the bot leave the chat.

func (*BotAPI) ListenForWebhook Uses

func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel

ListenForWebhook registers a http handler for a webhook.

func (*BotAPI) MakeRequest Uses

func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error)

MakeRequest makes a request to a specific endpoint with our token.

func (*BotAPI) PinChatMessage Uses

func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, error)

Pin message in supergroup

func (*BotAPI) PromoteChatMember Uses

func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error)

func (*BotAPI) RemoveWebhook Uses

func (bot *BotAPI) RemoveWebhook() (APIResponse, error)

RemoveWebhook unsets the webhook.

func (*BotAPI) RestrictChatMember Uses

func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error)

RestrictChatMember to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user. Returns True on success.

func (*BotAPI) Send Uses

func (bot *BotAPI) Send(c Chattable) (Message, error)

Send will send a Chattable item to Telegram.

It requires the Chattable to send.

func (*BotAPI) SetWebhook Uses

func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error)

SetWebhook sets a webhook.

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 (*BotAPI) UnbanChatMember Uses

func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error)

UnbanChatMember unbans a user from a chat. Note that this only will work in supergroups and channels, and requires the bot to be an admin.

func (*BotAPI) UnpinChatMessage Uses

func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error)

Unpin message in supergroup

func (*BotAPI) UploadFile Uses

func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldname string, file interface{}) (APIResponse, error)

UploadFile makes a request to the API with a file.

Requires the parameter to hold the file not be in the params. File should be a string to a file path, a FileBytes struct, a FileReader struct, or a url.URL.

Note that if your FileReader has a size set to -1, it will read the file into memory to calculate a size.

type CallbackConfig Uses

type CallbackConfig struct {
    CallbackQueryID string `json:"callback_query_id"`
    Text            string `json:"text"`
    ShowAlert       bool   `json:"show_alert"`
    URL             string `json:"url"`
    CacheTime       int    `json:"cache_time"`
}

CallbackConfig contains information on making a CallbackQuery response.

func NewCallback Uses

func NewCallback(id, text string) CallbackConfig

NewCallback creates a new callback message.

func NewCallbackWithAlert Uses

func NewCallbackWithAlert(id, text string) CallbackConfig

NewCallbackWithAlert creates a new callback message that alerts the user.

type CallbackGame Uses

type CallbackGame struct{}

CallbackGame is for starting a game in an inline keyboard button.

type CallbackQuery Uses

type CallbackQuery struct {
    ID              string   `json:"id"`
    From            *User    `json:"from"`
    Message         *Message `json:"message"`           // optional
    InlineMessageID string   `json:"inline_message_id"` // optional
    ChatInstance    string   `json:"chat_instance"`
    Data            string   `json:"data"`            // optional
    GameShortName   string   `json:"game_short_name"` // optional
}

CallbackQuery is data sent when a keyboard button with callback data is clicked.

type Chat Uses

type Chat struct {
    ID                  int64      `json:"id"`
    Type                string     `json:"type"`
    Title               string     `json:"title"`                          // optional
    UserName            string     `json:"username"`                       // optional
    FirstName           string     `json:"first_name"`                     // optional
    LastName            string     `json:"last_name"`                      // optional
    AllMembersAreAdmins bool       `json:"all_members_are_administrators"` // optional
    Photo               *ChatPhoto `json:"photo"`
    Description         string     `json:"description,omitempty"` // optional
    InviteLink          string     `json:"invite_link,omitempty"` // optional
}

Chat contains information about the place a message was sent.

func (Chat) ChatConfig Uses

func (c Chat) ChatConfig() ChatConfig

ChatConfig returns a ChatConfig struct for chat related methods.

func (Chat) IsChannel Uses

func (c Chat) IsChannel() bool

IsChannel returns if the Chat is a channel.

func (Chat) IsGroup Uses

func (c Chat) IsGroup() bool

IsGroup returns if the Chat is a group.

func (Chat) IsPrivate Uses

func (c Chat) IsPrivate() bool

IsPrivate returns if the Chat is a private conversation.

func (Chat) IsSuperGroup Uses

func (c Chat) IsSuperGroup() bool

IsSuperGroup returns if the Chat is a supergroup.

type ChatActionConfig Uses

type ChatActionConfig struct {
    BaseChat
    Action string // required
}

ChatActionConfig contains information about a SendChatAction request.

func NewChatAction Uses

func NewChatAction(chatID int64, action string) ChatActionConfig

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 Chat constants.

type ChatConfig Uses

type ChatConfig struct {
    ChatID             int64
    SuperGroupUsername string
}

ChatConfig contains information about getting information on a chat.

type ChatConfigWithUser Uses

type ChatConfigWithUser struct {
    ChatID             int64
    SuperGroupUsername string
    UserID             int
}

ChatConfigWithUser contains information about getting information on a specific user within a chat.

type ChatMember Uses

type ChatMember struct {
    User                  *User  `json:"user"`
    Status                string `json:"status"`
    UntilDate             int64  `json:"until_date,omitempty"`                // optional
    CanBeEdited           bool   `json:"can_be_edited,omitempty"`             // optional
    CanChangeInfo         bool   `json:"can_change_info,omitempty"`           // optional
    CanPostMessages       bool   `json:"can_post_messages,omitempty"`         // optional
    CanEditMessages       bool   `json:"can_edit_messages,omitempty"`         // optional
    CanDeleteMessages     bool   `json:"can_delete_messages,omitempty"`       // optional
    CanInviteUsers        bool   `json:"can_invite_users,omitempty"`          // optional
    CanRestrictMembers    bool   `json:"can_restrict_members,omitempty"`      // optional
    CanPinMessages        bool   `json:"can_pin_messages,omitempty"`          // optional
    CanPromoteMembers     bool   `json:"can_promote_members,omitempty"`       // optional
    CanSendMessages       bool   `json:"can_send_messages,omitempty"`         // optional
    CanSendMediaMessages  bool   `json:"can_send_media_messages,omitempty"`   // optional
    CanSendOtherMessages  bool   `json:"can_send_other_messages,omitempty"`   // optional
    CanAddWebPagePreviews bool   `json:"can_add_web_page_previews,omitempty"` // optional
}

ChatMember is information about a member in a chat.

func (ChatMember) HasLeft Uses

func (chat ChatMember) HasLeft() bool

HasLeft returns if the ChatMember left the chat.

func (ChatMember) IsAdministrator Uses

func (chat ChatMember) IsAdministrator() bool

IsAdministrator returns if the ChatMember is a chat administrator.

func (ChatMember) IsCreator Uses

func (chat ChatMember) IsCreator() bool

IsCreator returns if the ChatMember was the creator of the chat.

func (ChatMember) IsMember Uses

func (chat ChatMember) IsMember() bool

IsMember returns if the ChatMember is a current member of the chat.

func (ChatMember) WasKicked Uses

func (chat ChatMember) WasKicked() bool

WasKicked returns if the ChatMember was kicked from the chat.

type ChatMemberConfig Uses

type ChatMemberConfig struct {
    ChatID             int64
    SuperGroupUsername string
    ChannelUsername    string
    UserID             int
}

ChatMemberConfig contains information about a user in a chat for use with administrative functions such as kicking or unbanning a user.

type ChatPhoto Uses

type ChatPhoto struct {
    SmallFileID string `json:"small_file_id"`
    BigFileID   string `json:"big_file_id"`
}

ChatPhoto represents a chat photo.

type Chattable Uses

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

Chattable is any config type that can be sent.

type ChosenInlineResult Uses

type ChosenInlineResult struct {
    ResultID        string    `json:"result_id"`
    From            *User     `json:"from"`
    Location        *Location `json:"location"`
    InlineMessageID string    `json:"inline_message_id"`
    Query           string    `json:"query"`
}

ChosenInlineResult is an inline query result chosen by a User

type Contact Uses

type Contact struct {
    PhoneNumber string `json:"phone_number"`
    FirstName   string `json:"first_name"`
    LastName    string `json:"last_name"` // optional
    UserID      int    `json:"user_id"`   // optional
}

Contact contains information about a contact.

Note that LastName and UserID may be empty.

type ContactConfig Uses

type ContactConfig struct {
    BaseChat
    PhoneNumber string
    FirstName   string
    LastName    string
}

ContactConfig allows you to send a contact.

func NewContact Uses

func NewContact(chatID int64, phoneNumber, firstName string) ContactConfig

NewContact allows you to send a shared contact.

type DeleteMessageConfig Uses

type DeleteMessageConfig struct {
    ChatID    int64
    MessageID int
}

DeleteMessageConfig contains information of a message in a chat to delete.

type Document Uses

type Document struct {
    FileID    string     `json:"file_id"`
    Thumbnail *PhotoSize `json:"thumb"`     // optional
    FileName  string     `json:"file_name"` // optional
    MimeType  string     `json:"mime_type"` // optional
    FileSize  int        `json:"file_size"` // optional
}

Document contains information about a document.

type DocumentConfig Uses

type DocumentConfig struct {
    BaseFile
    Caption string
}

DocumentConfig contains information about a SendDocument request.

func NewDocumentShare Uses

func NewDocumentShare(chatID int64, fileID string) DocumentConfig

NewDocumentShare shares an existing document. You may use this to reshare an existing document without reuploading it.

chatID is where to send it, fileID is the ID of the document already uploaded.

func NewDocumentUpload Uses

func NewDocumentUpload(chatID int64, file interface{}) DocumentConfig

NewDocumentUpload creates a new document uploader.

chatID is where to send it, file is a string path to the file, FileReader, or FileBytes.

type EditMessageCaptionConfig Uses

type EditMessageCaptionConfig struct {
    BaseEdit
    Caption string
}

EditMessageCaptionConfig allows you to modify the caption of a message.

func NewEditMessageCaption Uses

func NewEditMessageCaption(chatID int64, messageID int, caption string) EditMessageCaptionConfig

NewEditMessageCaption allows you to edit the caption of a message.

type EditMessageReplyMarkupConfig Uses

type EditMessageReplyMarkupConfig struct {
    BaseEdit
}

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

func NewEditMessageReplyMarkup Uses

func NewEditMessageReplyMarkup(chatID int64, messageID int, replyMarkup InlineKeyboardMarkup) EditMessageReplyMarkupConfig

NewEditMessageReplyMarkup allows you to edit the inline keyboard markup.

type EditMessageTextConfig Uses

type EditMessageTextConfig struct {
    BaseEdit
    Text                  string
    ParseMode             string
    DisableWebPagePreview bool
}

EditMessageTextConfig allows you to modify the text in a message.

func NewEditMessageText Uses

func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTextConfig

NewEditMessageText allows you to edit the text of a message.

type File Uses

type File struct {
    FileID   string `json:"file_id"`
    FileSize int    `json:"file_size"` // optional
    FilePath string `json:"file_path"` // optional
}

File contains information about a file to download from Telegram.

func (f *File) Link(token string) string

Link returns a full path to the download URL for a File.

It requires the Bot Token to create the link.

type FileBytes Uses

type FileBytes struct {
    Name  string
    Bytes []byte
}

FileBytes contains information about a set of bytes to upload as a File.

type FileConfig Uses

type FileConfig struct {
    FileID string
}

FileConfig has information about a file hosted on Telegram.

type FileReader Uses

type FileReader struct {
    Name   string
    Reader io.Reader
    Size   int64
}

FileReader contains information about a reader to upload as a File. If Size is -1, it will read the entire Reader into memory to calculate a Size.

type Fileable Uses

type Fileable interface {
    Chattable
    // contains filtered or unexported methods
}

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

type ForceReply Uses

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

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

type ForwardConfig Uses

type ForwardConfig struct {
    BaseChat
    FromChatID          int64 // required
    FromChannelUsername string
    MessageID           int // required
}

ForwardConfig contains information about a ForwardMessage request.

func NewForward Uses

func NewForward(chatID int64, fromChatID int64, messageID int) ForwardConfig

NewForward creates a new forward.

chatID is where to send it, fromChatID is the source chat, and messageID is the ID of the original message.

type Game Uses

type Game struct {
    Title        string          `json:"title"`
    Description  string          `json:"description"`
    Photo        []PhotoSize     `json:"photo"`
    Text         string          `json:"text"`
    TextEntities []MessageEntity `json:"text_entities"`
    Animation    Animation       `json:"animation"`
}

Game is a game within Telegram.

type GameConfig Uses

type GameConfig struct {
    BaseChat
    GameShortName string
}

GameConfig allows you to send a game.

type GameHighScore Uses

type GameHighScore struct {
    Position int  `json:"position"`
    User     User `json:"user"`
    Score    int  `json:"score"`
}

GameHighScore is a user's score and position on the leaderboard.

type GetGameHighScoresConfig Uses

type GetGameHighScoresConfig struct {
    UserID          int
    ChatID          int
    ChannelUsername string
    MessageID       int
    InlineMessageID string
}

GetGameHighScoresConfig allows you to fetch the high scores for a game.

type GroupChat Uses

type GroupChat struct {
    ID    int    `json:"id"`
    Title string `json:"title"`
}

GroupChat is a group chat.

type InlineConfig Uses

type InlineConfig struct {
    InlineQueryID     string        `json:"inline_query_id"`
    Results           []interface{} `json:"results"`
    CacheTime         int           `json:"cache_time"`
    IsPersonal        bool          `json:"is_personal"`
    NextOffset        string        `json:"next_offset"`
    SwitchPMText      string        `json:"switch_pm_text"`
    SwitchPMParameter string        `json:"switch_pm_parameter"`
}

InlineConfig contains information on making an InlineQuery response.

type InlineKeyboardButton Uses

type InlineKeyboardButton struct {
    Text                         string        `json:"text"`
    URL                          *string       `json:"url,omitempty"`                              // optional
    CallbackData                 *string       `json:"callback_data,omitempty"`                    // optional
    SwitchInlineQuery            *string       `json:"switch_inline_query,omitempty"`              // optional
    SwitchInlineQueryCurrentChat *string       `json:"switch_inline_query_current_chat,omitempty"` // optional
    CallbackGame                 *CallbackGame `json:"callback_game,omitempty"`                    // optional
    Pay                          bool          `json:"pay,omitempty"`                              // optional
}

InlineKeyboardButton is a button within a custom keyboard for inline query responses.

Note that some values are references as even an empty string will change behavior.

CallbackGame, if set, MUST be first button in first row.

func NewInlineKeyboardButtonData Uses

func NewInlineKeyboardButtonData(text, data string) InlineKeyboardButton

NewInlineKeyboardButtonData creates an inline keyboard button with text and data for a callback.

func NewInlineKeyboardButtonSwitch Uses

func NewInlineKeyboardButtonSwitch(text, sw string) InlineKeyboardButton

NewInlineKeyboardButtonSwitch creates an inline keyboard button with text which allows the user to switch to a chat or return to a chat.

func NewInlineKeyboardButtonURL Uses

func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton

NewInlineKeyboardButtonURL creates an inline keyboard button with text which goes to a URL.

type InlineKeyboardMarkup Uses

type InlineKeyboardMarkup struct {
    InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}

InlineKeyboardMarkup is a custom keyboard presented for an inline bot.

func NewInlineKeyboardMarkup Uses

func NewInlineKeyboardMarkup(rows ...[]InlineKeyboardButton) InlineKeyboardMarkup

NewInlineKeyboardMarkup creates a new inline keyboard.

type InlineQuery Uses

type InlineQuery struct {
    ID       string    `json:"id"`
    From     *User     `json:"from"`
    Location *Location `json:"location"` // optional
    Query    string    `json:"query"`
    Offset   string    `json:"offset"`
}

InlineQuery is a Query from Telegram for an inline request.

type InlineQueryResultArticle Uses

type InlineQueryResultArticle struct {
    Type                string                `json:"type"`                            // required
    ID                  string                `json:"id"`                              // required
    Title               string                `json:"title"`                           // required
    InputMessageContent interface{}           `json:"input_message_content,omitempty"` // required
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    URL                 string                `json:"url"`
    HideURL             bool                  `json:"hide_url"`
    Description         string                `json:"description"`
    ThumbURL            string                `json:"thumb_url"`
    ThumbWidth          int                   `json:"thumb_width"`
    ThumbHeight         int                   `json:"thumb_height"`
}

InlineQueryResultArticle is an inline query response article.

func NewInlineQueryResultArticle Uses

func NewInlineQueryResultArticle(id, title, messageText string) InlineQueryResultArticle

NewInlineQueryResultArticle creates a new inline query article.

func NewInlineQueryResultArticleHTML Uses

func NewInlineQueryResultArticleHTML(id, title, messageText string) InlineQueryResultArticle

NewInlineQueryResultArticleHTML creates a new inline query article with HTML parsing.

func NewInlineQueryResultArticleMarkdown Uses

func NewInlineQueryResultArticleMarkdown(id, title, messageText string) InlineQueryResultArticle

NewInlineQueryResultArticleMarkdown creates a new inline query article with Markdown parsing.

type InlineQueryResultAudio Uses

type InlineQueryResultAudio struct {
    Type                string                `json:"type"`      // required
    ID                  string                `json:"id"`        // required
    URL                 string                `json:"audio_url"` // required
    Title               string                `json:"title"`     // required
    Caption             string                `json:"caption"`
    Performer           string                `json:"performer"`
    Duration            int                   `json:"audio_duration"`
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
}

InlineQueryResultAudio is an inline query response audio.

func NewInlineQueryResultAudio Uses

func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio

NewInlineQueryResultAudio creates a new inline query audio.

type InlineQueryResultDocument Uses

type InlineQueryResultDocument struct {
    Type                string                `json:"type"`  // required
    ID                  string                `json:"id"`    // required
    Title               string                `json:"title"` // required
    Caption             string                `json:"caption"`
    URL                 string                `json:"document_url"` // required
    MimeType            string                `json:"mime_type"`    // required
    Description         string                `json:"description"`
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
    ThumbURL            string                `json:"thumb_url"`
    ThumbWidth          int                   `json:"thumb_width"`
    ThumbHeight         int                   `json:"thumb_height"`
}

InlineQueryResultDocument is an inline query response document.

func NewInlineQueryResultDocument Uses

func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryResultDocument

NewInlineQueryResultDocument creates a new inline query document.

type InlineQueryResultGIF Uses

type InlineQueryResultGIF struct {
    Type                string                `json:"type"`    // required
    ID                  string                `json:"id"`      // required
    URL                 string                `json:"gif_url"` // required
    Width               int                   `json:"gif_width"`
    Height              int                   `json:"gif_height"`
    Duration            int                   `json:"gif_duration"`
    ThumbURL            string                `json:"thumb_url"`
    Title               string                `json:"title"`
    Caption             string                `json:"caption"`
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
}

InlineQueryResultGIF is an inline query response GIF.

func NewInlineQueryResultGIF Uses

func NewInlineQueryResultGIF(id, url string) InlineQueryResultGIF

NewInlineQueryResultGIF creates a new inline query GIF.

type InlineQueryResultGame Uses

type InlineQueryResultGame struct {
    Type          string                `json:"type"`
    ID            string                `json:"id"`
    GameShortName string                `json:"game_short_name"`
    ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup"`
}

InlineQueryResultGame is an inline query response game.

type InlineQueryResultLocation Uses

type InlineQueryResultLocation struct {
    Type                string                `json:"type"`      // required
    ID                  string                `json:"id"`        // required
    Latitude            float64               `json:"latitude"`  // required
    Longitude           float64               `json:"longitude"` // required
    Title               string                `json:"title"`     // required
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
    ThumbURL            string                `json:"thumb_url"`
    ThumbWidth          int                   `json:"thumb_width"`
    ThumbHeight         int                   `json:"thumb_height"`
}

InlineQueryResultLocation is an inline query response location.

func NewInlineQueryResultLocation Uses

func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) InlineQueryResultLocation

NewInlineQueryResultLocation creates a new inline query location.

type InlineQueryResultMPEG4GIF Uses

type InlineQueryResultMPEG4GIF struct {
    Type                string                `json:"type"`      // required
    ID                  string                `json:"id"`        // required
    URL                 string                `json:"mpeg4_url"` // required
    Width               int                   `json:"mpeg4_width"`
    Height              int                   `json:"mpeg4_height"`
    Duration            int                   `json:"mpeg4_duration"`
    ThumbURL            string                `json:"thumb_url"`
    Title               string                `json:"title"`
    Caption             string                `json:"caption"`
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
}

InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.

func NewInlineQueryResultMPEG4GIF Uses

func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF

NewInlineQueryResultMPEG4GIF creates a new inline query MPEG4 GIF.

type InlineQueryResultPhoto Uses

type InlineQueryResultPhoto struct {
    Type                string                `json:"type"`      // required
    ID                  string                `json:"id"`        // required
    URL                 string                `json:"photo_url"` // required
    MimeType            string                `json:"mime_type"`
    Width               int                   `json:"photo_width"`
    Height              int                   `json:"photo_height"`
    ThumbURL            string                `json:"thumb_url"`
    Title               string                `json:"title"`
    Description         string                `json:"description"`
    Caption             string                `json:"caption"`
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
}

InlineQueryResultPhoto is an inline query response photo.

func NewInlineQueryResultPhoto Uses

func NewInlineQueryResultPhoto(id, url string) InlineQueryResultPhoto

NewInlineQueryResultPhoto creates a new inline query photo.

func NewInlineQueryResultPhotoWithThumb Uses

func NewInlineQueryResultPhotoWithThumb(id, url, thumb string) InlineQueryResultPhoto

NewInlineQueryResultPhotoWithThumb creates a new inline query photo.

type InlineQueryResultVideo Uses

type InlineQueryResultVideo struct {
    Type                string                `json:"type"`      // required
    ID                  string                `json:"id"`        // required
    URL                 string                `json:"video_url"` // required
    MimeType            string                `json:"mime_type"` // required
    ThumbURL            string                `json:"thumb_url"`
    Title               string                `json:"title"`
    Caption             string                `json:"caption"`
    Width               int                   `json:"video_width"`
    Height              int                   `json:"video_height"`
    Duration            int                   `json:"video_duration"`
    Description         string                `json:"description"`
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
}

InlineQueryResultVideo is an inline query response video.

func NewInlineQueryResultVideo Uses

func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo

NewInlineQueryResultVideo creates a new inline query video.

type InlineQueryResultVoice Uses

type InlineQueryResultVoice struct {
    Type                string                `json:"type"`      // required
    ID                  string                `json:"id"`        // required
    URL                 string                `json:"voice_url"` // required
    Title               string                `json:"title"`     // required
    Caption             string                `json:"caption"`
    Duration            int                   `json:"voice_duration"`
    ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
    InputMessageContent interface{}           `json:"input_message_content,omitempty"`
}

InlineQueryResultVoice is an inline query response voice.

func NewInlineQueryResultVoice Uses

func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice

NewInlineQueryResultVoice creates a new inline query voice.

type InputContactMessageContent Uses

type InputContactMessageContent struct {
    PhoneNumber string `json:"phone_number"`
    FirstName   string `json:"first_name"`
    LastName    string `json:"last_name"`
}

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

type InputLocationMessageContent Uses

type InputLocationMessageContent struct {
    Latitude  float64 `json:"latitude"`
    Longitude float64 `json:"longitude"`
}

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

type InputTextMessageContent Uses

type InputTextMessageContent struct {
    Text                  string `json:"message_text"`
    ParseMode             string `json:"parse_mode"`
    DisableWebPagePreview bool   `json:"disable_web_page_preview"`
}

InputTextMessageContent contains text for displaying as an inline query result.

type InputVenueMessageContent Uses

type InputVenueMessageContent struct {
    Latitude     float64 `json:"latitude"`
    Longitude    float64 `json:"longitude"`
    Title        string  `json:"title"`
    Address      string  `json:"address"`
    FoursquareID string  `json:"foursquare_id"`
}

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

type Invoice Uses

type Invoice struct {
    Title          string `json:"title"`
    Description    string `json:"description"`
    StartParameter string `json:"start_parameter"`
    Currency       string `json:"currency"`
    TotalAmount    int    `json:"total_amount"`
}

Invoice contains basic information about an invoice.

type InvoiceConfig Uses

type InvoiceConfig struct {
    BaseChat
    Title               string          // required
    Description         string          // required
    Payload             string          // required
    ProviderToken       string          // required
    StartParameter      string          // required
    Currency            string          // required
    Prices              *[]LabeledPrice // required
    PhotoURL            string
    PhotoSize           int
    PhotoWidth          int
    PhotoHeight         int
    NeedName            bool
    NeedPhoneNumber     bool
    NeedEmail           bool
    NeedShippingAddress bool
    IsFlexible          bool
}

InvoiceConfig contains information for sendInvoice request.

func NewInvoice Uses

func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices *[]LabeledPrice) InvoiceConfig

NewInvoice created a new Invoice request to the user.

type KeyboardButton Uses

type KeyboardButton struct {
    Text            string `json:"text"`
    RequestContact  bool   `json:"request_contact"`
    RequestLocation bool   `json:"request_location"`
}

KeyboardButton is a button within a custom keyboard.

func NewKeyboardButton Uses

func NewKeyboardButton(text string) KeyboardButton

NewKeyboardButton creates a regular keyboard button.

func NewKeyboardButtonContact Uses

func NewKeyboardButtonContact(text string) KeyboardButton

NewKeyboardButtonContact creates a keyboard button that requests user contact information upon click.

func NewKeyboardButtonLocation Uses

func NewKeyboardButtonLocation(text string) KeyboardButton

NewKeyboardButtonLocation creates a keyboard button that requests user location information upon click.

type KickChatMemberConfig Uses

type KickChatMemberConfig struct {
    ChatMemberConfig
    UntilDate int64
}

KickChatMemberConfig contains extra fields to kick user

type LabeledPrice Uses

type LabeledPrice struct {
    Label  string `json:"label"`
    Amount int    `json:"amount"`
}

LabeledPrice represents a portion of the price for goods or services.

type Location Uses

type Location struct {
    Longitude float64 `json:"longitude"`
    Latitude  float64 `json:"latitude"`
}

Location contains information about a place.

type LocationConfig Uses

type LocationConfig struct {
    BaseChat
    Latitude  float64 // required
    Longitude float64 // required
}

LocationConfig contains information about a SendLocation request.

func NewLocation Uses

func NewLocation(chatID int64, latitude float64, longitude float64) LocationConfig

NewLocation shares your location.

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

type Message Uses

type Message struct {
    MessageID             int                `json:"message_id"`
    From                  *User              `json:"from"` // optional
    Date                  int                `json:"date"`
    Chat                  *Chat              `json:"chat"`
    ForwardFrom           *User              `json:"forward_from"`            // optional
    ForwardFromChat       *Chat              `json:"forward_from_chat"`       // optional
    ForwardFromMessageID  int                `json:"forward_from_message_id"` // optional
    ForwardDate           int                `json:"forward_date"`            // optional
    ReplyToMessage        *Message           `json:"reply_to_message"`        // optional
    EditDate              int                `json:"edit_date"`               // optional
    Text                  string             `json:"text"`                    // optional
    Entities              *[]MessageEntity   `json:"entities"`                // optional
    Audio                 *Audio             `json:"audio"`                   // optional
    Document              *Document          `json:"document"`                // optional
    Game                  *Game              `json:"game"`                    // optional
    Photo                 *[]PhotoSize       `json:"photo"`                   // optional
    Sticker               *Sticker           `json:"sticker"`                 // optional
    Video                 *Video             `json:"video"`                   // optional
    VideoNote             *VideoNote         `json:"video_note"`              // optional
    Voice                 *Voice             `json:"voice"`                   // optional
    Caption               string             `json:"caption"`                 // optional
    Contact               *Contact           `json:"contact"`                 // optional
    Location              *Location          `json:"location"`                // optional
    Venue                 *Venue             `json:"venue"`                   // optional
    NewChatMembers        *[]User            `json:"new_chat_members"`        // optional
    LeftChatMember        *User              `json:"left_chat_member"`        // optional
    NewChatTitle          string             `json:"new_chat_title"`          // optional
    NewChatPhoto          *[]PhotoSize       `json:"new_chat_photo"`          // optional
    DeleteChatPhoto       bool               `json:"delete_chat_photo"`       // optional
    GroupChatCreated      bool               `json:"group_chat_created"`      // optional
    SuperGroupChatCreated bool               `json:"supergroup_chat_created"` // optional
    ChannelChatCreated    bool               `json:"channel_chat_created"`    // optional
    MigrateToChatID       int64              `json:"migrate_to_chat_id"`      // optional
    MigrateFromChatID     int64              `json:"migrate_from_chat_id"`    // optional
    PinnedMessage         *Message           `json:"pinned_message"`          // optional
    Invoice               *Invoice           `json:"invoice"`                 // optional
    SuccessfulPayment     *SuccessfulPayment `json:"successful_payment"`      // optional
}

Message is returned by almost every request, and contains data about almost anything.

func (*Message) Command Uses

func (m *Message) Command() string

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

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

func (*Message) CommandArguments Uses

func (m *Message) CommandArguments() string

CommandArguments checks if the message was a command and if it was, returns all text after the command name. If the Message was not a command, it returns an empty string.

func (*Message) IsCommand Uses

func (m *Message) IsCommand() bool

IsCommand returns true if message starts with '/'.

func (*Message) Time Uses

func (m *Message) Time() time.Time

Time converts the message timestamp into a Time.

type MessageConfig Uses

type MessageConfig struct {
    BaseChat
    Text                  string
    ParseMode             string
    DisableWebPagePreview bool
}

MessageConfig contains information about a SendMessage request.

func NewMessage Uses

func NewMessage(chatID int64, text string) MessageConfig

NewMessage creates a new Message.

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

func NewMessageToChannel Uses

func NewMessageToChannel(username string, text string) MessageConfig

NewMessageToChannel creates a new Message that is sent to a channel by username.

username is the username of the channel, text is the message text.

type MessageEntity Uses

type MessageEntity struct {
    Type   string `json:"type"`
    Offset int    `json:"offset"`
    Length int    `json:"length"`
    URL    string `json:"url"`  // optional
    User   *User  `json:"user"` // optional
}

MessageEntity contains information about data in a Message.

func (MessageEntity) ParseURL Uses

func (entity MessageEntity) ParseURL() (*url.URL, error)

ParseURL attempts to parse a URL contained within a MessageEntity.

type OrderInfo Uses

type OrderInfo struct {
    Name            string           `json:"name,omitempty"`
    PhoneNumber     string           `json:"phone_number,omitempty"`
    Email           string           `json:"email,omitempty"`
    ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
}

OrderInfo represents information about an order.

type PhotoConfig Uses

type PhotoConfig struct {
    BaseFile
    Caption string
}

PhotoConfig contains information about a SendPhoto request.

func NewPhotoShare Uses

func NewPhotoShare(chatID int64, fileID string) PhotoConfig

NewPhotoShare shares an existing photo. You may use this to reshare an existing photo without reuploading it.

chatID is where to send it, fileID is the ID of the file already uploaded.

func NewPhotoUpload Uses

func NewPhotoUpload(chatID int64, file interface{}) PhotoConfig

NewPhotoUpload creates a new photo uploader.

chatID is where to send it, file is a string path to the file, FileReader, or FileBytes.

Note that you must send animated GIFs as a document.

type PhotoSize Uses

type PhotoSize struct {
    FileID   string `json:"file_id"`
    Width    int    `json:"width"`
    Height   int    `json:"height"`
    FileSize int    `json:"file_size"` // optional
}

PhotoSize contains information about photos.

type PinChatMessageConfig Uses

type PinChatMessageConfig struct {
    ChatID              int64
    MessageID           int
    DisableNotification bool
}

PinChatMessageConfig contains information of a message in a chat to pin.

type PreCheckoutConfig Uses

type PreCheckoutConfig struct {
    PreCheckoutQueryID string // required
    OK                 bool   // required
    ErrorMessage       string
}

PreCheckoutConfig conatins information for answerPreCheckoutQuery request.

type PreCheckoutQuery Uses

type PreCheckoutQuery struct {
    ID               string     `json:"id"`
    From             *User      `json:"from"`
    Currency         string     `json:"currency"`
    TotalAmount      int        `json:"total_amount"`
    InvoicePayload   string     `json:"invoice_payload"`
    ShippingOptionID string     `json:"shipping_option_id,omitempty"`
    OrderInfo        *OrderInfo `json:"order_info,omitempty"`
}

PreCheckoutQuery contains information about an incoming pre-checkout query.

type PromoteChatMemberConfig Uses

type PromoteChatMemberConfig struct {
    ChatMemberConfig
    CanChangeInfo      *bool
    CanPostMessages    *bool
    CanEditMessages    *bool
    CanDeleteMessages  *bool
    CanInviteUsers     *bool
    CanRestrictMembers *bool
    CanPinMessages     *bool
    CanPromoteMembers  *bool
}

PromoteChatMemberConfig contains fields to promote members of chat

type ReplyKeyboardHide Uses

type ReplyKeyboardHide struct {
    HideKeyboard bool `json:"hide_keyboard"`
    Selective    bool `json:"selective"` // optional
}

ReplyKeyboardHide allows the Bot to hide a custom keyboard.

func NewHideKeyboard Uses

func NewHideKeyboard(selective bool) ReplyKeyboardHide

NewHideKeyboard hides the keyboard, with the option for being selective or hiding for everyone.

type ReplyKeyboardMarkup Uses

type ReplyKeyboardMarkup struct {
    Keyboard        [][]KeyboardButton `json:"keyboard"`
    ResizeKeyboard  bool               `json:"resize_keyboard"`   // optional
    OneTimeKeyboard bool               `json:"one_time_keyboard"` // optional
    Selective       bool               `json:"selective"`         // optional
}

ReplyKeyboardMarkup allows the Bot to set a custom keyboard.

func NewReplyKeyboard Uses

func NewReplyKeyboard(rows ...[]KeyboardButton) ReplyKeyboardMarkup

NewReplyKeyboard creates a new regular keyboard with sane defaults.

type ReplyKeyboardRemove Uses

type ReplyKeyboardRemove struct {
    RemoveKeyboard bool `json:"remove_keyboard"`
    Selective      bool `json:"selective"`
}

ReplyKeyboardRemove allows the Bot to hide a custom keyboard.

func NewRemoveKeyboard Uses

func NewRemoveKeyboard(selective bool) ReplyKeyboardRemove

NewRemoveKeyboard hides the keyboard, with the option for being selective or hiding for everyone.

type ResponseParameters Uses

type ResponseParameters struct {
    MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
    RetryAfter      int   `json:"retry_after"`        // optional
}

ResponseParameters are various errors that can be returned in APIResponse.

type RestrictChatMemberConfig Uses

type RestrictChatMemberConfig struct {
    ChatMemberConfig
    UntilDate             int64
    CanSendMessages       *bool
    CanSendMediaMessages  *bool
    CanSendOtherMessages  *bool
    CanAddWebPagePreviews *bool
}

RestrictChatMemberConfig contains fields to restrict members of chat

type SetGameScoreConfig Uses

type SetGameScoreConfig struct {
    UserID             int
    Score              int
    Force              bool
    DisableEditMessage bool
    ChatID             int
    ChannelUsername    string
    MessageID          int
    InlineMessageID    string
}

SetGameScoreConfig allows you to update the game score in a chat.

type ShippingAddress Uses

type ShippingAddress struct {
    CountryCode string `json:"country_code"`
    State       string `json:"state"`
    City        string `json:"city"`
    StreetLine1 string `json:"street_line1"`
    StreetLine2 string `json:"street_line2"`
    PostCode    string `json:"post_code"`
}

ShippingAddress represents a shipping address.

type ShippingConfig Uses

type ShippingConfig struct {
    ShippingQueryID string // required
    OK              bool   // required
    ShippingOptions *[]ShippingOption
    ErrorMessage    string
}

ShippingConfig contains information for answerShippingQuery request.

type ShippingOption Uses

type ShippingOption struct {
    ID     string          `json:"id"`
    Title  string          `json:"title"`
    Prices *[]LabeledPrice `json:"prices"`
}

ShippingOption represents one shipping option.

type ShippingQuery Uses

type ShippingQuery struct {
    ID              string           `json:"id"`
    From            *User            `json:"from"`
    InvoicePayload  string           `json:"invoice_payload"`
    ShippingAddress *ShippingAddress `json:"shipping_address"`
}

ShippingQuery contains information about an incoming shipping query.

type Sticker Uses

type Sticker struct {
    FileID    string     `json:"file_id"`
    Width     int        `json:"width"`
    Height    int        `json:"height"`
    Thumbnail *PhotoSize `json:"thumb"`     // optional
    Emoji     string     `json:"emoji"`     // optional
    FileSize  int        `json:"file_size"` // optional
}

Sticker contains information about a sticker.

type StickerConfig Uses

type StickerConfig struct {
    BaseFile
}

StickerConfig contains information about a SendSticker request.

func NewStickerShare Uses

func NewStickerShare(chatID int64, fileID string) StickerConfig

NewStickerShare shares an existing sticker. You may use this to reshare an existing sticker without reuploading it.

chatID is where to send it, fileID is the ID of the sticker already uploaded.

func NewStickerUpload Uses

func NewStickerUpload(chatID int64, file interface{}) StickerConfig

NewStickerUpload creates a new sticker uploader.

chatID is where to send it, file is a string path to the file, FileReader, or FileBytes.

type SuccessfulPayment Uses

type SuccessfulPayment struct {
    Currency                string     `json:"currency"`
    TotalAmount             int        `json:"total_amount"`
    InvoicePayload          string     `json:"invoice_payload"`
    ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
    OrderInfo               *OrderInfo `json:"order_info,omitempty"`
    TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
    ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
}

SuccessfulPayment contains basic information about a successful payment.

type UnpinChatMessageConfig Uses

type UnpinChatMessageConfig struct {
    ChatID int64
}

UnpinChatMessageConfig contains information of chat to unpin.

type Update Uses

type Update struct {
    UpdateID           int                 `json:"update_id"`
    Message            *Message            `json:"message"`
    EditedMessage      *Message            `json:"edited_message"`
    ChannelPost        *Message            `json:"channel_post"`
    EditedChannelPost  *Message            `json:"edited_channel_post"`
    InlineQuery        *InlineQuery        `json:"inline_query"`
    ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
    CallbackQuery      *CallbackQuery      `json:"callback_query"`
    ShippingQuery      *ShippingQuery      `json:"shipping_query"`
    PreCheckoutQuery   *PreCheckoutQuery   `json:"pre_checkout_query"`
}

Update is an update response, from GetUpdates.

type UpdateConfig Uses

type UpdateConfig struct {
    Offset  int
    Limit   int
    Timeout int
}

UpdateConfig contains information about a GetUpdates request.

func NewUpdate Uses

func NewUpdate(offset int) UpdateConfig

NewUpdate gets updates since the last Offset.

offset is the last Update ID to include. You likely want to set this to the last Update ID plus 1.

type UpdatesChannel Uses

type UpdatesChannel <-chan Update

UpdatesChannel is the channel for getting updates.

func (UpdatesChannel) Clear Uses

func (ch UpdatesChannel) Clear()

Clear discards all unprocessed incoming updates.

type User Uses

type User struct {
    ID           int    `json:"id"`
    FirstName    string `json:"first_name"`
    LastName     string `json:"last_name"`     // optional
    UserName     string `json:"username"`      // optional
    LanguageCode string `json:"language_code"` // optional
}

User is a user on Telegram.

func (*User) String Uses

func (u *User) String() string

String displays a simple text version of a user.

It is normally a user's username, but falls back to a first/last name as available.

type UserProfilePhotos Uses

type UserProfilePhotos struct {
    TotalCount int           `json:"total_count"`
    Photos     [][]PhotoSize `json:"photos"`
}

UserProfilePhotos contains a set of user profile photos.

type UserProfilePhotosConfig Uses

type UserProfilePhotosConfig struct {
    UserID int
    Offset int
    Limit  int
}

UserProfilePhotosConfig contains information about a GetUserProfilePhotos request.

func NewUserProfilePhotos Uses

func NewUserProfilePhotos(userID int) UserProfilePhotosConfig

NewUserProfilePhotos gets user profile photos.

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

type Venue Uses

type Venue struct {
    Location     Location `json:"location"`
    Title        string   `json:"title"`
    Address      string   `json:"address"`
    FoursquareID string   `json:"foursquare_id"` // optional
}

Venue contains information about a venue, including its Location.

type VenueConfig Uses

type VenueConfig struct {
    BaseChat
    Latitude     float64 // required
    Longitude    float64 // required
    Title        string  // required
    Address      string  // required
    FoursquareID string
}

VenueConfig contains information about a SendVenue request.

func NewVenue Uses

func NewVenue(chatID int64, title, address string, latitude, longitude float64) VenueConfig

NewVenue allows you to send a venue and its location.

type Video Uses

type Video struct {
    FileID    string     `json:"file_id"`
    Width     int        `json:"width"`
    Height    int        `json:"height"`
    Duration  int        `json:"duration"`
    Thumbnail *PhotoSize `json:"thumb"`     // optional
    MimeType  string     `json:"mime_type"` // optional
    FileSize  int        `json:"file_size"` // optional
}

Video contains information about a video.

type VideoConfig Uses

type VideoConfig struct {
    BaseFile
    Duration int
    Caption  string
}

VideoConfig contains information about a SendVideo request.

func NewVideoShare Uses

func NewVideoShare(chatID int64, fileID string) VideoConfig

NewVideoShare shares an existing video. You may use this to reshare an existing video without reuploading it.

chatID is where to send it, fileID is the ID of the video already uploaded.

func NewVideoUpload Uses

func NewVideoUpload(chatID int64, file interface{}) VideoConfig

NewVideoUpload creates a new video uploader.

chatID is where to send it, file is a string path to the file, FileReader, or FileBytes.

type VideoNote Uses

type VideoNote struct {
    FileID    string     `json:"file_id"`
    Length    int        `json:"length"`
    Duration  int        `json:"duration"`
    Thumbnail *PhotoSize `json:"thumb"`     // optional
    FileSize  int        `json:"file_size"` // optional
}

VideoNote contains information about a video.

type VideoNoteConfig Uses

type VideoNoteConfig struct {
    BaseFile
    Duration int
    Length   int
}

VideoNoteConfig contains information about a SendVideoNote request.

func NewVideoNoteShare Uses

func NewVideoNoteShare(chatID int64, length int, fileID string) VideoNoteConfig

NewVideoNoteShare shares an existing video. You may use this to reshare an existing video without reuploading it.

chatID is where to send it, fileID is the ID of the video already uploaded.

func NewVideoNoteUpload Uses

func NewVideoNoteUpload(chatID int64, length int, file interface{}) VideoNoteConfig

NewVideoNoteUpload creates a new video note uploader.

chatID is where to send it, file is a string path to the file, FileReader, or FileBytes.

type Voice Uses

type Voice struct {
    FileID   string `json:"file_id"`
    Duration int    `json:"duration"`
    MimeType string `json:"mime_type"` // optional
    FileSize int    `json:"file_size"` // optional
}

Voice contains information about a voice.

type VoiceConfig Uses

type VoiceConfig struct {
    BaseFile
    Caption  string
    Duration int
}

VoiceConfig contains information about a SendVoice request.

func NewVoiceShare Uses

func NewVoiceShare(chatID int64, fileID string) VoiceConfig

NewVoiceShare shares an existing voice. You may use this to reshare an existing voice without reuploading it.

chatID is where to send it, fileID is the ID of the video already uploaded.

func NewVoiceUpload Uses

func NewVoiceUpload(chatID int64, file interface{}) VoiceConfig

NewVoiceUpload creates a new voice uploader.

chatID is where to send it, file is a string path to the file, FileReader, or FileBytes.

type WebhookConfig Uses

type WebhookConfig struct {
    URL            *url.URL
    Certificate    interface{}
    MaxConnections int
}

WebhookConfig contains information about a SetWebhook request.

func NewWebhook Uses

func NewWebhook(link string) WebhookConfig

NewWebhook creates a new webhook.

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

Code:

bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
if err != nil {
    log.Fatal(err)
}

bot.Debug = true

log.Printf("Authorized on account %s", bot.Self.UserName)

_, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
if err != nil {
    log.Fatal(err)
}

updates := bot.ListenForWebhook("/" + bot.Token)
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)

for update := range updates {
    log.Printf("%+v\n", update)
}

func NewWebhookWithCert Uses

func NewWebhookWithCert(link string, file interface{}) WebhookConfig

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.

type WebhookInfo Uses

type WebhookInfo struct {
    URL                  string `json:"url"`
    HasCustomCertificate bool   `json:"has_custom_certificate"`
    PendingUpdateCount   int    `json:"pending_update_count"`
    LastErrorDate        int    `json:"last_error_date"`    // optional
    LastErrorMessage     string `json:"last_error_message"` // optional
}

WebhookInfo is information about a currently set webhook.

func (WebhookInfo) IsSet Uses

func (info WebhookInfo) IsSet() bool

IsSet returns true if a webhook is currently set.

Package tgbotapi imports 14 packages (graph) and is imported by 26 packages. Updated 2017-08-06. Refresh now. Tools for package owners.