Documentation ¶
Overview ¶
Package longpoll implements User Long Poll API.
Long polling – this is a technology that allows the receiving of information about new events with the help of "long requests". The server receives the request but it doesn't immediately send the answer but rather when some event will happen (for example, receiving a new incoming message), or waiting period is over.
By using this approach, you can instantly display in your app the most important events. Be aware that with the help of Long Poll, you won't be able to send messages. For this, you’ll need to use the messages.send method.
Initialization ¶
The module can be used with the user access key obtained in the Standalone application via Implicit Flow(access rights required: messages) or with the community access key(access rights required: messages).
vk := api.NewVK("<TOKEN>")
And then longpoll
mode := longpoll.ReceiveAttachments + longpoll.ExtendedEvents lp, err := longpoll.NewLongpoll(vk, mode)
Setting ¶
TODO: write about lp.Ts lp.Wait
The module has the ability to modify the HTTP client
dialer, _ := proxy.SOCKS5("tcp", "127.0.0.1:9050", nil, proxy.Direct) httpTransport := &http.Transport{ Dial: dialer.Dial, // DisableKeepAlives: true, } httpTransport.Dial = dialer.Dial lp.Client.Transport = httpTransport
Wrapper ¶
Wrapper allows you to get ready-made structures ¶
Wrapper for v3 https://pkg.go.dev/github.com/SevereCloud/vksdk/longpoll-user/v3
Run and shutdown ¶
TODO: write about lp.Run() and lp.Shutdown()
VK documentation https://vk.com/dev/using_longpoll
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Longpoll ¶
type Longpoll struct { Key string Server string Ts int Mode Mode Version int Wait int VK *api.VK Client *http.Client // contains filtered or unexported fields }
Longpoll struct.
func NewLongpoll ¶ added in v1.5.0
NewLongpoll returns a new Longpoll.
The Longpoll will use the http.DefaultClient. This means that if the http.DefaultClient is modified by other components of your application the modifications will be picked up by the SDK as well.
func (*Longpoll) FullResponse ¶
func (lp *Longpoll) FullResponse(f func(object.LongpollResponse))
FullResponse handler.
type Mode ¶ added in v1.3.0
type Mode = int
Mode additional answer options.
const ( // receive attachments ReceiveAttachments Mode = 1 << 1 // receive more events ExtendedEvents Mode = 1 << 3 // receive pts (used in messages.getLongPollHistory) ReturnPts Mode = 1 << 5 // extra fields in event type 8(friend become online) Code8ExtraFields Mode = 1 << 6 // return random_id field ReturnRandomID Mode = 1 << 7 )
A list of necessary option codes.