botgolang

package module
v0.0.0-...-4d4de6b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 17 Imported by: 23

README

VK Teams Bot API for Golang

Go codecov go.dev reference

VK Teams API Specification

Getting started

  • Create your own bot by sending the /newbot command to Metabot and follow the instructions.

    Note: a bot can only reply after the user has added it to his contact list, or if the user was the first to start a dialogue.

  • You can configure the domain that hosts your VK Teams server. When instantiating the Bot class, add the address of your domain.
  • An example of how to use the framework can be seen in example/main.go

Install

go get github.com/mail-ru-im/bot-golang

Usage

Create your own bot by sending the /newbot command to Metabot and follow the instructions. Note a bot can only reply after the user has added it to his contacts list, or if the user was the first to start a dialogue.

Create your bot
package main

import "github.com/mail-ru-im/bot-golang"

func main() {
    bot, err := botgolang.NewBot(BOT_TOKEN)
    if err != nil {
        log.Println("wrong token")
    }

    message := bot.NewTextMessage("some@mail.com", "text")
    message.Send()
}
Send and edit messages

You can create, edit and reply to messages like a piece of cake.

message := bot.NewTextMessage("some@mail.com", "text")
message.Send()

message.Text = "new text"

message.Edit()
message.Reply("I changed my text")
Subscribe events

Get all updates from the channel. Use context for cancellation.

ctx, finish := context.WithCancel(context.Background())
updates := bot.GetUpdatesChannel(ctx)
for update := range updates {
	// your logic here
}
Passing options

You don't need this. But if you do, you can override bot's API URL:

bot := botgolang.NewBot(BOT_TOKEN, botgolang.BotApiURL("https://vkteams.com/bot/v1"))

And debug all api requests and responses:

bot := botgolang.NewBot(BOT_TOKEN, botgolang.BotDebug(true))

Documentation

Index

Constants

