maxbot

package module
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 19 Imported by: 6

README

Max Bot API Client library for Golang

Документация

В документации вы можете найти подробные инструкции по использованию фреймворка.

Быстрый старт

Если вы новичок, то можете прочитать официальную документацию, написанную разработчиками Max

Получение токена

Откройте диалог с MasterBot, следуйте инструкциям и создайте нового бота. После создания бота MasterBot отправит вам токен.

Documentation

Overview

Package maxbot implements MAX Bot API. Official documentation: https://dev.max.ru/

Index

Constants

View Source
const (
	// Deprecated: not allowed
	Version = "1.2.5"

	SecretHeader = "X-Max-Bot-Api-Secret"

	DefaultAPIURL = "https://platform-api2.max.ru/"
)

Variables

View Source
var (
	ErrEmptyToken = errors.New("bot token is empty")
	ErrInvalidURL = errors.New("invalid API URL")
)

Functions

func Btn added in v1.6.15

func Btn(text, payload string, intent ...schemes.Intent) schemes.ButtonInterface

Btn creates a standard Callback button. Optionally, you can pass schemes.Intent (default is schemes.DEFAULT).

func BtnApp added in v1.6.15

func BtnApp(text, app, payload string, contactId int64) schemes.ButtonInterface

BtnApp creates a button to open the Web App.

func BtnClipboard added in v1.6.15

func BtnClipboard(text, payload string) schemes.ButtonInterface

BtnClipboard creates a button to copy to the clipboard.

func BtnContact added in v1.6.15

func BtnContact(text string) schemes.ButtonInterface

BtnContact creates a contact request button.

func BtnGeo added in v1.6.15

func BtnGeo(text string, quick bool) schemes.ButtonInterface

BtnGeo creates a location request button.

func BtnLink(text, url string) schemes.ButtonInterface

BtnLink creates a link button.

func BtnMsg added in v1.6.15

func BtnMsg(text string) schemes.ButtonInterface

BtnMsg creates a button to send text on behalf of the user.

func Row added in v1.6.15

Row creates one line of buttons.

Types

type APIError

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Details string `json:"details,omitempty"`
}

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsAttachmentNotReady

func (e *APIError) IsAttachmentNotReady() bool

type Api

type Api struct {
	Bots          *bots
	Chats         *chats
	Debugs        *debugs
	Messages      *messages
	Subscriptions *subscriptions
	Uploads       *uploads
	// contains filtered or unexported fields
}

Api represents the MAX Bot API client.

func New

func New(token string, opts ...Option) (*Api, error)

New creates a new Max Bot API client with the provided token.

func (*Api) GetErrors

func (a *Api) GetErrors() <-chan error

func (*Api) GetHandler

func (a *Api) GetHandler(updates chan<- schemes.UpdateInterface) http.HandlerFunc

GetHandler returns an http.HandlerFunc for webhook handling. Deprecated: use GetUpdateHandler for channel. Or if you want use updateHandler directly use GetUpdateHandlerFunc.

func (*Api) GetUpdateHandler added in v1.6.9

func (a *Api) GetUpdateHandler(updates chan<- schemes.UpdateInterface, secret string) http.HandlerFunc

func (*Api) GetUpdateHandlerFunc added in v1.6.9

func (a *Api) GetUpdateHandlerFunc(h UpdateHandler, secret string) http.HandlerFunc

func (*Api) GetUpdates

func (a *Api) GetUpdates(ctx context.Context) <-chan schemes.UpdateInterface

GetUpdates returns a channel that delivers updates from the API.

type HttpClient

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

type Keyboard

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

Keyboard implements a builder for the inline keyboard.

func InlineKeyboard added in v1.6.15

func InlineKeyboard(rows ...[]schemes.ButtonInterface) *Keyboard

InlineKeyboard create inline keyboard

func (*Keyboard) AddRow

func (k *Keyboard) AddRow() *KeyboardRow

AddRow adds a row to the inline keyboard.

func (*Keyboard) Build

func (k *Keyboard) Build() schemes.Keyboard

Build returns the keyboard.

type KeyboardRow

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

KeyboardRow represents a button row.

func (*KeyboardRow) AddButton

func (*KeyboardRow) AddCallback

func (k *KeyboardRow) AddCallback(text string, intent schemes.Intent, payload string) *KeyboardRow

AddCallback button.

func (*KeyboardRow) AddClipboard added in v1.6.11

func (k *KeyboardRow) AddClipboard(text, payload string) *KeyboardRow

func (*KeyboardRow) AddContact

func (k *KeyboardRow) AddContact(text string) *KeyboardRow

AddContact button.

func (*KeyboardRow) AddGeolocation

func (k *KeyboardRow) AddGeolocation(text string, quick bool) *KeyboardRow

