Documentation ¶
Index ¶
- Constants
- func DecodeJSON[T any](r io.Reader) (*T, []byte, error)
- func Request[T any](a *API, method string, d *Data) (T, error)
- func RequestContext[T any](ctx context.Context, a *API, method string, data *Data) (result T, err error)
- type API
- type Data
- func (d *Data) AddAttach(file tg.Inputtable)
- func (d *Data) AddFile(field string, file tg.Inputtable)
- func (d *Data) Data() (string, io.Reader)
- func (d *Data) Set(k, v string, force ...bool) *Data
- func (d *Data) SetBool(key string, v bool, force ...bool) *Data
- func (d *Data) SetFile(field string, file, thumb tg.Inputtable)
- func (d *Data) SetFloat(key string, v float32, force ...bool) *Data
- func (d *Data) SetFloat64(key string, v float64, force ...bool) *Data
- func (d *Data) SetInt(key string, v int, force ...bool) *Data
- func (d *Data) SetInt64(key string, v int64, force ...bool) *Data
- func (d *Data) SetJSON(key string, v any) *Data
- type DownloadError
- type Empty
- type Error
- type JSONError
Constants ¶
const DefaultAPIURL = "https://api.telegram.org/bot"
DefaultAPIURL is a default url for telegram api.
const DefaultFileURL = "https://api.telegram.org/file/bot"
DefaultFileURL is a default url for downloading files.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes reader into object or returns raw json data if error occured.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API provides access to the Telegram Bot API.
func New ¶
New creates a new API instance. If apiURL or fileURL are empty, the Telegram defaults are used. If client is nil, the http.DefaultClient is used.
func NewDefault ¶
NewDefault creates a new API instance with default values.
func (*API) DownloadFile ¶
func (a *API) DownloadFile(path string) (io.ReadCloser, error)
DownloadFile downloads a file from the server with background context.
func (*API) DownloadFileContext ¶
DownloadFileContext downloads a file from the server.
type Data ¶
type Data struct { // contains query parameters and files that does not need to be uploaded. Params map[string]string // key is a multipart field name. Files map[string]*tg.InputFile // contains filtered or unexported fields }
Data contains query parameters and files data.
func (*Data) AddAttach ¶
func (d *Data) AddAttach(file tg.Inputtable)
AddAttach links a file to the multipart field and adds it. If the file is not *tg.InputFile, it does nothing.
func (*Data) SetFile ¶
func (d *Data) SetFile(field string, file, thumb tg.Inputtable)
SetFile sets file with thumbnail.
func (*Data) SetFloat64 ¶
SetFloat64 sets the key to float64 value.
type DownloadError ¶
DownloadError represents download error.
func (*DownloadError) Error ¶
func (e *DownloadError) Error() string
func (*DownloadError) Unwrap ¶
func (e *DownloadError) Unwrap() error
type Empty ¶
type Empty struct{}
Empty type is used to avoid spending resources on unmarshaling.
func (*Empty) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.