View Source
const (
	NEW_MESSAGE       EventType = "newMessage"
	EDITED_MESSAGE    EventType = "editedMessage"
	DELETED_MESSAGE   EventType = "deletedMessage"
	PINNED_MESSAGE    EventType = "pinnedMessage"
	UNPINNED_MESSAGE  EventType = "unpinnedMessage"
	NEW_CHAT_MEMBERS  EventType = "newChatMembers"
	LEFT_CHAT_MEMBERS EventType = "leftChatMembers"
	CALLBACK_QUERY    EventType = "callbackQuery"

	STICKER PartType = "sticker"
	MENTION PartType = "mention"
	VOICE   PartType = "voice"
	FILE    PartType = "file"
	FORWARD PartType = "forward"
	REPLY   PartType = "reply"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminsListResponse

type AdminsListResponse struct {
	List []ChatMember `json:"admins"`
}

func (AdminsListResponse) MarshalEasyJSON

func (v AdminsListResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (AdminsListResponse) MarshalJSON

func (v AdminsListResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*AdminsListResponse) UnmarshalEasyJSON

func (v *AdminsListResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*AdminsListResponse) UnmarshalJSON

func (v *AdminsListResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type BaseEventPayload

type BaseEventPayload struct {
	// Id of the message.
	// Presented in newMessage, editedMessage, deletedMessage, pinnedMessage, unpinnedMessage events.
	MsgID string `json:"msgId"`

	// Chat info.
	// Presented in all events.
	Chat Chat `json:"chat"`

	// Author of the message
	// Presented in newMessage and editedMessage events.
	From Contact `json:"from"`

	// Text of the message.
	// Presented in newMessage, editedMessage and pinnedMessage events.
	Text string `json:"text"`

	// Timestamp of the event.
	Timestamp int `json:"timestamp"`
}

func (BaseEventPayload) MarshalEasyJSON

func (v BaseEventPayload) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (BaseEventPayload) MarshalJSON

func (v BaseEventPayload) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*BaseEventPayload) UnmarshalEasyJSON

func (v *BaseEventPayload) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*BaseEventPayload) UnmarshalJSON

func (v *BaseEventPayload) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Bot

type Bot struct {
	Info *BotInfo
	// contains filtered or unexported fields
}

Bot is the main structure for interaction with API. All fields are private, you can configure bot using config arguments in NewBot func.

func NewBot

func NewBot(token string, opts ...BotOption) (*Bot, error)

NewBot returns new bot object. All communications with bot API must go through Bot struct. In general you don't need to configure this bot, therefore all options are optional arguments.

func (*Bot) BlockChatUser

func (b *Bot) BlockChatUser(chatID, userID string, deleteLastMessages bool) error

BlockChatUser blocks user and removes him from chat. If deleteLastMessages is true, the messages written recently will be deleted

func (*Bot) EditMessage

func (b *Bot) EditMessage(message *Message) error

EditMessage edit a message passed as an argument.

func (*Bot) GetChatAdmins

func (b *Bot) GetChatAdmins(chatID string) ([]ChatMember, error)

GetChatAdmins returns chat admins list with fields: userID, creator flag

func (*Bot) GetChatBlockedUsers

func (b *Bot) GetChatBlockedUsers(chatID string) ([]User, error)

GetChatBlockedUsers returns chat blocked users list: userID

func (*Bot) GetChatInfo

func (b *Bot) GetChatInfo(chatID string) (*Chat, error)

GetChatInfo returns information about chat: id, type, title, public, group, inviteLink, admins

func (*Bot) GetChatMembers

func (b *Bot) GetChatMembers(chatID string) ([]ChatMember, error)

GetChatMem returns chat members list with fields: userID, creator flag, admin flag

func (*Bot) GetChatPendingUsers

func (b *Bot) GetChatPendingUsers(chatID string) ([]User, error)

GetChatPendingUsers returns chat join pending users list: userID

func (*Bot) GetFileInfo

func (b *Bot) GetFileInfo(fileID string) (*File, error)

GetFileInfo returns information about file: id, type, size, filename, url

func (*Bot) GetInfo

func (b *Bot) GetInfo() (*BotInfo, error)

GetInfo returns information about bot: id, name, about, avatar

func (*Bot) GetUpdatesChannel

func (b *Bot) GetUpdatesChannel(ctx context.Context) <-chan Event

GetUpdatesChannel returns a channel, which will be filled with events. You can pass cancellable context there and stop receiving events. The channel will be closed after context cancellation.

func (*Bot) NewButtonResponse

func (b *Bot) NewButtonResponse(queryID, url, text string, showAlert bool) *ButtonResponse

NewButtonResponse returns new ButtonResponse

func (*Bot) NewChat

func (b *Bot) NewChat(id string) *Chat

func (*Bot) NewDeeplinkMessage

func (b *Bot) NewDeeplinkMessage(chatID, text string, keyboard Keyboard, deeplink string) *Message

NewDeeplinkMessage returns new text message with inline keyboard and deeplink

func (*Bot) NewFileMessage

func (b *Bot) NewFileMessage(chatID string, file *os.File) *Message

NewFileMessage returns new file message

func (*Bot) NewFileMessageByFileID

func (b *Bot) NewFileMessageByFileID(chatID, fileID string) *Message

NewFileMessageByFileID returns new message with previously uploaded file id

func (*Bot) NewInlineKeyboardMessage

func (b *Bot) NewInlineKeyboardMessage(chatID, text string, keyboard Keyboard) *Message

NewInlineKeyboardMessage returns new text message with inline keyboard

func (*Bot) NewMessage

func (b *Bot) NewMessage(chatID string) *Message

NewMessage returns new message

func (*Bot) NewMessageFromPart

func (b *Bot) NewMessageFromPart(message PartMessage) *Message

NewMessageFromPart returns new message based on part message

func (*Bot) NewTextMessage

func (b *Bot) NewTextMessage(chatID, text string) *Message

NewTextMessage returns new text message

func (*Bot) NewTextMessageWithRequestID

func (b *Bot) NewTextMessageWithRequestID(chatID, text, requestID string) *Message

NewTextMessageWithRequestID returns new text message with client requestID

func (*Bot) NewVoiceMessage

func (b *Bot) NewVoiceMessage(chatID string, file *os.File) *Message

NewVoiceMessage returns new voice message

func (*Bot) NewVoiceMessageByFileID

func (b *Bot) NewVoiceMessageByFileID(chatID, fileID string) *Message

NewVoiceMessageByFileID returns new message with previously uploaded voice file id

func (*Bot) ResolveChatJoinRequests

func (b *Bot) ResolveChatJoinRequests(chatID, userID string, accept, everyone bool) error

ResolveChatJoinRequests sends a decision to accept/decline user join to chat

func (*Bot) SendChatActions

func (b *Bot) SendChatActions(chatID string, actions ...ChatAction) error

SendChatActions sends an actions like "typing, looking"

func (*Bot) SendMessage

func (b *Bot) SendMessage(message *Message) error

SendMessage sends a message, passed as an argument. This method fills the argument with ID of sent message and returns an error if any.

func (*Bot) SetChatAbout

func (b *Bot) SetChatAbout(chatID, about string) error

SetChatAbout changes chat about

func (*Bot) SetChatRules

func (b *Bot) SetChatRules(chatID, rules string) error

SetChatRules changes chat rules

func (*Bot) SetChatTitle

func (b *Bot) SetChatTitle(chatID, title string) error

SetChatTitle changes chat title

func (*Bot) UnblockChatUser

func (b *Bot) UnblockChatUser(chatID, userID string) error

UnblockChatUser unblocks user in chat

type BotApiURL

type BotApiURL string

func (BotApiURL) Type

func (o BotApiURL) Type() string

func (BotApiURL) Value

func (o BotApiURL) Value() interface{}

type BotDebug

type BotDebug bool

func (BotDebug) Type

func (o BotDebug) Type() string

func (BotDebug) Value

func (o BotDebug) Value() interface{}

type BotHTTPClient

type BotHTTPClient http.Client

func (BotHTTPClient) Type

func (o BotHTTPClient) Type() string

func (BotHTTPClient) Value

func (o BotHTTPClient) Value() interface{}

type BotInfo

type BotInfo struct {
	User

	// Nickname of the bot
	Nick string `json:"nick"`

	// Name of the bot
	FirstName string `json:"firstName"`

	// Information about the box
	About string `json:"about"`

	// A slice of avatars
	Photo []Photo `json:"photo"`
}

func (BotInfo) MarshalEasyJSON

func (v BotInfo) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (BotInfo) MarshalJSON

func (v BotInfo) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*BotInfo) UnmarshalEasyJSON

