Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

aprosvetova/go-vkstream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang bindings for the VK Streaming API

GoDoc

I'm very new to Go, so I'll be happy if you make some Pull Requests and help me with tests.

Read the VK Streaming API description and docs to understand how it works.

Warning! Please note that VK will send you only 1% of events that match your rules. You need to ask the support for the full access to get all the events.

Example

package main

import (
	"github.com/aprosvetova/go-vkstream"
	"log"
	"time"
)

func main() {
	stream, err := vkstream.NewStreamWithToken("your_token")
	if err != nil {
		log.Fatal(err)
		return
	}
	stream.AddRule("golang -rust", "1") //will listen for all posts/comments containing "golang" and NOT containing "rust", hehe. Read VK docs for detailed rules syntax
	events, err := stream.Listen()
	if err != nil {
		log.Fatal(err)
		return
	}
	log.Print("Started listening")
	go func() {
		for event := range events {
			log.Print(event.URL) //will just print the url of the post/comment/etc
		}
	}()
	time.AfterFunc(time.Minute, func() {
		stream.Stop()
		log.Print("Stopped listening")
	}) //stop listening after a minute just to demonstrate how Stop works
	for {
		select {}
	}
}

Contact me

If you have any questions about my shitty code, feel free to contact me by Telegram (@koteeq). I speak English and Russian.

Releases

No releases published

Packages

No packages published

Languages