maxigo

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 12 Imported by: 0

README

maxigo-client

Idiomatic Go HTTP client for Max Bot API (OpenAPI schema v0.0.10). Zero external dependencies.

Why This Project?

The official max-bot-api-client-go has systemic issues that make it unsuitable for production use:

Category Issues Severity
Errors swallowed via log.Println / slog.Error 30+ places Critical — library must not write to stdout
Untestable without real API No WithBaseURL, uploads use http.DefaultClient Critical — impossible to unit test
Unnecessary dependencies zerolog, yaml, env — 6 transitive deps Critical — for an HTTP client
Broken API methods GetChatID() returns 0 for callbacks Critical — callbacks unusable
Wrong types time.Duration for Unix timestamps, int64→int casts Critical — data corruption on 32-bit
No context.Context in uploads http.Get() without timeout or cancellation Critical — can hang forever
Non-idiomatic API Builder pattern, SCREAMING_CASE, no functional options Major
schemes.Error always non-nil Check() returns error even on success Critical — always errors

maxigo-client fixes all of these.

Documentation

Installation

go get github.com/maxigo-bot/maxigo-client

Quick Start

package main

import (
	"context"
	"fmt"
	"log"

	maxigo "github.com/maxigo-bot/maxigo-client"
)

func main() {
	client, err := maxigo.New("YOUR_BOT_TOKEN")
	if err != nil {
		log.Fatal(err)
	}

	bot, err := client.GetBot(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Bot: %s (ID: %d)\n", bot.FirstName, bot.UserID)
}

Features

  • Zero external dependencies — only stdlib
  • All methods take context.Context
  • Structured error handling with errors.As
  • Full Max Bot API coverage: messages, chats, uploads, webhooks, long polling
  • Type-safe constructors for all button types and attachments
  • Optional[T] generics for three-state fields (unset / zero / value)
  • Testable without real API via WithBaseURL

Type-Safe Constructors

No need to remember string constants — use constructors for buttons and attachments:

Buttons:

maxigo.NewCallbackButton("Click", "payload")                        // callback
maxigo.NewCallbackButtonWithIntent("Yes", "yes", maxigo.IntentPositive) // callback with intent
maxigo.NewLinkButton("Open", "https://example.com")                 // link
maxigo.NewRequestContactButton("Share contact")                     // request contact
maxigo.NewRequestGeoLocationButton("Send location", true)           // request geo (quick=true)
maxigo.NewChatButton("Create chat", "Title")                        // create chat
maxigo.NewMessageButton("Send")                                     // message from user
maxigo.NewOpenAppButton("Open WebApp", "bot_username")               // open mini-app

Attachments:

maxigo.NewInlineKeyboardAttachment(buttons) // inline keyboard
maxigo.NewPhotoAttachment(payload)          // image
maxigo.NewVideoAttachment(payload)          // video
maxigo.NewAudioAttachment(payload)          // audio
maxigo.NewFileAttachment(payload)           // file
maxigo.NewStickerAttachment(payload)        // sticker
maxigo.NewContactAttachment(payload)        // contact card
maxigo.NewShareAttachment(payload)          // share link
maxigo.NewLocationAttachment(lat, lng)      // location

Example — inline keyboard with contact and geo buttons:

msg, err := client.SendMessage(ctx, chatID, &maxigo.NewMessageBody{
    Text: maxigo.Some("Choose an option:"),
    Attachments: []maxigo.AttachmentRequest{
        maxigo.NewInlineKeyboardAttachment([][]maxigo.Button{
            {
                maxigo.NewRequestContactButton("Share contact"),
                maxigo.NewRequestGeoLocationButton("Send location", false),
            },
            {
                maxigo.NewCallbackButtonWithIntent("Cancel", "cancel", maxigo.IntentNegative),
            },
        }),
    },
})

API Overview

// Bot
client.GetBot(ctx)
client.EditBot(ctx, patch)

// Messages
client.SendMessage(ctx, chatID, body)
client.EditMessage(ctx, messageID, body)
client.DeleteMessage(ctx, messageID)
client.AnswerCallback(ctx, callbackID, answer)

// Chats
client.GetChat(ctx, chatID)
client.GetChats(ctx, opts)
client.EditChat(ctx, chatID, patch)
client.GetMembers(ctx, chatID, opts)
client.SendAction(ctx, chatID, action)

// Uploads
client.UploadPhoto(ctx, filename, reader)
client.UploadMedia(ctx, uploadType, filename, reader)

// Webhooks
client.Subscribe(ctx, url, types, secret)
client.Unsubscribe(ctx, url)

// Long Polling
client.GetUpdates(ctx, opts)

Error Handling

var e *maxigo.Error
if errors.As(err, &e) {
    fmt.Printf("[%s] %s %d: %s\n", e.Op, e.Kind, e.StatusCode, e.Message)
}

Error kinds: ErrAPI, ErrNetwork, ErrTimeout, ErrDecode. See guide for details.

Ecosystem

Package Description
github.com/maxigo-bot/maxigo-client HTTP client
github.com/maxigo/maxigo Bot framework with router/middleware/context

Both packages are currently in development and not yet published.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyToken = errors.New("bot token is empty")

ErrEmptyToken is returned when an empty token is passed to New.

View Source
var ErrPollDeadline = errors.New("context deadline is shorter than polling timeout + buffer; increase the deadline or reduce GetUpdatesOpts.Timeout")

ErrPollDeadline is returned by Client.GetUpdates when the context deadline is too short for the requested long-polling timeout.

Functions

This section is empty.

Types

type ActionRequestBody

type ActionRequestBody struct {
	Action SenderAction `json:"action"`
}

ActionRequestBody is the request body for POST /chats/{chatId}/actions.

type Attachment added in v0.2.0

type Attachment interface {
	// GetType returns the attachment type string (e.g. "image", "video", "contact").
	GetType() string
}

Attachment is implemented by all attachment response types. Use MessageBody.ParseAttachments to convert raw JSON attachments into typed structs, then type-switch on the result.

type AttachmentRequest

type AttachmentRequest struct {
	Type    string `json:"type"`
	Payload any    `json:"payload,omitempty"`

	// Location
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`

	// Reply keyboard
	Buttons      [][]ReplyButton `json:"buttons,omitempty"`
	Direct       bool            `json:"direct,omitempty"`
	DirectUserID OptInt64        `json:"direct_user_id,omitzero"`
}

AttachmentRequest represents a request to attach something to a message.

Use the constructor functions (NewPhotoAttachment, NewVideoAttachment, etc.) for type-safe attachment creation. The Payload field accepts specific payload types depending on Type — see each constructor for details.

func NewAudioAttachment

func NewAudioAttachment(payload UploadedInfo) AttachmentRequest

NewAudioAttachment creates an audio attachment request from an upload token.

func NewContactAttachment

func NewContactAttachment(payload ContactAttachmentRequestPayload) AttachmentRequest

NewContactAttachment creates a contact attachment request.

func NewFileAttachment

func NewFileAttachment(payload UploadedInfo) AttachmentRequest

NewFileAttachment creates a file attachment request from an upload token.

func NewInlineKeyboardAttachment

func NewInlineKeyboardAttachment(buttons [][]Button) AttachmentRequest

NewInlineKeyboardAttachment creates an inline keyboard attachment request.

func NewLocationAttachment

func NewLocationAttachment(latitude, longitude float64) AttachmentRequest

NewLocationAttachment creates a location attachment request.

func NewPhotoAttachment

func NewPhotoAttachment(payload PhotoAttachmentRequestPayload) AttachmentRequest

NewPhotoAttachment creates an image attachment request.

func NewShareAttachment

func NewShareAttachment(payload ShareAttachmentPayload) AttachmentRequest

NewShareAttachment creates a share (link) attachment request.

func NewStickerAttachment

func NewStickerAttachment(payload StickerAttachmentRequestPayload) AttachmentRequest

NewStickerAttachment creates a sticker attachment request.

func NewVideoAttachment

func NewVideoAttachment(payload UploadedInfo) AttachmentRequest

NewVideoAttachment creates a video attachment request from an upload token.

type AttachmentType

type AttachmentType struct {
	Type string `json:"type"`
}

AttachmentType is embedded in all attachment responses.

func (AttachmentType) GetType added in v0.2.0

func (a AttachmentType) GetType() string

GetType implements the Attachment interface.

type AudioAttachment

type AudioAttachment struct {
	AttachmentType
	Payload       MediaAttachmentPayload `json:"payload"`
	Transcription *string                `json:"transcription,omitempty"`
}

AudioAttachment represents an audio attachment in a message.

type BotAddedUpdate

type BotAddedUpdate struct {
	Update
	ChatID    int64 `json:"chat_id"`
	User      User  `json:"user"`
	IsChannel bool  `json:"is_channel"`
}

BotAddedUpdate is received when the bot is added to a chat.

type BotCommand

type BotCommand struct {
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
}

BotCommand represents a command supported by the bot.

type BotInfo

type BotInfo struct {
	UserWithPhoto
	// Commands supported by the bot (up to 32).
	Commands []BotCommand `json:"commands,omitempty"`
}

BotInfo represents the bot's info returned by GET /me.

type BotPatch

type BotPatch struct {
	// Deprecated: use FirstName instead. Will be removed in a future API version.
	Name        OptString                      `json:"name,omitzero"`
	FirstName   OptString                      `json:"first_name,omitzero"`
	Description OptString                      `json:"description,omitzero"`
	Commands    []BotCommand                   `json:"commands,omitempty"`
	Photo       *PhotoAttachmentRequestPayload `json:"photo,omitempty"`
}

BotPatch represents the request body for PATCH /me.

type BotRemovedUpdate

type BotRemovedUpdate struct {
	Update
	ChatID    int64 `json:"chat_id"`
	User      User  `json:"user"`
	IsChannel bool  `json:"is_channel"`
}

BotRemovedUpdate is received when the bot is removed from a chat.

type BotStartedUpdate

type BotStartedUpdate struct {
	Update
	ChatID     int64   `json:"chat_id"`
	User       User    `json:"user"`
	Payload    *string `json:"payload,omitempty"`
	UserLocale *string `json:"user_locale,omitempty"`
}

BotStartedUpdate is received when a user presses the Start button.

type BotStoppedUpdate added in v0.2.2

type BotStoppedUpdate struct {
	Update
	ChatID int64 `json:"chat_id"`
	User   User  `json:"user"`
}

BotStoppedUpdate is received when a user stops the bot.

type Button

type Button struct {
	Type            string    `json:"type"`
	Text            string    `json:"text"`
	Payload         string    `json:"payload,omitempty"`
	URL             string    `json:"url,omitempty"`
	Intent          Intent    `json:"intent,omitempty"`
	Quick           bool      `json:"quick,omitempty"`
	ChatTitle       string    `json:"chat_title,omitempty"`
	ChatDescription OptString `json:"chat_description,omitzero"`
	StartPayload    OptString `json:"start_payload,omitzero"`
	UUID            OptInt64  `json:"uuid,omitzero"`
	WebApp          string    `json:"web_app,omitempty"`
}

Button represents a button in an inline keyboard. Use the Type field to determine the button kind: "callback", "link", "request_contact", "request_geo_location", "chat", "message", "open_app".

func NewCallbackButton added in v0.2.0

func NewCallbackButton(text, payload string) Button

NewCallbackButton creates a callback button that sends payload to the bot.

func NewCallbackButtonWithIntent added in v0.2.0

func NewCallbackButtonWithIntent(text, payload string, intent Intent) Button

NewCallbackButtonWithIntent creates a callback button with a visual intent.

func NewChatButton added in v0.2.0

func NewChatButton(text, chatTitle string) Button

NewChatButton creates a button that creates a new chat when pressed. The bot will be added as administrator and the message author will own the chat.

func NewLinkButton added in v0.2.0

func NewLinkButton(text, url string) Button

NewLinkButton creates a button that opens a URL when pressed.

func NewMessageButton added in v0.2.0

func NewMessageButton(text string) Button

NewMessageButton creates a button that sends a message from the user in chat.

func NewOpenAppButton added in v0.2.2

func NewOpenAppButton(text, webApp string) Button

NewOpenAppButton creates a button that opens a mini app inside the messenger. The webApp parameter is the bot username whose mini app to launch.

func NewRequestContactButton added in v0.2.0

func NewRequestContactButton(text string) Button

NewRequestContactButton creates a button that requests the user's contact information.

func NewRequestGeoLocationButton added in v0.2.0

func NewRequestGeoLocationButton(text string, quick bool) Button

NewRequestGeoLocationButton creates a button that requests the user's location. If quick is true, the location is sent without asking user's confirmation.

type Callback

type Callback struct {
	Timestamp  int64  `json:"timestamp"`
	CallbackID string `json:"callback_id"`
	Payload    string `json:"payload,omitempty"`
	User       User   `json:"user"`
}

Callback represents the data received when a user presses an inline button.

type CallbackAnswer

type CallbackAnswer struct {
	Message      *NewMessageBody `json:"message,omitempty"`
	Notification OptString       `json:"notification,omitzero"`
}

CallbackAnswer represents the response to a callback.

type Chat

type Chat struct {
	// Chat identifier.
	ChatID int64 `json:"chat_id"`
	// Chat type: "chat" (group), "dialog" (direct), or "channel".
	Type ChatType `json:"type"`
	// Bot's status in the chat: "active", "removed", "left", "closed".
	Status ChatStatus `json:"status"`
	// Display title. May be null for dialogs.
	Title *string `json:"title"`
	// Chat icon.
	Icon *Image `json:"icon"`
	// Last event time in the chat (Unix time).
	LastEventTime int64 `json:"last_event_time"`
	// Number of participants. Always 2 for dialogs.
	ParticipantsCount int `json:"participants_count"`
	// Chat owner ID.
	OwnerID *int64 `json:"owner_id,omitempty"`
	// Participants with last activity time. May be null for chat lists.
	Participants map[string]int64 `json:"participants,omitempty"`
	// Whether the chat is publicly accessible (always false for dialogs).
	IsPublic bool `json:"is_public"`
	// Chat invite link.
	Link *string `json:"link,omitempty"`
	// Chat description.
	Description *string `json:"description"`
	// User info for dialog chats (type "dialog" only).
	DialogWithUser *UserWithPhoto `json:"dialog_with_user,omitempty"`
	// Message count. Only for group chats and channels, not dialogs.
	MessagesCount *int `json:"messages_count,omitempty"`
	// ID of the message containing the button that initiated this chat.
	ChatMessageID *string `json:"chat_message_id,omitempty"`
	// Pinned message. Only returned when requesting a specific chat.
	PinnedMessage *Message `json:"pinned_message,omitempty"`
}

Chat represents a Max chat.

type ChatAdmin

type ChatAdmin struct {
	UserID      int64                 `json:"user_id"`
	Permissions []ChatAdminPermission `json:"permissions"`
	Alias       *string               `json:"alias,omitempty"`
}

ChatAdmin represents an administrator with permissions.

type ChatAdminPermission

type ChatAdminPermission string

ChatAdminPermission represents a permission granted to a chat admin.

const (
	PermReadAllMessages  ChatAdminPermission = "read_all_messages"
	PermAddRemoveMembers ChatAdminPermission = "add_remove_members"
	PermAddAdmins        ChatAdminPermission = "add_admins"
	PermChangeChatInfo   ChatAdminPermission = "change_chat_info"
	PermPinMessage       ChatAdminPermission = "pin_message"
	PermWrite            ChatAdminPermission = "write"
)

type ChatAdminsList

type ChatAdminsList struct {
	Admins []ChatAdmin `json:"admins"`
}

ChatAdminsList represents a list of chat admins.

type ChatList

type ChatList struct {
	Chats  []Chat `json:"chats"`
	Marker *int64 `json:"marker"`
}

ChatList represents a paginated list of chats.

type ChatMember

type ChatMember struct {
	UserWithPhoto
	// Last activity time in the chat. May be stale for superchats.
	LastAccessTime int64 `json:"last_access_time"`
	// Whether the user is the chat owner.
	IsOwner bool `json:"is_owner"`
	// Whether the user is a chat administrator.
	IsAdmin bool `json:"is_admin"`
	// Time when the user joined the chat (Unix time).
	JoinTime int64 `json:"join_time"`
	// Admin permissions. Null if the member is not an admin.
	Permissions []ChatAdminPermission `json:"permissions"`
	// Custom admin title shown in chat.
	Alias *string `json:"alias"`
}

ChatMember represents a member of a chat.

type ChatMembersList

type ChatMembersList struct {
	Members []ChatMember `json:"members"`
	Marker  *int64       `json:"marker,omitempty"`
}

ChatMembersList represents a paginated list of chat members.

type ChatPatch

type ChatPatch struct {
	Icon   *PhotoAttachmentRequestPayload `json:"icon,omitempty"`
	Title  OptString                      `json:"title,omitzero"`
	Pin    OptString                      `json:"pin,omitzero"`
	Notify OptBool                        `json:"notify,omitzero"`
}

ChatPatch represents the request body for PATCH /chats/{chatId}.

type ChatStatus

type ChatStatus string

ChatStatus represents the bot's status in a chat.

const (
	ChatStatusActive    ChatStatus = "active"
	ChatStatusRemoved   ChatStatus = "removed"
	ChatStatusLeft      ChatStatus = "left"
	ChatStatusClosed    ChatStatus = "closed"
	ChatStatusSuspended ChatStatus = "suspended"
)

type ChatTitleChangedUpdate

type ChatTitleChangedUpdate struct {
	Update
	ChatID int64  `json:"chat_id"`
	User   User   `json:"user"`
	Title  string `json:"title"`
}

ChatTitleChangedUpdate is received when a chat title is changed.

type ChatType

type ChatType string

ChatType represents the type of chat.

const (
	ChatDialog  ChatType = "dialog"
	ChatGroup   ChatType = "chat"
	ChatChannel ChatType = "channel"
)

type Client

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

Client is an HTTP client for the Max Bot API. Create one with New and configure it with Option functions.

All methods are safe for concurrent use.

func New

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

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

Use functional options to customize the client:

client, err := maxigo.New("your-token",
    maxigo.WithTimeout(10 * time.Second),
)

func (*Client) AddMembers

func (c *Client) AddMembers(ctx context.Context, chatID int64, userIDs []int64) (*SimpleQueryResult, error)

AddMembers adds members to a chat. Corresponds to POST /chats/{chatId}/members.

func (*Client) AnswerCallback

func (c *Client) AnswerCallback(ctx context.Context, callbackID string, answer *CallbackAnswer) (*SimpleQueryResult, error)

AnswerCallback sends a response to a callback button press. Corresponds to POST /answers.

func (*Client) DeleteChat

func (c *Client) DeleteChat(ctx context.Context, chatID int64) (*SimpleQueryResult, error)

DeleteChat deletes a chat for all participants. Corresponds to DELETE /chats/{chatId}.

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(ctx context.Context, messageID string) (*SimpleQueryResult, error)

DeleteMessage deletes a message. Corresponds to DELETE /messages.

func (*Client) EditBot

func (c *Client) EditBot(ctx context.Context, patch *BotPatch) (*BotInfo, error)

EditBot edits the current bot's info. Only filled fields will be updated; the rest remain unchanged. Corresponds to PATCH /me.

func (*Client) EditChat

func (c *Client) EditChat(ctx context.Context, chatID int64, patch *ChatPatch) (*Chat, error)

EditChat edits a chat's info (title, icon, pin). Corresponds to PATCH /chats/{chatId}.

func (*Client) EditMessage

func (c *Client) EditMessage(ctx context.Context, messageID string, body *NewMessageBody) (*SimpleQueryResult, error)

EditMessage edits an existing message. Corresponds to PUT /messages.

func (*Client) GetAdmins

func (c *Client) GetAdmins(ctx context.Context, chatID int64) (*ChatAdminsList, error)

GetAdmins returns all administrators of a chat. The bot must be an administrator in the chat. Corresponds to GET /chats/{chatId}/members/admins.

func (*Client) GetBot

func (c *Client) GetBot(ctx context.Context) (*BotInfo, error)

GetBot returns info about the current bot. Corresponds to GET /me.

func (*Client) GetChat

func (c *Client) GetChat(ctx context.Context, chatID int64) (*Chat, error)

GetChat returns info about a chat by its ID. Corresponds to GET /chats/{chatId}.

func (c *Client) GetChatByLink(ctx context.Context, chatLink string) (*Chat, error)

GetChatByLink returns chat/channel information by its public link or username. Corresponds to GET /chats/{chatLink}.

func (*Client) GetChats

func (c *Client) GetChats(ctx context.Context, opts GetChatsOpts) (*ChatList, error)

GetChats returns a paginated list of chats the bot participates in. Corresponds to GET /chats.

func (*Client) GetMembers

func (c *Client) GetMembers(ctx context.Context, chatID int64, opts GetMembersOpts) (*ChatMembersList, error)

GetMembers returns a paginated list of chat members. Corresponds to GET /chats/{chatId}/members.

func (*Client) GetMembership

func (c *Client) GetMembership(ctx context.Context, chatID int64) (*ChatMember, error)

GetMembership returns the bot's membership info for a chat. Corresponds to GET /chats/{chatId}/members/me.

func (*Client) GetMessageByID

func (c *Client) GetMessageByID(ctx context.Context, messageID string) (*Message, error)

GetMessageByID returns a single message by its identifier. Corresponds to GET /messages/{messageId}.

func (*Client) GetMessages

func (c *Client) GetMessages(ctx context.Context, opts GetMessagesOpts) (*MessageList, error)

GetMessages returns messages from a chat. Corresponds to GET /messages.

func (*Client) GetPinnedMessage

func (c *Client) GetPinnedMessage(ctx context.Context, chatID int64) (*GetPinnedMessageResult, error)

GetPinnedMessage returns the pinned message in a chat or channel. Corresponds to GET /chats/{chatId}/pin.

func (*Client) GetSubscriptions

func (c *Client) GetSubscriptions(ctx context.Context) ([]Subscription, error)

GetSubscriptions returns all active WebHook subscriptions. Corresponds to GET /subscriptions.

func (*Client) GetUpdates

func (c *Client) GetUpdates(ctx context.Context, opts GetUpdatesOpts) (*UpdateList, error)

GetUpdates fetches updates using long polling. Corresponds to GET /updates.

The client automatically adjusts the HTTP timeout to accommodate the server-side long-polling duration, preventing spurious timeout errors.

func (*Client) GetUploadURL

func (c *Client) GetUploadURL(ctx context.Context, uploadType UploadType) (*UploadEndpoint, error)

GetUploadURL returns a URL to upload a file of the given type. Corresponds to POST /uploads.

func (*Client) GetVideoDetails

func (c *Client) GetVideoDetails(ctx context.Context, videoToken string) (*VideoAttachmentDetails, error)

GetVideoDetails returns detailed information about a video attachment. Corresponds to GET /videos/{videoToken}.

func (*Client) LeaveChat

func (c *Client) LeaveChat(ctx context.Context, chatID int64) (*SimpleQueryResult, error)

LeaveChat removes the bot from chat members. Corresponds to DELETE /chats/{chatId}/members/me.

func (*Client) PinMessage

func (c *Client) PinMessage(ctx context.Context, chatID int64, body *PinMessageBody) (*SimpleQueryResult, error)

PinMessage pins a message in a chat or channel. Corresponds to PUT /chats/{chatId}/pin.

func (*Client) RemoveAdmin

func (c *Client) RemoveAdmin(ctx context.Context, chatID int64, userID int64) (*SimpleQueryResult, error)

RemoveAdmin revokes admin rights from a user in the chat. Corresponds to DELETE /chats/{chatId}/members/admins/{userId}.

func (*Client) RemoveMember

func (c *Client) RemoveMember(ctx context.Context, chatID int64, userID int64, block bool) (*SimpleQueryResult, error)

RemoveMember removes a member from a chat. Set block=true to also block the user (only for chats with public/private links). Corresponds to DELETE /chats/{chatId}/members.

func (*Client) SendAction

func (c *Client) SendAction(ctx context.Context, chatID int64, action SenderAction) (*SimpleQueryResult, error)

SendAction sends a bot action (e.g. typing) to a chat. Corresponds to POST /chats/{chatId}/actions.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, chatID int64, body *NewMessageBody) (*Message, error)

SendMessage sends a message to a chat. Set body.DisableLinkPreview to true to prevent the server from generating link previews. Corresponds to POST /messages.

func (*Client) SendMessageToUser

func (c *Client) SendMessageToUser(ctx context.Context, userID int64, body *NewMessageBody) (*Message, error)

SendMessageToUser sends a message directly to a user. Set body.DisableLinkPreview to true to prevent the server from generating link previews. Corresponds to POST /messages with user_id query parameter.

func (*Client) SetAdmins

func (c *Client) SetAdmins(ctx context.Context, chatID int64, admins *ChatAdminsList) (*SimpleQueryResult, error)

SetAdmins sets chat administrators with specified permissions. Corresponds to POST /chats/{chatId}/members/admins.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, webhookURL string, updateTypes []string, secret string) (*SimpleQueryResult, error)

Subscribe sets up a WebHook subscription for the bot. Corresponds to POST /subscriptions.

func (*Client) UnpinMessage

func (c *Client) UnpinMessage(ctx context.Context, chatID int64) (*SimpleQueryResult, error)

UnpinMessage unpins the pinned message in a chat or channel. Corresponds to DELETE /chats/{chatId}/pin.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, webhookURL string) (*SimpleQueryResult, error)

Unsubscribe removes a WebHook subscription. After calling this method, long polling becomes available again. Corresponds to DELETE /subscriptions.

func (*Client) UploadMedia

func (c *Client) UploadMedia(ctx context.Context, uploadType UploadType, filename string, reader io.Reader) (*UploadedInfo, error)

UploadMedia uploads a video, audio, or file and returns the token. This is a two-step operation: get upload URL, then upload the file.

func (*Client) UploadPhoto

func (c *Client) UploadPhoto(ctx context.Context, filename string, reader io.Reader) (*PhotoTokens, error)

UploadPhoto uploads an image and returns photo tokens. This is a two-step operation: get upload URL, then upload the file.

type ContactAttachment

type ContactAttachment struct {
	AttachmentType
	Payload ContactAttachmentPayload `json:"payload"`
}

ContactAttachment represents a contact attachment in a message.

type ContactAttachmentPayload

type ContactAttachmentPayload struct {
	VCFInfo *string `json:"vcf_info,omitempty"`
	MaxInfo *User   `json:"max_info,omitempty"`
}

ContactAttachmentPayload represents the payload of a contact attachment.

type ContactAttachmentRequestPayload

type ContactAttachmentRequestPayload struct {
	Name      OptString `json:"name,omitzero"`
	ContactID OptInt64  `json:"contact_id,omitzero"`
	VCFInfo   OptString `json:"vcf_info,omitzero"`
	VCFPhone  OptString `json:"vcf_phone,omitzero"`
}

ContactAttachmentRequestPayload is the payload for attaching a contact.

type DataAttachment

type DataAttachment struct {
	AttachmentType
	Data string `json:"data"`
}

DataAttachment contains a payload sent through a SendMessageButton.

type DialogClearedUpdate added in v0.2.2

type DialogClearedUpdate struct {
	Update
	ChatID int64 `json:"chat_id"`
	User   User  `json:"user"`
}

DialogClearedUpdate is received when a user clears the dialog history.

type DialogMutedUpdate added in v0.2.2

type DialogMutedUpdate struct {
	Update
	ChatID int64 `json:"chat_id"`
	User   User  `json:"user"`
}

DialogMutedUpdate is received when a user mutes the dialog with the bot.

type DialogRemovedUpdate added in v0.2.2

type DialogRemovedUpdate struct {
	Update
	ChatID int64 `json:"chat_id"`
	User   User  `json:"user"`
}

DialogRemovedUpdate is received when a user removes the dialog with the bot.

type DialogUnmutedUpdate added in v0.2.2

type DialogUnmutedUpdate struct {
	Update
	ChatID int64 `json:"chat_id"`
	User   User  `json:"user"`
}

DialogUnmutedUpdate is received when a user unmutes the dialog with the bot.

type Error

type Error struct {
	// Kind classifies the error category.
	Kind ErrorKind
	// StatusCode is the HTTP status code. Only set when Kind is ErrAPI.
	StatusCode int
	// Message is a human-readable error description.
	Message string
	// Op is the client operation that failed (e.g. "SendMessage", "GetChat").
	Op string
	// Err is the underlying error, if any.
	Err error
}

Error represents any error produced by the maxigo client.

Use errors.As to extract the Error and inspect its fields:

var e *maxigo.Error
if errors.As(err, &e) {
    switch e.Kind {
    case maxigo.ErrAPI:
        log.Printf("API error %d: %s", e.StatusCode, e.Message)
    case maxigo.ErrTimeout:
        log.Printf("timeout in %s", e.Op)
    }
}

func (*Error) Error

func (e *Error) Error() string

Error returns a formatted error string including the operation, kind, and details.

func (*Error) Timeout

func (e *Error) Timeout() bool

Timeout reports whether the error represents a timeout. This implements the informal timeout interface used by net.Error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error for use with errors.Is and errors.As.

type ErrorKind

type ErrorKind int

ErrorKind classifies the category of an error returned by the client.

const (
	// ErrAPI indicates the Max Bot API returned a non-200 HTTP response.
	ErrAPI ErrorKind = iota
	// ErrNetwork indicates an HTTP transport failure (connection refused, DNS, etc.).
	ErrNetwork
	// ErrTimeout indicates the request timed out or the context deadline was exceeded.
	ErrTimeout
	// ErrDecode indicates a JSON marshal or unmarshal failure.
	ErrDecode
)

func (ErrorKind) String

func (k ErrorKind) String() string

String returns a human-readable name for the error kind.

type FileAttachment

type FileAttachment struct {
	AttachmentType
	Payload  FileAttachmentPayload `json:"payload"`
	Filename string                `json:"filename"`
	Size     int64                 `json:"size"`
}

FileAttachment represents a file attachment in a message.

type FileAttachmentPayload

type FileAttachmentPayload struct {
	URL   string `json:"url"`
	Token string `json:"token"`
}

FileAttachmentPayload represents the payload of a file attachment.

type GetChatsOpts

type GetChatsOpts struct {
	// Count limits the number of returned chats. 0 uses the server default (50).
	Count int
	// Marker is the pagination cursor. 0 for the first page.
	Marker int64
}

GetChatsOpts holds optional parameters for Client.GetChats.

type GetMembersOpts

type GetMembersOpts struct {
	// Count limits the number of returned members. 0 uses the server default (20).
	Count int
	// Marker is the pagination cursor. 0 for the first page.
	Marker int64
	// UserIDs filters members by specific user IDs.
	UserIDs []int64
}

GetMembersOpts holds optional parameters for Client.GetMembers.

type GetMessagesOpts

type GetMessagesOpts struct {
	// ChatID filters messages by chat. Required unless MessageIDs is set.
	ChatID int64
	// Count limits the number of returned messages. 0 uses the server default.
	Count int
	// MessageIDs requests specific messages by their IDs.
	MessageIDs []string
	// From is the start timestamp (inclusive). Messages are returned in reverse
	// chronological order, so From should be greater than To.
	From int64
	// To is the end timestamp (inclusive).
	To int64
}

GetMessagesOpts holds optional parameters for Client.GetMessages.

type GetPinnedMessageResult

type GetPinnedMessageResult struct {
	Message *Message `json:"message"`
}

GetPinnedMessageResult is the response from GET /chats/{chatId}/pin.

type GetUpdatesOpts

type GetUpdatesOpts struct {
	// Limit sets the maximum number of updates to return. 0 uses the server default (100).
	Limit int
	// Timeout sets the long-polling timeout in seconds. 0 uses the server default (30).
	Timeout int
	// Marker is the pagination cursor. 0 returns uncommitted updates.
	Marker int64
	// Types filters updates by type (e.g. "message_created", "message_callback").
	Types []string
}

GetUpdatesOpts holds optional parameters for Client.GetUpdates.

type Image

type Image struct {
	URL string `json:"url"`
}

Image represents a generic image object.

type InlineKeyboardAttachment

type InlineKeyboardAttachment struct {
	AttachmentType
	Payload Keyboard `json:"payload"`
}

InlineKeyboardAttachment represents an inline keyboard in a message.

type Intent

type Intent string

Intent represents the visual intent of a button.

const (
	IntentPositive Intent = "positive"
	IntentNegative Intent = "negative"
	IntentDefault  Intent = "default"
)

type Keyboard

type Keyboard struct {
	Buttons [][]Button `json:"buttons"`
}

Keyboard represents a two-dimensional array of buttons.

type LinkedMessage

type LinkedMessage struct {
	Type    MessageLinkType `json:"type"`
	Sender  *User           `json:"sender,omitempty"`
	ChatID  int64           `json:"chat_id,omitempty"`
	Message MessageBody     `json:"message"`
}

LinkedMessage represents a forwarded or replied message.

type LocationAttachment

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

LocationAttachment represents a location attachment in a message.

type MarkupElement

type MarkupElement struct {
	Type     string  `json:"type"`
	From     int     `json:"from"`
	Length   int     `json:"length"`
	URL      string  `json:"url,omitempty"`
	UserLink *string `json:"user_link,omitempty"`
	UserID   *int64  `json:"user_id,omitempty"`
}

MarkupElement represents a text formatting element in a message.

type MediaAttachmentPayload

type MediaAttachmentPayload struct {
	URL   string `json:"url"`
	Token string `json:"token"`
}

MediaAttachmentPayload represents the payload of video/audio attachments.

type Message

type Message struct {
	// User who sent the message.
	Sender *User `json:"sender,omitempty"`
	// Recipient — can be a user or a chat.
	Recipient Recipient `json:"recipient"`
	// Message creation time (Unix time).
	Timestamp int64 `json:"timestamp"`
	// Forwarded or replied-to message.
	Link *LinkedMessage `json:"link,omitempty"`
	// Message content: text and attachments.
	Body MessageBody `json:"body"`
	// Message statistics.
	Stat *MessageStat `json:"stat,omitempty"`
	// Public link to a channel post. Absent for dialogs and group chats.
	URL *string `json:"url,omitempty"`
}

Message represents a message in a chat.

type MessageBody

type MessageBody struct {
	MID         string            `json:"mid"`
	Seq         int64             `json:"seq"`
	Text        *string           `json:"text"`
	Attachments []json.RawMessage `json:"attachments"`
	Markup      []MarkupElement   `json:"markup,omitempty"`
}

MessageBody represents the body of a message.

func (*MessageBody) ParseAttachments added in v0.2.0

func (mb *MessageBody) ParseAttachments() ([]Attachment, error)

ParseAttachments unmarshals raw JSON attachments into typed structs. Each returned element is a pointer to one of the attachment types (e.g. *PhotoAttachment, *ContactAttachment). Use a type switch to inspect individual attachments.

Unknown attachment types are silently skipped for forward compatibility. Returns nil, nil when there are no attachments.

type MessageCallbackUpdate

type MessageCallbackUpdate struct {
	Update
	Callback   Callback `json:"callback"`
	Message    *Message `json:"message"`
	UserLocale *string  `json:"user_locale,omitempty"`
}

MessageCallbackUpdate is received when a user presses an inline button.

type MessageChatCreatedUpdate

type MessageChatCreatedUpdate struct {
	Update
	Chat         Chat    `json:"chat"`
	MessageID    string  `json:"message_id"`
	StartPayload *string `json:"start_payload,omitempty"`
}

MessageChatCreatedUpdate is received when a chat is created via a chat button.

type MessageCreatedUpdate

type MessageCreatedUpdate struct {
	Update
	// The newly created message.
	Message Message `json:"message"`
	// User's current locale (IETF BCP 47). Only available in dialogs.
	UserLocale *string `json:"user_locale,omitempty"`
}

MessageCreatedUpdate is received when a new message is created.

type MessageEditedUpdate

type MessageEditedUpdate struct {
	Update
	Message Message `json:"message"`
}

MessageEditedUpdate is received when a message is edited.

type MessageLinkType

type MessageLinkType string

MessageLinkType represents the type of linked message.

const (
	LinkForward MessageLinkType = "forward"
	LinkReply   MessageLinkType = "reply"
)

type MessageList

type MessageList struct {
	Messages []Message `json:"messages"`
}

MessageList represents a paginated list of messages.

type MessageRemovedUpdate

type MessageRemovedUpdate struct {
	Update
	MessageID string `json:"message_id"`
	ChatID    int64  `json:"chat_id"`
	UserID    int64  `json:"user_id"`
}

MessageRemovedUpdate is received when a message is removed.

type MessageStat

type MessageStat struct {
	Views int `json:"views"`
}

MessageStat represents message statistics.

type NewMessageBody

type NewMessageBody struct {
	// Message text (up to 4000 characters).
	Text OptString `json:"text,omitzero"`
	// Message attachments. If empty, all existing attachments will be removed.
	Attachments []AttachmentRequest `json:"attachments,omitzero"`
	// Link to another message (for reply or forward).
	Link *NewMessageLink `json:"link,omitempty"`
	// If false, chat members will not be notified (default true).
	Notify OptBool `json:"notify,omitzero"`
	// Text formatting mode: "markdown" or "html".
	Format Optional[TextFormat] `json:"format,omitzero"`

	// DisableLinkPreview prevents the server from generating link previews.
	// Sent as a query parameter, not in the JSON body.
	DisableLinkPreview bool `json:"-"`
}

NewMessageBody represents the body for sending or editing a message.

Use Some to set optional fields. Unset fields are omitted from JSON, which tells the server to keep the existing value when editing a message.

type NewMessageLink struct {
	Type MessageLinkType `json:"type"`
	MID  string          `json:"mid"`
}

NewMessageLink represents a link to another message (for reply/forward).

type OptBool added in v0.2.0

type OptBool = Optional[bool]

Common type aliases for convenience.

type OptInt64 added in v0.2.0

type OptInt64 = Optional[int64]

Common type aliases for convenience.

type OptString added in v0.2.0

type OptString = Optional[string]

Common type aliases for convenience.

type Option

type Option func(*Client)

Option configures the Client.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the default API base URL (https://botapi.max.ru). This is primarily useful for testing with httptest.Server.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom HTTP client. Useful for testing or custom transports. The client is shallow-copied to prevent mutation of the original.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the request timeout. Default is 30 seconds. This timeout is applied via context to each request that has no deadline set. For long-polling requests (Client.GetUpdates), the timeout is automatically extended to accommodate the server-side polling.

type Optional added in v0.2.0

type Optional[T any] struct {
	Value T
	Set   bool
}

Optional represents a value that may or may not be set. Use Some to create a set value. The zero value is unset.

When used with JSON struct tag "omitzero", unset fields are omitted from marshaled output. This allows distinguishing between three states:

  • Unset (zero value): field omitted from JSON
  • Set to zero value: field included (e.g. "" for string, false for bool)
  • Set to non-zero value: field included with value

func Some added in v0.2.0

func Some[T any](v T) Optional[T]

Some creates a set Optional with the given value.

func (Optional[T]) IsZero added in v0.2.0

func (o Optional[T]) IsZero() bool

IsZero reports whether the Optional is unset. Used by encoding/json with the "omitzero" tag option.

func (Optional[T]) MarshalJSON added in v0.2.0

func (o Optional[T]) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value. If the Optional is unset, it marshals as JSON null.

func (*Optional[T]) UnmarshalJSON added in v0.2.0

func (o *Optional[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the value and marks the Optional as set. JSON null is treated as unset (Set remains false).

type PhotoAttachment

type PhotoAttachment struct {
	AttachmentType
	Payload PhotoAttachmentPayload `json:"payload"`
}

PhotoAttachment represents an image attachment in a message.

type PhotoAttachmentPayload

type PhotoAttachmentPayload struct {
	PhotoID int64  `json:"photo_id"`
	Token   string `json:"token"`
	URL     string `json:"url"`
}

PhotoAttachmentPayload represents the payload of a photo attachment.

type PhotoAttachmentRequestPayload

type PhotoAttachmentRequestPayload struct {
	URL    OptString             `json:"url,omitzero"`
	Token  OptString             `json:"token,omitzero"`
	Photos map[string]PhotoToken `json:"photos,omitempty"`
}

PhotoAttachmentRequestPayload is the payload for attaching an image. Fields are mutually exclusive.

type PhotoToken

type PhotoToken struct {
	Token string `json:"token"`
}

PhotoToken represents an uploaded image token.

type PhotoTokens

type PhotoTokens struct {
	Photos map[string]PhotoToken `json:"photos"`
}

PhotoTokens is the response after uploading images.

type PinMessageBody

type PinMessageBody struct {
	MessageID string  `json:"message_id"`
	Notify    OptBool `json:"notify,omitzero"`
}

PinMessageBody is the request body for PUT /chats/{chatId}/pin.

type Recipient

type Recipient struct {
	ChatID   *int64   `json:"chat_id"`
	ChatType ChatType `json:"chat_type"`
	UserID   *int64   `json:"user_id"`
}

Recipient represents a message recipient (user or chat).

type ReplyButton

type ReplyButton struct {
	Type    string    `json:"type,omitempty"`
	Text    string    `json:"text"`
	Payload OptString `json:"payload,omitzero"`
	Intent  Intent    `json:"intent,omitempty"`
	Quick   bool      `json:"quick,omitempty"`
}

ReplyButton represents a button in a reply keyboard.

type ReplyKeyboardAttachment

type ReplyKeyboardAttachment struct {
	AttachmentType
	Buttons [][]ReplyButton `json:"buttons"`
}

ReplyKeyboardAttachment represents a reply keyboard in a message.

type SenderAction

type SenderAction string

SenderAction represents an action to send to chat members.

const (
	ActionTypingOn  SenderAction = "typing_on"
	ActionSendPhoto SenderAction = "sending_photo"
	ActionSendVideo SenderAction = "sending_video"
	ActionSendAudio SenderAction = "sending_audio"
	ActionSendFile  SenderAction = "sending_file"
	ActionMarkSeen  SenderAction = "mark_seen"
)

type ShareAttachment

type ShareAttachment struct {
	AttachmentType
	Payload     ShareAttachmentPayload `json:"payload"`
	Title       *string                `json:"title,omitempty"`
	Description *string                `json:"description,omitempty"`
	ImageURL    *string                `json:"image_url,omitempty"`
}

ShareAttachment represents a link share attachment in a message.

type ShareAttachmentPayload

type ShareAttachmentPayload struct {
	URL   OptString `json:"url,omitzero"`
	Token OptString `json:"token,omitzero"`
}

ShareAttachmentPayload represents the payload of a share attachment.

type SimpleQueryResult

type SimpleQueryResult struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
}

SimpleQueryResult represents a simple success/failure response.

type StickerAttachment

type StickerAttachment struct {
	AttachmentType
	Payload StickerAttachmentPayload `json:"payload"`
	Width   int                      `json:"width"`
	Height  int                      `json:"height"`
}

StickerAttachment represents a sticker attachment in a message.

type StickerAttachmentPayload

type StickerAttachmentPayload struct {
	URL  string `json:"url"`
	Code string `json:"code"`
}

StickerAttachmentPayload represents the payload of a sticker attachment.

type StickerAttachmentRequestPayload

type StickerAttachmentRequestPayload struct {
	Code string `json:"code"`
}

StickerAttachmentRequestPayload is the payload for attaching a sticker.

type Subscription

type Subscription struct {
	URL         string   `json:"url"`
	Time        int64    `json:"time"`
	UpdateTypes []string `json:"update_types"`
	Version     *string  `json:"version"`
}

Subscription represents a WebHook subscription.

type SubscriptionRequestBody

type SubscriptionRequestBody struct {
	URL         string   `json:"url"`
	Secret      string   `json:"secret,omitempty"`
	UpdateTypes []string `json:"update_types,omitempty"`
	Version     string   `json:"version,omitempty"`
}

SubscriptionRequestBody represents the request body for POST /subscriptions.

type TextFormat

type TextFormat string

TextFormat represents the text formatting mode.

const (
	FormatMarkdown TextFormat = "markdown"
	FormatHTML     TextFormat = "html"
)

type Update

type Update struct {
	// Discriminator that determines the update type.
	UpdateType UpdateType `json:"update_type"`
	// Unix time when the event occurred.
	Timestamp int64 `json:"timestamp"`
}

Update is the base for all update events.

type UpdateList

type UpdateList struct {
	Updates []json.RawMessage `json:"updates"`
	Marker  *int64            `json:"marker"`
}

UpdateList is the response from GET /updates.

type UpdateType

type UpdateType string

UpdateType represents the type of an update event.

const (
	UpdateMessageCreated     UpdateType = "message_created"
	UpdateMessageCallback    UpdateType = "message_callback"
	UpdateMessageEdited      UpdateType = "message_edited"
	UpdateMessageRemoved     UpdateType = "message_removed"
	UpdateBotStarted         UpdateType = "bot_started"
	UpdateBotStopped         UpdateType = "bot_stopped"
	UpdateBotAdded           UpdateType = "bot_added"
	UpdateBotRemoved         UpdateType = "bot_removed"
	UpdateUserAdded          UpdateType = "user_added"
	UpdateUserRemoved        UpdateType = "user_removed"
	UpdateChatTitleChanged   UpdateType = "chat_title_changed"
	UpdateMessageChatCreated UpdateType = "message_chat_created"
	UpdateDialogMuted        UpdateType = "dialog_muted"
	UpdateDialogUnmuted      UpdateType = "dialog_unmuted"
	UpdateDialogCleared      UpdateType = "dialog_cleared"
	UpdateDialogRemoved      UpdateType = "dialog_removed"
)

type UploadEndpoint

type UploadEndpoint struct {
	URL   string  `json:"url"`
	Token *string `json:"token,omitempty"`
}

UploadEndpoint is returned by POST /uploads.

type UploadType

type UploadType string

UploadType represents the type of file being uploaded.

const (
	UploadImage UploadType = "image"
	UploadVideo UploadType = "video"
	UploadAudio UploadType = "audio"
	UploadFile  UploadType = "file"
)

type UploadedInfo

type UploadedInfo struct {
	Token string `json:"token"`
}

UploadedInfo contains a token received after uploading media.

type User

type User struct {
	// Unique identifier of the user or bot.
	UserID int64 `json:"user_id"`
	// Display name of the user or bot.
	FirstName string `json:"first_name"`
	// Display last name. Not returned for bots.
	LastName *string `json:"last_name,omitempty"`
	// Bot username or unique public name. May be null for users.
	Username *string `json:"username,omitempty"`
	// True if this is a bot.
	IsBot bool `json:"is_bot"`
	// Last activity time in MAX (Unix time in milliseconds).
	// May be absent if the user disabled online status in settings.
	LastActivityTime int64 `json:"last_activity_time"`
}

User represents a Max user or bot.

type UserAddedUpdate

type UserAddedUpdate struct {
	Update
	ChatID    int64  `json:"chat_id"`
	User      User   `json:"user"`
	InviterID *int64 `json:"inviter_id,omitempty"`
	IsChannel bool   `json:"is_channel"`
}

UserAddedUpdate is received when a user is added to a chat.

type UserIDsList

type UserIDsList struct {
	UserIDs []int64 `json:"user_ids"`
}

UserIDsList is the request body for POST /chats/{chatId}/members.

type UserRemovedUpdate

type UserRemovedUpdate struct {
	Update
	ChatID    int64  `json:"chat_id"`
	User      User   `json:"user"`
	AdminID   *int64 `json:"admin_id,omitempty"`
	IsChannel bool   `json:"is_channel"`
}

UserRemovedUpdate is received when a user is removed from a chat.

type UserWithPhoto

type UserWithPhoto struct {
	User
	// User or bot description (up to 16000 characters).
	Description *string `json:"description,omitempty"`
	// Small avatar URL.
	AvatarURL string `json:"avatar_url,omitempty"`
	// Full-size avatar URL.
	FullAvatarURL string `json:"full_avatar_url,omitempty"`
}

UserWithPhoto extends User with avatar and description.

type VideoAttachment

type VideoAttachment struct {
	AttachmentType
	Payload   MediaAttachmentPayload `json:"payload"`
	Thumbnail *VideoThumbnail        `json:"thumbnail,omitempty"`
	Width     *int                   `json:"width,omitempty"`
	Height    *int                   `json:"height,omitempty"`
	Duration  *int                   `json:"duration,omitempty"`
}

VideoAttachment represents a video attachment in a message.

type VideoAttachmentDetails

type VideoAttachmentDetails struct {
	Token     string                  `json:"token"`
	URLs      *VideoURLs              `json:"urls,omitempty"`
	Thumbnail *PhotoAttachmentPayload `json:"thumbnail,omitempty"`
	Width     int                     `json:"width"`
	Height    int                     `json:"height"`
	Duration  int                     `json:"duration"`
}

VideoAttachmentDetails is the response from GET /videos/{videoToken}.

type VideoThumbnail

type VideoThumbnail struct {
	URL string `json:"url"`
}

VideoThumbnail represents a video thumbnail.

type VideoURLs

type VideoURLs struct {
	MP41080 *string `json:"mp4_1080,omitempty"`
	MP4720  *string `json:"mp4_720,omitempty"`
	MP4480  *string `json:"mp4_480,omitempty"`
	MP4360  *string `json:"mp4_360,omitempty"`
	MP4240  *string `json:"mp4_240,omitempty"`
	MP4144  *string `json:"mp4_144,omitempty"`
	HLS     *string `json:"hls,omitempty"`
}

VideoURLs contains video playback URLs in various resolutions.

Jump to

Keyboard shortcuts

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