func (v *BotInfo) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*BotInfo) UnmarshalJSON

func (v *BotInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type BotOption

type BotOption interface {
	Type() string
	Value() interface{}
}

type Button

type Button struct {
	// Button text
	Text string `json:"text"`

	// URL to be opened
	// You can't use it with CallbackData
	URL string `json:"url,omitempty"`

	// Data that identify the button
	// You can't use it with URL
	CallbackData string `json:"callbackData,omitempty"`

	// Style of a button
	Style ButtonStyle `json:"style,omitempty"`
}

Button represents a button in inline keyboard Make sure you have URL or CallbackData in your Button.

func NewCallbackButton

func NewCallbackButton(text string, callbackData string) Button

NewCallbackButton returns new button with CallbackData field

func NewURLButton

func NewURLButton(text string, url string) Button

NewURLButton returns new button with URL field

func (Button) MarshalEasyJSON

func (v Button) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Button) MarshalJSON

func (v Button) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Button) UnmarshalEasyJSON

func (v *Button) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Button) UnmarshalJSON

func (v *Button) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

func (Button) WithStyle

func (v Button) WithStyle(style ButtonStyle) Button

WithStyle sets ButtonStyle for Button

type ButtonResponse

type ButtonResponse struct {

	// Id of the query
	QueryID string `json:"queryId"`

	// Text of the response message
	Text string `json:"text"`

	// Display alert?
	ShowAlert bool `json:"showAlert"`

	// URL to be opened
	URL string `json:"url"`

	// CallbackData of the query (id of the pressed button).
	CallbackData string `json:"callbackData"`
	// contains filtered or unexported fields
}

