npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lib-vk

v2.0.4

Published

Compact SDK with VK API for Node.js

Downloads

38

Readme

lib-vk

Features

  • Quickly
  • Compact
  • Support for both callback and long polling at the same time

NPM

npm i lib-vk

Example usage

/** process.env.TOKEN — group or page token
* process.env.GROUPID — group id (if the page token does not need to be specified)
* process.env.SECRET — secret key for working with callback
* process.env.PATH — path for receiving callback events
*/
const vk = new (require('lib-vk').VK)(
  { 
    longPoll: {
      token: process.env.TOKEN,
      groupId: process.env.GROUPID
    },
    callback: {
      secret: process.env.SECRET,
      path: process.env.PATH
    }
  }
)

/** In the event location, you can specify an array of events that will be intercepted (For pages)
*    Example: ['messageNew', 'messageEdit']
*/ 
vk.track('messageNew', message => 
  message.text == 'test' &&
  vk.reply(message, 'This is a reply message') &&
  vk.send(message, 'This is a normal message'))

Calling methods

const getUser = await vk.Query('users.get', {user_id: 1});

// Calling multiple methods at once
const response = await vk.parallelExecute([[ 
  [
    ['messages.send', {chat_id: 1, random_id: 0, message: 'send 1'}],
    ['messages.send', {chat_id: 2, random_id: 0, message: 'send 2'}],
    ['users.get', {user_ids: [1, 2, 3]}]
  ]
]])

Implementation of the «kick» command on «parallelExecute» (Instant execution)

if(message.text === '!kick') {
  if(!vk.hasReply(message)) return vk.reply(message, 'Нужно ответить на сообщение кого исключить');

  return vk.parallelExecute([
    [
      [['messages.removeChatUser', {member_id: message.reply_message.from_id, chat_id: message.peer_id - 2e9}],
      ['users.get', {user_ids: message.reply_message.from_id}]],
        `messages.send({random_id: 0, message: !this[0] 
          ? ("Не могу исключить ${message.reply_message.from_id > 0 ? '@id" + this[1][0].id + " (этого пользователя)"' 
            : `@club${-message.reply_message.from_id} (это сообщество)"`}) 
              : (" ${message.reply_message.from_id > 0 ? ' @id" + this[1][0].id + "(" + this[1][0].first_name + ") исключён"' 
                : ` Исключил @club${-message.reply_message.from_id} (это сообщество)"`}),
     chat_id: ${message.peer_id - 2e9}})`
     ]
  ])
}

The name of all events and their structure for pages

Adding a new message

* messageNew 
{
    'type' {string}
    'id' {integer}
    'minorId' {integer}
    'peerId' {integer}
    'date' {integer}
    'text' {string}
}
  • Edit the message
* messageEdit 
{
    'type' {string}
    'id' {integer}
    'minorId' {integer}
    'peerId' {integer}
    'date' {integer}
    'text' {string}
}
  • Reading all outgoing messages in $peerId that arrived before the message with $localId
* readingAllOutMessages 
{
    'type' {string}
    'peerId' {integer}
    'localId' {integer}
}
  • A friend of $userId has become online. The extra contains the platform ID
  • $timestamp — the time of the last action of the user $userId on the site
* userOnline 
{
    'type' {string}
    'userId' {integer}
    'extra' {integer}
    'timestamp' {integer}
}
  • Friend $userId has become offline ($flags is 0 if the user has left the site and 1 if offline by timeout)
  • $timestamp — the time of the last action of the user $userId on the site
* userOffline 
{
    'type' {sting}
    'userId' {integer}
    'flags' {integer}
    'timestamp' {integer}
}
  • Changing the chat information $peer_id with the type $type_id, $info - additional information about the changes, depends on the type of event
* changingChatInfo
{
    'type' {string}
    'typeEventIsChat' {string}
    'peerId' {integer}
    'infoType' {string OR integer}
}
  • The user $userId is typing text in the dialog
  • The event comes once every ~5 seconds when typing. $flags = 1
* messageTyping 
{
    'type' {string}
    'userId' {integer}
    'flags' {integer}
}
  • The user $userId types text in the conversation $chatId
* messageTypingIsChat 
{
    'type' {string}
    'userId' {integer}
    'chatId' {integer}
}
  • Users $userIds type text in the conversation $peerId
  • A maximum of five conversation participants are transmitted, the total number of printers is indicated in $totalCount
  • $ts is the time when this event was generated
* messageTypingsIsChat 
{
    'type' {string}
    'userIds' {integer}
    'peerId' {integer}
    'totalCount' {integer}
    'ts' {integer}
}
  • Users $userIds record an audio message in the conversation $peerId
* recordsAudiomessage 
{
    'type' {string}
    'userIds' {integer}
    'peerId' {integer}
    'totalCount' {integer}
    'ts' {integer}
}

Если вам есть что предложить прошу написать мне VK