api

package
v0.0.0-...-e5246f5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IncomingMessage  = "message_new"
	OutcomingMessage = "message_reply"
	JoinGroup        = "group_join"
	LeaveGroup       = "group_leave"
)

Constant values for type of message.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotAPI

type BotAPI struct {
	Token  string `json:"token"`
	Buffer int    `json:"buffer"`

	GroupID      int    `json:"-"`
	Secret       string `json:"-"`
	Confirmation string `json:"-"`

	Client *http.Client `json:"-"`
}

BotAPI contains information for using API.

func NewBot

func NewBot(token string, group int) (*BotAPI, error)

NewBot creates a new BotAPI instance.

func (*BotAPI) ListenForWebhook

func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Packet

ListenForWebhook registers a http handler for a webhook.

func (*BotAPI) Send

func (bot *BotAPI) Send(id int, text ...string) (Response, error)

Send will send message to user through VK.

type Error

type Error struct {
	ErrorCode     int           `json:"error_code"`
	ErrorMsg      string        `json:"error_msg"`
	RequestParams []interface{} `json:"request_params"`
}

Error is type for possibly error.

type Packet

type Packet struct {
	Type    string  `json:"type"`
	Payload Payload `json:"object"`
	GroupID int     `json:"group_id"`
	Secret  string  `json:"secret"`
}

Packet is type for incoming message.

type Payload

type Payload struct {
	ID        int    `json:"id"`
	Date      int64  `json:"date"`
	Out       int    `json:"out"`
	UserID    int    `json:"user_id"`
	ReadState int    `json:"read_state"`
	Title     string `json:"title"`
	Body      string `json:"body"`
	JoinType  int    `json:"join_type"`
	Self      int    `json:"self"`
}

Payload is type for payload of incoming message.

type Response

type Response struct {
	Error    Error `json:"error"`
	Response int   `json:"response"`
}

Response is type for response in Send function.

Jump to

Keyboard shortcuts

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