ButtonResponse represents a data that is returned when a button is clicked

func (ButtonResponse) MarshalEasyJSON

func (v ButtonResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ButtonResponse) MarshalJSON

func (v ButtonResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ButtonResponse) Send

func (cl *ButtonResponse) Send() error

Send method sends your response message. Make sure you have QueryID in your ButtonResponse.

func (*ButtonResponse) UnmarshalEasyJSON

func (v *ButtonResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ButtonResponse) UnmarshalJSON

func (v *ButtonResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ButtonStyle

type ButtonStyle string

ButtonStyle represent a style of a Button

const (
	ButtonPrimary   ButtonStyle = "primary"
	ButtonAttention ButtonStyle = "attention"
)

type Chat

type Chat struct {

	// Id of the chat
	ID string `json:"chatId"`

	// Type of the chat: channel, group or private
	Type ChatType `json:"type"`

	// First name of the user
	FirstName string `json:"firstName"`

	// Last name of the user
	LastName string `json:"lastName"`

	// Nick of the user
	Nick string `json:"nick"`

	// User about or group/channel description
	About string `json:"about"`

	// Rules of the group/channel
	Rules string `json:"rules"`

	// Title of the chat
	Title string `json:"title"`

	// Flag that indicates that requested chat is the bot
	IsBot bool `json:"isBot"`

	// Is this chat public?
	Public bool `json:"public"`

	// Is this chat has join moderation?
	JoinModeration bool `json:"joinModeration"`

	// You can send this link to all your friends
	InviteLink string `json:"inviteLink"`
	// contains filtered or unexported fields
}

func (*Chat) BlockUser

func (c *Chat) BlockUser(userID string, deleteLastMessages bool) error

Block user and remove him from chat. If deleteLastMessages is true, the messages written recently will be deleted

func (*Chat) GetAdmins

func (c *Chat) GetAdmins() ([]ChatMember, error)

Get chat administrators list

func (*Chat) GetBlockedUsers

func (c *Chat) GetBlockedUsers() ([]User, error)

Get chat blocked users list

func (*Chat) GetMembers

func (c *Chat) GetMembers() ([]ChatMember, error)

Get chat members list

func (*Chat) GetPendingUsers

func (c *Chat) GetPendingUsers() ([]User, error)

Get chat join pending users list

func (Chat) MarshalEasyJSON

func (v Chat) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Chat) MarshalJSON

func (v Chat) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Chat) ResolveAllJoinRequests

func (c *Chat) ResolveAllJoinRequests(accept bool) error

ResolveAllJoinRequest resolve all chat join requests

func (*Chat) ResolveJoinRequest

func (c *Chat) ResolveJoinRequest(userID string, accept bool) error

ResolveJoinRequest resolve specific user chat join request

func (*Chat) SendActions

func (c *Chat) SendActions(actions ...ChatAction) error

Send bot actions to the chat

You can call this method every time you change the current actions, or every 10 seconds if the actions have not changed. After sending a request without active action, you should not re-notify of their absence.

func (*Chat) SetAbout

func (c *Chat) SetAbout(about string) error

SetAbout changes chat about

func (*Chat) SetRules

func (c *Chat) SetRules(rules string) error

SetRules changes chat rules

func (*Chat) SetTitle

func (c *Chat) SetTitle(title string) error

SetTitle changes chat title

func (*Chat) UnblockUser

func (c *Chat) UnblockUser(userID string) error

Unblock user in chat (but not add him back)

func (*Chat) UnmarshalEasyJSON

func (v *Chat) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Chat) UnmarshalJSON

func (v *Chat) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ChatAction

type ChatAction = string
const (
	TypingAction  ChatAction = "typing"
	LookingAction ChatAction = "looking"
)

type ChatMember

type ChatMember struct {
	User
	Creator bool `json:"creator"`
	Admin   bool `json:"admin"`
}

func (ChatMember) MarshalEasyJSON

func (v ChatMember) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ChatMember) MarshalJSON