AddGeolocation button.

func (k *KeyboardRow) AddLink(text string, _ schemes.Intent, url string) *KeyboardRow

AddLink button.

func (*KeyboardRow) AddMessage

func (k *KeyboardRow) AddMessage(text string) *KeyboardRow

AddMessage button.

func (*KeyboardRow) AddOpenApp

func (k *KeyboardRow) AddOpenApp(text string, app, payload string, contactId int64) *KeyboardRow

AddOpenApp button.

func (*KeyboardRow) Build

func (k *KeyboardRow) Build() []schemes.ButtonInterface

Build returns keyboard rows.

type Message

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

func NewMessage

func NewMessage() *Message

func (*Message) AddAudio

func (m *Message) AddAudio(audio *schemes.UploadedInfo) *Message

func (*Message) AddContact

func (m *Message) AddContact(name string, contactID int64, vcfInfo string, vcfPhone string) *Message

func (*Message) AddFile

func (m *Message) AddFile(file *schemes.UploadedInfo) *Message

func (*Message) AddKeyboard

func (m *Message) AddKeyboard(keyboard *Keyboard) *Message

func (*Message) AddLocation

func (m *Message) AddLocation(lat float64, lon float64) *Message

func (*Message) AddMarkUp

func (m *Message) AddMarkUp(user int64, from int, len int) *Message

func (*Message) AddPhoto

func (m *Message) AddPhoto(photo *schemes.PhotoTokens) *Message

func (*Message) AddPhotoByToken

func (m *Message) AddPhotoByToken(token string) *Message

func (*Message) AddSticker

func (m *Message) AddSticker(code string) *Message

func (*Message) AddVideo

func (m *Message) AddVideo(video *schemes.UploadedInfo) *Message

func (*Message) Reply

func (m *Message) Reply(text string, reply schemes.Message) *Message

func (*Message) SetChat

func (m *Message) SetChat(chatID int64) *Message

func (*Message) SetDisableLinkPreview added in v1.6.10

func (m *Message) SetDisableLinkPreview(disableLinkPreview bool) *Message

func (*Message) SetFormat

func (m *Message) SetFormat(format schemes.Format) *Message

func (*Message) SetForward added in v1.6.22

func (m *Message) SetForward(id string) *Message

func (*Message) SetNotify

func (m *Message) SetNotify(notify bool) *Message

func (*Message) SetPhoneNumbers

func (m *Message) SetPhoneNumbers(phoneNumbers []string) *Message

func (*Message) SetReply

func (m *Message) SetReply(text, id string) *Message

func (*Message) SetReset

func (m *Message) SetReset(reset bool) *Message

func (*Message) SetText

func (m *Message) SetText(text string) *Message

func (*Message) SetUser

func (m *Message) SetUser(userID int64) *Message

type MessageResponse

type MessageResponse struct {
	Message schemes.Message `json:"message"`
}

MessageResponse represents the response wrapper when a message is sent

type NetworkError

type NetworkError struct {
	Op  string
	Err error
}

func (*NetworkError) Error

func (e *NetworkError) Error() string

func (*NetworkError) Unwrap

func (e *NetworkError) Unwrap() error

type Option

type Option func(api *Api)

func WithApiTimeout

func WithApiTimeout(timeout time.Duration) Option

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithDebugChat

func WithDebugChat(chat int64) Option

func WithDebugMode

func WithDebugMode() Option

func WithErrorBufferSize added in v1.6.21

func WithErrorBufferSize(size int) Option

WithErrorBufferSize задаёт ёмкость канала ошибок, возвращаемого GetErrors(). Больший буфер снижает риск потери ошибок при всплесках (повторные сбои long polling и т.п.). Значения меньше 1 игнорируются.

func WithHTTPClient

func WithHTTPClient(httpClient HttpClient) Option

func WithPauseTimeout

func WithPauseTimeout(timeout time.Duration) Option

func WithUpdateHandler

func WithUpdateHandler(f UpdateHandler) Option

func WithVersion deprecated

func WithVersion(_ string) Option

Deprecated: not allowed

type SerializationError

type SerializationError struct {
	Op   string
	Type string
	Err  error
}

func (*SerializationError) Error

func (e *SerializationError) Error() string

func (*SerializationError) Unwrap

func (e *SerializationError) Unwrap() error

type TimeoutError

type TimeoutError struct {
	Op     string
	Reason string
}

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

func (*TimeoutError) Timeout

func (e *TimeoutError) Timeout() bool

type UpdateHandler

type UpdateHandler func(schemes.UpdateInterface)

type UpdatesParams

type UpdatesParams struct {
	Limit   int
	Timeout time.Duration
	Marker  int64
	Types   []string
}

UpdatesParams holds parameters for getting updates.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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