node-vk-bot-api
Advanced tools
Comparing version 2.1.7 to 2.1.8
@@ -18,5 +18,6 @@ const methods = require('./methods') | ||
this.methods = [] | ||
this.settings = typeof settings === 'object' | ||
? settings | ||
: { token: settings } | ||
this.settings = Object.assign({}, { | ||
polling_timeout: 25, | ||
execute_timeout: 50, | ||
}, typeof settings === 'object' ? settings : { token: settings }) | ||
@@ -57,4 +58,4 @@ Object.entries({ ...methods, api, callExecute }).forEach(([key, method]) => { | ||
startPolling(timeout) { | ||
return this.startPolling(timeout) | ||
startPolling(callback) { | ||
return this.startPolling(callback) | ||
} | ||
@@ -61,0 +62,0 @@ } |
const axios = require('axios') | ||
const Context = require('../context') | ||
module.exports = async function (timeout = 25, ts) { | ||
module.exports = async function (callback, ts) { | ||
try { | ||
@@ -10,2 +10,6 @@ if (!this.longPollParams) { | ||
if (callback) { | ||
callback() | ||
} | ||
const { data: body } = await axios.get(this.longPollParams.server, { | ||
@@ -16,3 +20,3 @@ params: { | ||
act: 'a_check', | ||
wait: timeout, | ||
wait: this.settings.polling_timeout, | ||
}, | ||
@@ -24,7 +28,7 @@ }) | ||
case 1: | ||
return this.startPolling(timeout, body.ts) | ||
return this.startPolling(null, body.ts) | ||
case 2: | ||
case 3: | ||
this.longPollParams = null | ||
return this.startPolling(timeout) | ||
return this.startPolling() | ||
default: | ||
@@ -34,7 +38,7 @@ console.error(`Listening Error: ${JSON.stringify(body)}`) | ||
this.longPollParams = null | ||
return this.startPolling(timeout) | ||
return this.startPolling() | ||
} | ||
} | ||
this.startPolling(timeout, body.ts) | ||
this.startPolling(null, body.ts) | ||
@@ -44,4 +48,4 @@ body.updates.forEach(update => this.next(new Context(update, this))) | ||
this.longPollParams = null | ||
this.startPolling(timeout) | ||
this.startPolling() | ||
} | ||
} |
{ | ||
"name": "node-vk-bot-api", | ||
"version": "2.1.7", | ||
"version": "2.1.8", | ||
"description": "🤖 Vk bot framework for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -45,3 +45,3 @@ [![node-vk-bot-api](https://img.shields.io/npm/v/node-vk-bot-api.svg?style=flat-square)](https://www.npmjs.com/package/node-vk-bot-api/) | ||
* [.sendMessage(userId, message, attachment, keyboard, sticker)](#sendmessageuserid-message-attachment-keyboard-sticker) | ||
* [.startPolling()](#startpollingtimeout) | ||
* [.startPolling([callback])](#startpollingcallback) | ||
@@ -60,3 +60,4 @@ ### constructor(settings) | ||
group_id: process.env.GROUP_ID, | ||
execute_timeout: process.env.EXECUTE_TIMEOUT, | ||
execute_timeout: process.env.EXECUTE_TIMEOUT, // in ms (50 by default) | ||
polling_timeout: process.env.POLLING_TIMEOUT, // in secs (25 by default) | ||
}) | ||
@@ -123,8 +124,10 @@ ``` | ||
### .startPolling([timeout]) | ||
### .startPolling([callback]) | ||
Start polling with given timeout (25 by default). | ||
Start polling with optional callback. | ||
```js | ||
bot.startPolling() | ||
bot.startPolling(() => { | ||
console.log('Bot started.') | ||
}) | ||
``` | ||
@@ -131,0 +134,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19381
422
285