func (v ChatMember) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ChatMember) UnmarshalEasyJSON

func (v *ChatMember) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ChatMember) UnmarshalJSON

func (v *ChatMember) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ChatType

type ChatType = string
const (
	Private ChatType = "private"
	Group   ChatType = "group"
	Channel ChatType = "channel"
)

type Client

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

func NewClient

func NewClient(baseURL string, token string, logger *logrus.Logger) *Client

func NewCustomClient

func NewCustomClient(client *http.Client, baseURL string, token string, logger *logrus.Logger) *Client

func (*Client) BlockChatUser

func (c *Client) BlockChatUser(chatID, userID string, deleteLastMessages bool) error

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(message *Message) error

func (*Client) Do

func (c *Client) Do(path string, params url.Values, file *os.File) ([]byte, error)

func (*Client) DoWithContext

func (c *Client) DoWithContext(ctx context.Context, path string, params url.Values, file *os.File) ([]byte, error)

func (*Client) EditMessage

func (c *Client) EditMessage(message *Message) error

func (*Client) GetChatAdmins

func (c *Client) GetChatAdmins(chatID string) ([]ChatMember, error)

func (*Client) GetChatBlockedUsers

func (c *Client) GetChatBlockedUsers(chatID string) ([]User, error)

func (*Client) GetChatInfo

func (c *Client) GetChatInfo(chatID string) (*Chat, error)

func (*Client) GetChatMembers

func (c *Client) GetChatMembers(chatID string) ([]ChatMember, error)

func (*Client) GetChatPendingUsers

func (c *Client) GetChatPendingUsers(chatID string) ([]User, error)

func (*Client) GetEvents

func (c *Client) GetEvents(lastEventID int, pollTime int) ([]*Event, error)

func (*Client) GetEventsWithContext

func (c *Client) GetEventsWithContext(ctx context.Context, lastEventID int, pollTime int) ([]*Event, error)

func (*Client) GetFileInfo

func (c *Client) GetFileInfo(fileID string) (*File, error)

func (*Client) GetInfo

func (c *Client) GetInfo() (*BotInfo, error)

func (*Client) GetVoiceInfo

func (c *Client) GetVoiceInfo(fileID string) (*File, error)

func (*Client) PinMessage

func (c *Client) PinMessage(message *Message) error

func (*Client) ResolveChatPending

func (c *Client) ResolveChatPending(chatID, userID string, approve, everyone bool) error

func (*Client) SendAnswerCallbackQuery

func (c *Client) SendAnswerCallbackQuery(answer *ButtonResponse) error

func (*Client) SendChatActions

func (c *Client) SendChatActions(chatID string, actions ...ChatAction) error

func (*Client) SendFileMessage

func (c *Client) SendFileMessage(message *Message) error

func (*Client) SendTextMessage

func (c *Client) SendTextMessage(message *Message) error

func (*Client) SendTextWithDeeplinkMessage

func (c *Client) SendTextWithDeeplinkMessage(message *Message) error

func (*Client) SendVoiceMessage

func (c *Client) SendVoiceMessage(message *Message) error

func (*Client) SetChatAbout

func (c *Client) SetChatAbout(chatID, about string) error

func (*Client) SetChatRules

func (c *Client) SetChatRules(chatID, rules string) error

func (*Client) SetChatTitle

func (c *Client) SetChatTitle(chatID, title string) error

func (*Client) UnblockChatUser

func (c *Client) UnblockChatUser(chatID, userID string) error

func (*Client) UnpinMessage

func (c *Client) UnpinMessage(message *Message) error

func (*Client) UploadFile

func (c *Client) UploadFile(message *Message) error

func (*Client) UploadVoice

func (c *Client) UploadVoice(message *Message) error

type Contact

type Contact struct {
	User
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
}

func (Contact) MarshalEasyJSON

func (v Contact) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Contact) MarshalJSON

func (v Contact) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Contact) UnmarshalEasyJSON

func (v *Contact) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Contact) UnmarshalJSON

func (v *Contact) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Event

