Documentation ¶
Index ¶
- Constants
- type APIResponse
- type AudioConfig
- type BaseChat
- type BaseFile
- type BotAPI
- func (bot *BotAPI) AddMiddleware(handler MiddlewareHandlerFunc)
- func (bot *BotAPI) FindCallbackHandler(action string) CallbackHandlerFunc
- func (bot *BotAPI) FindMessageHandler(action string) MessageHandlerFunc
- func (bot *BotAPI) HandleCallback(statePath string, handler CallbackHandlerFunc)
- func (bot *BotAPI) HandleMessage(statePath string, handler MessageHandlerFunc)
- func (bot *BotAPI) HandleUpdates(update []byte) (err error)
- func (bot *BotAPI) MakeRequest(endpoint string, params Params) (*APIResponse, error)
- func (bot *BotAPI) Request(c Chattable) (*APIResponse, error)
- func (bot *BotAPI) Send(c Chattable) (Message, error)
- func (bot *BotAPI) UploadFile(params Params, file RequestFile) (*UploadResponse, error)
- type CallbackAnswerConfig
- type CallbackHandlerFunc
- type CallbackHandlers
- type CallbackQuery
- type CallbackQueryAction
- type Chattable
- type Contact
- type DeleteMessageConfig
- type Error
- type FORM_OBJECTS_TYPE
- type File
- type FileConfig
- type FilePath
- type FileReader
- type Fileable
- type FormData
- type FormObject
- func NewForm(formObject ...FormObject) []FormObject
- func NewFormObjectBarcode(name, label string) FormObject
- func NewFormObjectCheckbox(name, label string) FormObject
- func NewFormObjectInput(name, label string, value ...string) FormObject
- func NewFormObjectInputWithValue(name, label, value string) FormObject
- func NewFormObjectQrcode(name, label string) FormObject
- func NewFormObjectRadioInput(name, label string, options []FormObjectOption) FormObject
- func NewFormObjectSelect(name, label string, options []FormObjectOption) FormObject
- func NewFormObjectSubmit(name, label string) FormObject
- func NewFormObjectTextarea(name, label string, value ...string) FormObject
- type FormObjectOption
- type HTTPClient
- type INLINE_KEYBOARD_CURRENCY
- type INLINE_KEYBOARD_URL_OPENIN
- type ImageUrls
- type InlineKeyboardButton
- func NewInlineKeyboardButton(text string, callbackData CallbackQueryAction) InlineKeyboardButton
- func NewInlineKeyboardButtonPayment(text string, amount int, currency INLINE_KEYBOARD_CURRENCY, ...) InlineKeyboardButton
- func NewInlineKeyboardButtonURL(text, url string, openIn INLINE_KEYBOARD_URL_OPENIN) InlineKeyboardButton
- func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) []InlineKeyboardButton
- type InlineKeyboardMarkup
- type Location
- type MESSAGE_TYPE
- type Message
- type MessageConfig
- type MessageHandlerFunc
- type MessageHandlers
- type MiddlewareHandlerFunc
- type MiddlewareHandlers
- type Params
- func (p Params) AddBool(key string, value bool)
- func (p Params) AddFirstValid(key string, args ...interface{}) error
- func (p Params) AddInterface(key string, value interface{}) error
- func (p Params) AddNonEmpty(key, value string)
- func (p Params) AddNonZero(key string, value int)
- func (p Params) AddNonZero64(key string, value int64)
- func (p Params) AddNonZeroFloat(key string, value float64)
- func (p Params) GetParam(key string) string
- type PaymentInfo
- type PhotoConfig
- type ReplyKeyboardButton
- type ReplyKeyboardMarkup
- type RequestFile
- type RequestFileData
- type UpdateMessageConfig
- type UploadResponse
- type User
- type VideoConfig
- type VoiceConfig
Constants ¶
const ( ChatTyping = "typing" ChatUploadPhoto = "upload_photo" ChatRecordVideo = "record_video" ChatUploadVideo = "upload_video" ChatRecordVoice = "record_voice" ChatUploadVoice = "upload_voice" ChatUploadDocument = "upload_document" ChatChooseSticker = "choose_sticker" ChatFindLocation = "find_location" ChatRecordVideoNote = "record_video_note" ChatUploadVideoNote = "upload_video_note" )
Constant values for ChatActions
const ( // APIEndpoint is the endpoint for all API methods, // with formatting for Sprintf. APIEndpoint = "https://api.gap.im/%s" )
Telegram constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIResponse ¶
type AudioConfig ¶
func NewAudio ¶
func NewAudio(chatID int64, file RequestFileData) AudioConfig
type BaseChat ¶
type BaseChat struct { ChatID int64 // required ReplyKeyboardMarkup interface{} InlineKeyboardMarkup InlineKeyboardMarkup }
BaseChat is base type for all chat config types.
type BaseFile ¶
type BaseFile struct { BaseChat File RequestFileData }
BaseFile is a base type for all file config types.
type BotAPI ¶
type BotAPI struct { Token string `json:"token"` Debug bool `json:"debug"` Client HTTPClient `json:"-"` MessageHandlers MessageHandlers CallbackHandlers CallbackHandlers MiddlewareHandlers MiddlewareHandlers DefaultTypesHandlers map[string]MessageHandlerFunc // contains filtered or unexported fields }
func NewBotAPI ¶
NewBotAPI creates a new BotAPI instance.
It requires a token, provided by @BotFather on Telegram.
func NewBotAPIWithClient ¶
func NewBotAPIWithClient(token, apiEndpoint string, client HTTPClient) (*BotAPI, error)
func (*BotAPI) AddMiddleware ¶ added in v1.1.1
func (bot *BotAPI) AddMiddleware(handler MiddlewareHandlerFunc)
func (*BotAPI) FindCallbackHandler ¶
func (bot *BotAPI) FindCallbackHandler(action string) CallbackHandlerFunc
func (*BotAPI) FindMessageHandler ¶
func (bot *BotAPI) FindMessageHandler(action string) MessageHandlerFunc
func (*BotAPI) HandleCallback ¶
func (bot *BotAPI) HandleCallback(statePath string, handler CallbackHandlerFunc)
func (*BotAPI) HandleMessage ¶
func (bot *BotAPI) HandleMessage(statePath string, handler MessageHandlerFunc)
func (*BotAPI) HandleUpdates ¶
func (*BotAPI) MakeRequest ¶
func (bot *BotAPI) MakeRequest(endpoint string, params Params) (*APIResponse, error)
MakeRequest makes a request to a specific endpoint with our token.
func (*BotAPI) Send ¶
Send will send a Chattable item to Telegram and provides the returned Message.
func (*BotAPI) UploadFile ¶
func (bot *BotAPI) UploadFile(params Params, file RequestFile) (*UploadResponse, error)
type CallbackAnswerConfig ¶
type CallbackAnswerConfig struct { BaseChat CallbackId string `json:"callback_id"` Text string `json:"text"` ShowAlert bool `json:"show_alert"` }
func NewAnswerCallback ¶
func NewAnswerCallback(chatID int64, callbackId string, text string, showAlert bool) CallbackAnswerConfig
type CallbackHandlerFunc ¶
type CallbackHandlerFunc func(botApi *BotAPI, callback *CallbackQuery, params map[string]string) error
type CallbackHandlers ¶
type CallbackHandlers map[string]CallbackHandlerFunc
type CallbackQuery ¶
type CallbackQueryAction ¶
type DeleteMessageConfig ¶
type DeleteMessageConfig struct { BaseChat Type MESSAGE_TYPE `json:"type"` Text string `json:"data"` MessageId int64 `json:"message_id"` }
func NewDeleteMessage ¶
func NewDeleteMessage(chatID int64, messageID int64) DeleteMessageConfig
NewDeleteMessage creates a request to delete a messageHandler.
type Error ¶
type Error struct {
Message string
}
Error is an error containing extra information returned by the Telegram API.
type FORM_OBJECTS_TYPE ¶
type FORM_OBJECTS_TYPE string
const ( FORM_OBJECTS_TYPE_TEXT FORM_OBJECTS_TYPE = "text" FORM_OBJECTS_TYPE_RADIO FORM_OBJECTS_TYPE = "radio" FORM_OBJECTS_TYPE_SELECT FORM_OBJECTS_TYPE = "select" FORM_OBJECTS_TYPE_TEXTAREA FORM_OBJECTS_TYPE = "textarea" FORM_OBJECTS_TYPE_INBUILT FORM_OBJECTS_TYPE = "inbuilt" FORM_OBJECTS_TYPE_CHECKBOX FORM_OBJECTS_TYPE = "checkbox" FORM_OBJECTS_TYPE_SUBMIT FORM_OBJECTS_TYPE = "submit" )
type File ¶
type File struct { Id int64 `json:"id,omitempty"` SID string `json:"SID,omitempty"` RoundVideo bool `json:"RoundVideo,omitempty"` Extension string `json:"extension,omitempty"` Filename string `json:"filename,omitempty"` Filesize int64 `json:"filesize,omitempty"` Type string `json:"type,omitempty"` Width int64 `json:"width,omitempty"` Height int64 `json:"height,omitempty"` Duration float64 `json:"duration,omitempty"` Desc string `json:"desc,omitempty"` Path string `json:"path,omitempty"` Screenshots ImageUrls `json:"image_urls,omitempty"` }
type FileConfig ¶
func NewFile ¶
func NewFile(chatID int64, file RequestFileData) FileConfig
type FilePath ¶
type FilePath string
FilePath is a path to a local file.
func (FilePath) NeedsUpload ¶
type FileReader ¶
FileReader contains information about a reader to upload as a File.
func (FileReader) NeedsUpload ¶
func (fr FileReader) NeedsUpload() bool
func (FileReader) SendData ¶
func (fr FileReader) SendData() string
func (FileReader) UploadData ¶
func (fr FileReader) UploadData() (string, io.Reader, error)
type FormObject ¶
type FormObject struct { Name string `json:"name,omitempty"` Type FORM_OBJECTS_TYPE `json:"type,omitempty"` Label string `json:"label,omitempty"` Value string `json:"value,omitempty"` Options []FormObjectOption `json:"options,omitempty"` }
func NewForm ¶
func NewForm(formObject ...FormObject) []FormObject
func NewFormObjectBarcode ¶
func NewFormObjectBarcode(name, label string) FormObject
func NewFormObjectCheckbox ¶
func NewFormObjectCheckbox(name, label string) FormObject
func NewFormObjectInput ¶
func NewFormObjectInput(name, label string, value ...string) FormObject
func NewFormObjectInputWithValue ¶
func NewFormObjectInputWithValue(name, label, value string) FormObject
func NewFormObjectQrcode ¶
func NewFormObjectQrcode(name, label string) FormObject
func NewFormObjectRadioInput ¶
func NewFormObjectRadioInput(name, label string, options []FormObjectOption) FormObject
func NewFormObjectSelect ¶
func NewFormObjectSelect(name, label string, options []FormObjectOption) FormObject
func NewFormObjectSubmit ¶
func NewFormObjectSubmit(name, label string) FormObject
func NewFormObjectTextarea ¶
func NewFormObjectTextarea(name, label string, value ...string) FormObject
type FormObjectOption ¶
type HTTPClient ¶
HTTPClient is the type needed for the bot to perform HTTP requests.
type INLINE_KEYBOARD_CURRENCY ¶
type INLINE_KEYBOARD_CURRENCY string
const ( INLINE_KEYBOARD_CURRENCY_IRR INLINE_KEYBOARD_CURRENCY = "IRR" INLINE_KEYBOARD_CURRENCY_GAPCY INLINE_KEYBOARD_CURRENCY = "coin" )
type INLINE_KEYBOARD_URL_OPENIN ¶
type INLINE_KEYBOARD_URL_OPENIN string
const ( INLINE_KEYBOARD_URL_OPENIN_BROWSER INLINE_KEYBOARD_URL_OPENIN = "browser" INLINE_KEYBOARD_URL_OPENIN_INLINE_BROWSER INLINE_KEYBOARD_URL_OPENIN = "inline_browser" INLINE_KEYBOARD_URL_OPENIN_WEBVIEW INLINE_KEYBOARD_URL_OPENIN = "webview" INLINE_KEYBOARD_URL_OPENIN_WEBVIEW_FULL INLINE_KEYBOARD_URL_OPENIN = "webview_full" INLINE_KEYBOARD_URL_OPENIN_WEBVIEW_WITH_HEADER INLINE_KEYBOARD_URL_OPENIN = "webview_with_header" )
type InlineKeyboardButton ¶
type InlineKeyboardButton struct { Text string `json:"text"` CallbackData string `json:"cb_data,omitempty"` URL string `json:"url,omitempty"` OpenIn INLINE_KEYBOARD_URL_OPENIN `json:"open_in,omitempty"` Amount int `json:"amount,omitempty"` Currency INLINE_KEYBOARD_CURRENCY `json:"currency,omitempty"` RefId string `json:"ref_id,omitempty"` Description string `json:"desc,omitempty"` }
func NewInlineKeyboardButton ¶
func NewInlineKeyboardButton(text string, callbackData CallbackQueryAction) InlineKeyboardButton
func NewInlineKeyboardButtonPayment ¶
func NewInlineKeyboardButtonPayment(text string, amount int, currency INLINE_KEYBOARD_CURRENCY, refId, description string) InlineKeyboardButton
func NewInlineKeyboardButtonURL ¶
func NewInlineKeyboardButtonURL(text, url string, openIn INLINE_KEYBOARD_URL_OPENIN) InlineKeyboardButton
func NewInlineKeyboardRow ¶
func NewInlineKeyboardRow(buttons ...InlineKeyboardButton) []InlineKeyboardButton
NewInlineKeyboardRow creates an inline keyboard row with buttons.
type InlineKeyboardMarkup ¶
type InlineKeyboardMarkup [][]InlineKeyboardButton
func NewInlineKeyboardMarkup ¶
func NewInlineKeyboardMarkup(rows ...[]InlineKeyboardButton) InlineKeyboardMarkup
NewInlineKeyboardMarkup creates a new inline keyboard.
func (InlineKeyboardMarkup) AddButtonToEndRow ¶
func (ikm InlineKeyboardMarkup) AddButtonToEndRow(ikb InlineKeyboardButton) InlineKeyboardMarkup
func (InlineKeyboardMarkup) AddRow ¶
func (ikm InlineKeyboardMarkup) AddRow(rows []InlineKeyboardButton) InlineKeyboardMarkup
type MESSAGE_TYPE ¶
type MESSAGE_TYPE string
const ( MESSAGE_TYPE_JOIN MESSAGE_TYPE = "join" MESSAGE_TYPE_LEAVE MESSAGE_TYPE = "leave" MESSAGE_TYPE_TEXT MESSAGE_TYPE = "text" MESSAGE_TYPE_IMAGE MESSAGE_TYPE = "image" MESSAGE_TYPE_AUDIO MESSAGE_TYPE = "audio" MESSAGE_TYPE_VIDEO MESSAGE_TYPE = "video" MESSAGE_TYPE_VOICE MESSAGE_TYPE = "voice" MESSAGE_TYPE_FILE MESSAGE_TYPE = "file" MESSAGE_TYPE_CONTACT MESSAGE_TYPE = "contact" MESSAGE_TYPE_LOCATION MESSAGE_TYPE = "location" MESSAGE_TYPE_SUBMITFORM MESSAGE_TYPE = "submitForm" MESSAGE_TYPE_TRIGGER_BUTTON MESSAGE_TYPE = "triggerButton" MESSAGE_TYPE_PAY_CALLBACK MESSAGE_TYPE = "paycallback" MESSAGE_TYPE_INVOICE_CALLBACK MESSAGE_TYPE = "invoicecallback" )
type Message ¶
type Message struct { ChatID int64 `json:"chat_id"` MessageID int64 `json:"id"` Text string `json:"text"` Data string `json:"data"` From User `json:"from"` Type MESSAGE_TYPE `json:"type"` Photo File `json:"photo,omitempty"` Video File `json:"video,omitempty"` Voice File `json:"voice,omitempty"` Audio File `json:"audio,omitempty"` File File `json:"file,omitempty"` PaymentInfo PaymentInfo `json:"payment_info,omitempty"` CallbackQuery CallbackQuery `json:"callback,omitempty"` Contact Contact `json:"contact,omitempty"` Location Location `json:"location,omitempty"` FormData FormData `json:"form_data,omitempty"` }
Message represents a messageHandler.
func (*Message) UnmarshalJson ¶
type MessageConfig ¶
type MessageConfig struct { BaseChat Type MESSAGE_TYPE `json:"type"` Text string `json:"data"` Form []FormObject `json:"form"` }
func NewMessage ¶
func NewMessage(chatID int64, text string) MessageConfig
type MessageHandlerFunc ¶
type MessageHandlers ¶
type MessageHandlers map[string]MessageHandlerFunc
type MiddlewareHandlerFunc ¶ added in v1.1.1
type MiddlewareHandlers ¶ added in v1.1.0
type MiddlewareHandlers []MiddlewareHandlerFunc
type Params ¶
Params represents a set of parameters that gets passed to a request.
func (Params) AddFirstValid ¶
AddFirstValid attempts to add the first item that is not a default value.
For example, AddFirstValid(0, "", "sample") would add "sample".
func (Params) AddInterface ¶
AddInterface adds an interface if it is not nil and can be JSON marshalled.
func (Params) AddNonEmpty ¶
AddNonEmpty adds a value if it not an empty string.
func (Params) AddNonZero ¶
AddNonZero adds a value if it is not zero.
func (Params) AddNonZero64 ¶
AddNonZero64 is the same as AddNonZero except uses an int64.
func (Params) AddNonZeroFloat ¶
AddNonZeroFloat adds a floating point value that is not zero.
type PaymentInfo ¶
type PhotoConfig ¶
func NewPhoto ¶
func NewPhoto(chatID int64, file RequestFileData) PhotoConfig
type ReplyKeyboardButton ¶
func NewKeyboardButton ¶
func NewKeyboardButton(text string, value string) ReplyKeyboardButton
NewKeyboardButton creates a regular keyboard button.
func NewKeyboardButtonContact ¶
func NewKeyboardButtonContact(text string) ReplyKeyboardButton
func NewKeyboardButtonLocation ¶
func NewKeyboardButtonLocation(text string) ReplyKeyboardButton
func NewKeyboardButtonRow ¶
func NewKeyboardButtonRow(buttons ...ReplyKeyboardButton) []ReplyKeyboardButton
type ReplyKeyboardMarkup ¶
type ReplyKeyboardMarkup struct {
Keyboard [][]ReplyKeyboardButton `json:"keyboard"`
}
func NewReplyKeyboardMarkup ¶
func NewReplyKeyboardMarkup(rows ...[]ReplyKeyboardButton) ReplyKeyboardMarkup
NewReplyKeyboardMarkup creates a new regular keyboard with sane defaults.
type RequestFile ¶
type RequestFile struct { // The file field name. Name string Type MESSAGE_TYPE // The file data to include. Data RequestFileData }
type RequestFileData ¶
type RequestFileData interface { // NeedsUpload shows if the file needs to be uploaded. NeedsUpload() bool // UploadData gets the file name and an `io.Reader` for the file to be uploaded. This // must only be called when the file needs to be uploaded. UploadData() (string, io.Reader, error) // SendData gets the file data to send when a file does not need to be uploaded. This // must only be called when the file does not need to be uploaded. SendData() string }
type UpdateMessageConfig ¶
type UpdateMessageConfig struct { BaseChat Type MESSAGE_TYPE `json:"type"` Text string `json:"data"` MessageId int64 `json:"message_id"` }
func NewUpdateMessage ¶
func NewUpdateMessage(chatID int64, messageID int64, text string) UpdateMessageConfig
type UploadResponse ¶
type UploadResponse struct { APIResponse `json:"-"` File `json:"-"` }
type VideoConfig ¶
func NewVideo ¶
func NewVideo(chatID int64, file RequestFileData) VideoConfig
type VoiceConfig ¶
func NewVoice ¶
func NewVoice(chatID int64, file RequestFileData) VoiceConfig