vk

package module
v0.0.0-...-12f8348 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2017 License: MIT Imports: 7 Imported by: 0

README

go-vk-api

GoDoc Go Report Card

Golang wrapper for VK API

Install

Install the package with:

go get github.com/urShadow/go-vk-api

Import it with:

import "github.com/urShadow/go-vk-api"

and use vk as the package name inside the code.

Example

package main

import (
	"github.com/urShadow/go-vk-api"
	"log"
	"strconv"
)

func main() {
	api := vk.New("ru")
	// set http proxy
	//api.Proxy = "localhost:8080"

	err := api.Init("TOKEN")

	if err != nil {
		log.Fatalln(err)
	}

	api.OnNewMessage(func(msg *vk.LPMessage) {
		if msg.Flags&vk.FlagMessageOutBox == 0 {
			if msg.Text == "/hello" {
				api.Messages.Send(vk.RequestParams{
					"peer_id":          strconv.FormatInt(msg.FromID, 10),
					"message":          "Hello!",
					"forward_messages": strconv.FormatInt(msg.ID, 10),
				})
			}
		}
	})

	api.RunLongPoll()
}

Documentation

Index

Constants

View Source
const (
	FlagMessageUnread = 1 << iota
	FlagMessageOutBox
	FlagMessageReplied
	FlagMessageImportant
	FlagMessageChat
	FlagMessageFriends
	FlagMessageSpam
	FlagMessageDeleted
	FlagMessageFixed
	FlagMessageMedia
)

Message's flags

Variables

This section is empty.

Functions

This section is empty.

Types

type EventNewMessage

type EventNewMessage func(*LPMessage)

EventNewMessage delegate

type LPMessage

type LPMessage struct {
	ID, Flags, FromID, Timestamp int64
	Subject, Text                string
	Attachments                  map[string]string
}

LPMessage struct

type Messages

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

Messages https://new.vk.com/dev/messages

func (*Messages) Send

func (messages *Messages) Send(params RequestParams) (int64, error)

Send https://new.vk.com/dev/messages.send

type RequestParams

type RequestParams map[string]string

RequestParams struct

type VK

type VK struct {
	Messages *Messages

	Proxy string
	// contains filtered or unexported fields
}

VK struct

func New

func New(lang string) *VK

New returns a new VK instance

func (*VK) CallMethod

func (client *VK) CallMethod(method string, params RequestParams) ([]byte, error)

CallMethod calls VK API method

func (*VK) Init

func (client *VK) Init(token string) error

Init sets the token

func (*VK) Log

func (client *VK) Log(a ...interface{})

Log writes data in stdout and logfile

func (*VK) OnNewMessage

func (client *VK) OnNewMessage(event EventNewMessage)

OnNewMessage sets event

func (*VK) RunLongPoll

func (client *VK) RunLongPoll()

RunLongPoll starts longpoll process

func (*VK) SetLogFile

func (client *VK) SetLogFile(logFile *os.File)

SetLogFile sets pointer to logfile

Jump to

Keyboard shortcuts

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