type Event struct {

	// Id of the event
	EventID int `json:"eventId"`

	// Type of the event: newMessage, editedMessage, deletedMessage, pinnedMessage, unpinnedMessage, newChatMembers
	Type EventType `json:"type"`

	// Payload of the event
	Payload EventPayload `json:"payload"`
	// contains filtered or unexported fields
}

func (Event) MarshalEasyJSON

func (v Event) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Event) MarshalJSON

func (v Event) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Event) UnmarshalEasyJSON

func (v *Event) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Event) UnmarshalJSON

func (v *Event) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type EventPayload

type EventPayload struct {
	BaseEventPayload

	// Parts of the message.
	// Presented only in newMessage event.
	Parts []Part `json:"parts"`

	// Id of the query.
	// Presented only in callbackQuery event.
	QueryID string `json:"queryId"`

	// Callback message of the query (parent message for button).
	// Presented only in callbackQuery event.
	CallbackMsg BaseEventPayload `json:"message"`

	// CallbackData of the query (id of button).
	// Presented only in callbackQuery event.
	CallbackData string `json:"callbackData"`

	LeftMembers []Contact `json:"leftMembers"`

	NewMembers []Contact `json:"newMembers"`

	AddedBy Contact `json:"addedBy"`

	RemovedBy Contact `json:"removedBy"`
	// contains filtered or unexported fields
}

func (*EventPayload) CallbackMessage

func (ep *EventPayload) CallbackMessage() *Message

func (*EventPayload) CallbackQuery

func (ep *EventPayload) CallbackQuery() *ButtonResponse

func (EventPayload) MarshalEasyJSON

func (v EventPayload) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (EventPayload) MarshalJSON

func (v EventPayload) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*EventPayload) Message

func (ep *EventPayload) Message() *Message

func (*EventPayload) UnmarshalEasyJSON

func (v *EventPayload) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*EventPayload) UnmarshalJSON

func (v *EventPayload) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type EventType

type EventType string

type File

type File struct {
	// Id of the file
	ID string `json:"fileId"`

	// Type of the file
	Type string `json:"type"`

	// Size in bytes
	Size uint64 `json:"size"`

	// Name of file
	Name string `json:"filename"`

	// URL to the file
	URL string `json:"url"`
}

func (File) MarshalEasyJSON

func (v File) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (File) MarshalJSON

func (v File) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*File) UnmarshalEasyJSON

func (v *File) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*File) UnmarshalJSON

func (v *File) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Keyboard

type Keyboard struct {
	Rows [][]Button
}

Keyboard represents an inline keyboard markup Call the NewKeyboard() func to get a keyboard instance

func NewKeyboard

func NewKeyboard() Keyboard

NewKeyboard returns a new keyboard instance

func (*Keyboard) AddButton

func (k *Keyboard) AddButton(rowIndex int, button Button) error

AddButton adds a button to the end of the row

func (*Keyboard) AddRow

func (k *Keyboard) AddRow(row ...Button)

AddRows adds a row to the keyboard

func (*Keyboard) ChangeButton

func (k *Keyboard) ChangeButton(rowIndex, buttonIndex int, newButton Button) error

ChangeButton changes the button to a new one at the specified position

func (*Keyboard) DeleteButton

func (k *Keyboard) DeleteButton(rowIndex, buttonIndex int) error

DeleteButton removes the button from the row. Note - at least one button should remain in a row, if you want to delete all buttons, use the DeleteRow function

func (*Keyboard) DeleteRow

func (k *Keyboard) DeleteRow(index int) error

DeleteRow removes the row from the keyboard

func (*Keyboard) GetKeyboard

func (k *Keyboard) GetKeyboard() [][]Button

GetKeyboard returns an array of button rows

func (*Keyboard) RowSize

func (k *Keyboard) RowSize(row int) int

RowSize returns the number of buttons in a row. If there is no such row, then returns -1

func (*Keyboard) RowsCount

func (k *Keyboard) RowsCount() int

RowsCount returns the number of rows

func (*Keyboard) SwapRows

func (k *Keyboard) SwapRows(first, second int) error

SwapRows swaps two rows in keyboard

