Work with Vkontakte API for StandAlone application on The Go Programming Language.
go get -u github.com/Dimonchik0036/vk-api
Displays incoming messages. If this is a "/start", then a "Hello!" message will be sent.
package main
import (
"github.com/dimonchik0036/vk-api"
"log"
)
func main() {
//client, err := vkapi.NewClientFromLogin("<username>", "<password>", vkapi.ScopeMessages)
client, err := vkapi.NewClientFromToken("<access_token>")
if err != nil {
log.Panic(err)
}
client.Log(true)
if err := client.InitLongPoll(0, 2); err != nil {
log.Panic(err)
}
updates, _, err := client.GetLPUpdatesChan(100, vkapi.LPConfig{25, vkapi.LPModeAttachments})
if err != nil {
log.Panic(err)
}
for update := range updates {
if update.Message == nil || !update.IsNewMessage() || update.Message.Outbox(){
continue
}
log.Printf("%s", update.Message.String())
if update.Message.Text == "/start" {
client.SendMessage(vkapi.NewMessage(vkapi.NewDstFromUserID(update.Message.FromID), "Hello!"))
}
}
}
- API version 5.67.