Golang wrapper for VK API
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.
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()
}