type MembersListResponse

type MembersListResponse struct {
	// TODO: cursor
	List []ChatMember `json:"members"`
}

func (MembersListResponse) MarshalEasyJSON

func (v MembersListResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (MembersListResponse) MarshalJSON

func (v MembersListResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*MembersListResponse) UnmarshalEasyJSON

func (v *MembersListResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*MembersListResponse) UnmarshalJSON

func (v *MembersListResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Message

type Message struct {
	ContentType MessageContentType

	// Id of the message (for editing)
	ID string `json:"msgId"`

	// File contains file attachment of the message
	File *os.File `json:"-"`

	// Id of file to send
	FileID string `json:"fileId"`

	// Text of the message or caption for file
	Text string `json:"text"`

	// Chat where to send the message
	Chat Chat `json:"chat"`

	// Id of replied message
	// You can't use it with ForwardMsgID or ForwardChatID
	ReplyMsgID string `json:"replyMsgId"`

	// Id of forwarded message
	// You can't use it with ReplyMsgID
	ForwardMsgID string `json:"forwardMsgId"`

	// Id of a chat from which you forward the message
	// You can't use it with ReplyMsgID
	// You should use it with ForwardMsgID
	ForwardChatID string `json:"forwardChatId"`

	Timestamp int `json:"timestamp"`

	// The markup for the inline keyboard
	InlineKeyboard *Keyboard `json:"inlineKeyboardMarkup"`

	// The parse mode (HTML/MarkdownV2)
	ParseMode ParseMode `json:"parseMode"`

	// RequestID from library clients that is used in my-team logs
	RequestID string `json:"requestID"`

	// Use it only with content type Deeplink
	Deeplink string `json:"deeplink"`
	// contains filtered or unexported fields
}

Message represents a text message

func (*Message) AppendParseMode

func (m *Message) AppendParseMode(mode ParseMode)

AppendParseMode append a type of text formatting for current message

func (*Message) AttachExistingFile

func (m *Message) AttachExistingFile(fileID string)

func (*Message) AttachExistingVoice

func (m *Message) AttachExistingVoice(fileID string)

func (*Message) AttachInlineKeyboard

func (m *Message) AttachInlineKeyboard(keyboard Keyboard)

AttachInlineKeyboard adds a keyboard to the message. Note - at least one row should be in the keyboard and there should be no empty rows

func (*Message) AttachNewFile

func (m *Message) AttachNewFile(file *os.File)

func (*Message) AttachNewVoice

func (m *Message) AttachNewVoice(file *os.File)

func (*Message) Delete

func (m *Message) Delete() error

Delete method deletes your message. Make sure you have ID in your message.

func (*Message) Edit

func (m *Message) Edit() error

Edit method edits your message. Make sure you have ID in your message.

func (*Message) Forward

func (m *Message) Forward(chatID string) error

Forward method forwards your message to chat. Make sure you have ID in your message.

func (Message) MarshalEasyJSON

func (v Message) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Message) MarshalJSON

func (v Message) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Message) Pin

func (m *Message) Pin() error

Pin message in chat Make sure you are admin in this chat

func (*Message) Reply

func (m *Message) Reply(text string) error

Reply method replies to the message. Make sure you have ID in the message.

func (*Message) Send

func (m *Message) Send() error

Send method sends your message. Make sure you have Text or FileID in your message.

func (*Message) UnmarshalEasyJSON

func (v *Message) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Message) UnmarshalJSON

func (v *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

func (*Message) Unpin

func (m *Message) Unpin() error

Unpin message in chat Make sure you are admin in this chat

type MessageContentType

type MessageContentType uint8
const (
	Unknown MessageContentType = iota
	Text
	OtherFile
	Voice
	Deeplink
)

type MockHandler

type MockHandler struct {
	http.Handler
	// contains filtered or unexported fields
}

func (*MockHandler) GetEvents

func (h *MockHandler) GetEvents(w http.ResponseWriter)

func (*MockHandler) SelfGet

func (h *MockHandler) SelfGet(w http.ResponseWriter, r *http.Request)

func (*MockHandler) SendMessage

func (h *MockHandler) SendMessage(w http.ResponseWriter)

func (*MockHandler) ServeHTTP

func (h *MockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MockHandler) TokenError

func (h *MockHandler) TokenError(w http.ResponseWriter)

type ParseMode

type ParseMode string

ParseMode represent a type of text formatting

const (
	ParseModeHTML       ParseMode = "HTML"
	ParseModeMarkdownV2 ParseMode = "MarkdownV2"
)

type Part

type Part struct {
	// Type of the part
	Type PartType `json:"type"`

	// Payload of the part
	Payload PartPayload `json:"payload"`
}

func (Part) MarshalEasyJSON

func (v Part) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Part) MarshalJSON

func (v Part) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Part) UnmarshalEasyJSON

func (v *Part) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Part) UnmarshalJSON

func (v *Part) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type PartMessage

type PartMessage struct {
	From      Contact `json:"from"`
	MsgID     string  `json:"msgId"`
	Text      string  `json:"text"`
	Timestamp int     `json:"timestamp"`
}

func (PartMessage) MarshalEasyJSON

func (v PartMessage) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (PartMessage) MarshalJSON

func (v PartMessage) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*PartMessage) UnmarshalEasyJSON

func (v *PartMessage) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*PartMessage) UnmarshalJSON

func (v *PartMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type PartPayload

type PartPayload struct {
	FirstName   string      `json:"firstName"`
	LastName    string      `json:"lastName"`
	UserID      string      `json:"userId"`
	FileID      string      `json:"fileId"`
	Caption     string      `json:"caption"`
	Type        string      `json:"type"`
	PartMessage PartMessage `json:"message"`
	Message     PartMessage `json:"-"`
}

func (PartPayload) MarshalEasyJSON

func (v PartPayload) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (PartPayload) MarshalJSON

func (v PartPayload) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*PartPayload) UnmarshalEasyJSON

func (v *PartPayload) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*PartPayload) UnmarshalJSON

func (v *PartPayload) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type PartType

type PartType string

type Photo

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

func (Photo) MarshalEasyJSON

func (v Photo) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Photo) MarshalJSON

func (v Photo) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Photo) UnmarshalEasyJSON

func (v *Photo) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Photo) UnmarshalJSON

func (v *Photo) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Response

type Response struct {
	OK          bool   `json:"ok"`
	Description string `json:"description,omitempty"`
}

func (Response) MarshalEasyJSON

func (v Response) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Response) MarshalJSON

func (v Response) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Response) UnmarshalEasyJSON

func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Response) UnmarshalJSON

func (v *Response) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Updater

type Updater struct {
	PollTime int
	// contains filtered or unexported fields
}

func NewUpdater

func NewUpdater(client *Client, pollTime int, logger *logrus.Logger) *Updater

func (*Updater) GetLastEvents

func (u *Updater) GetLastEvents(pollTime int) ([]*Event, error)

func (*Updater) GetLastEventsWithContext

func (u *Updater) GetLastEventsWithContext(ctx context.Context, pollTime int) ([]*Event, error)

func (*Updater) NewMessageFromPayload

func (u *Updater) NewMessageFromPayload(message EventPayload) *Message

NewMessageFromPart returns new message based on part message

func (*Updater) RunUpdatesCheck

func (u *Updater) RunUpdatesCheck(ctx context.Context, ch chan<- Event)

type User

type User struct {
	ID string `json:"userId"`
}

func (User) MarshalEasyJSON

func (v User) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (User) MarshalJSON

func (v User) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*User) UnmarshalEasyJSON

func (v *User) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*User) UnmarshalJSON

func (v *User) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type UsersListResponse

type UsersListResponse struct {
	List []User `json:"users"`
}

func (UsersListResponse) MarshalEasyJSON

func (v UsersListResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (UsersListResponse) MarshalJSON

func (v UsersListResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*UsersListResponse) UnmarshalEasyJSON

func (v *UsersListResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*UsersListResponse) UnmarshalJSON

func (v *UsersListResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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