node-vk-bot-api
Advanced tools
Comparing version 2.1.3 to 2.1.4
@@ -7,5 +7,7 @@ const methods = require('./methods') | ||
constructor(settings) { | ||
if (!settings.token) { | ||
if (!settings) { | ||
throw new Error('You must pass token into settings') | ||
} else if (typeof settings === 'object' && !settings.token) { | ||
throw new Error('You must set token param in settings') | ||
} else if (!settings.group_id) { | ||
} else if (typeof settings === 'object' && !settings.group_id) { | ||
throw new Error('You must set group_id param in settings') | ||
@@ -17,3 +19,5 @@ } | ||
this.methods = [] | ||
this.settings = settings | ||
this.settings = typeof settings === 'object' | ||
? settings | ||
: { token: settings } | ||
@@ -27,3 +31,3 @@ Object.entries({ ...methods, api, callExecute }).forEach(([key, method]) => { | ||
this.methods = [] | ||
}, settings.executeTimeout || 50) | ||
}, settings.execute_timeout || 50) | ||
} | ||
@@ -30,0 +34,0 @@ |
@@ -9,3 +9,3 @@ const toArray = value => (Array.isArray(value) ? value : [value]) | ||
fn: ctx => fn(ctx, () => this.next(ctx, idx)), | ||
triggers: toArray(triggers).map(item => item instanceof RegExp ? item : item.toLowerCase()), | ||
triggers: toArray(triggers).map(item => (item instanceof RegExp ? item : item.toLowerCase())), | ||
}) | ||
@@ -12,0 +12,0 @@ }) |
@@ -5,3 +5,3 @@ module.exports = function (method, settings, callback = () => {}) { | ||
v: '5.80', | ||
...settings | ||
...settings, | ||
})})`, | ||
@@ -8,0 +8,0 @@ callback, |
module.exports = async function () { | ||
if (!this.settings.group_id) { | ||
const { response } = await this.api('groups.getById', { | ||
access_token: this.settings.token, | ||
}) | ||
this.settings.group_id = response[0].id | ||
} | ||
const { response } = await this.api('groups.getLongPollServer', { | ||
@@ -3,0 +11,0 @@ group_id: this.settings.group_id, |
@@ -40,3 +40,3 @@ class Stage { | ||
ctx.session.__scene.step = index | ||
} | ||
}, | ||
} | ||
@@ -43,0 +43,0 @@ |
{ | ||
"name": "node-vk-bot-api", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"description": "🤖 Vk bot framework for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -20,6 +20,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/) | ||
const bot = new VkBot({ | ||
token: process.env.TOKEN, | ||
group_id: process.env.GROUP_ID | ||
}) | ||
const bot = new VkBot(process.env.TOKEN) | ||
@@ -52,5 +49,10 @@ bot.command('/start', (ctx) => { | ||
```javascript | ||
// Simple usage | ||
const bot = new VkBot(process.env.TOKEN) | ||
// Advanced usage | ||
const bot = new VkBot({ | ||
token: process.env.TOKEN, | ||
group_id: process.env.GROUP_ID | ||
group_id: process.env.GROUP_ID, | ||
execute_timeout: process.env.EXECUTE_TIMEOUT, | ||
}) | ||
@@ -113,3 +115,3 @@ ``` | ||
lat: 59.939095, | ||
lng: 30.315868 | ||
lng: 30.315868, | ||
}) | ||
@@ -186,6 +188,3 @@ ``` | ||
const bot = new VkBot({ | ||
token: process.env.TOKEN, | ||
group_id: process.env.GROUP_ID, | ||
}) | ||
const bot = new VkBot(process.env.TOKEN) | ||
const session = new Session() | ||
@@ -216,3 +215,3 @@ | ||
const getSessionKey = (ctx) => { | ||
return `${ctx.message.from_id}:${ctx.message.from_id}` | ||
return `${ctx.message.from_id}:${ctx.message.from_id}` | ||
} | ||
@@ -230,6 +229,3 @@ ```` | ||
const bot = new VkBot({ | ||
token: process.env.TOKEN, | ||
group_id: process.env.GROUP_ID, | ||
}) | ||
const bot = new VkBot(process.env.TOKEN) | ||
const scene = new Scene('meet', | ||
@@ -251,3 +247,3 @@ (ctx) => { | ||
ctx.reply(`Nice to meet you, ${ctx.session.name} (${ctx.session.age} years old)`) | ||
} | ||
}, | ||
) | ||
@@ -254,0 +250,0 @@ const session = new Session() |
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
19138
430
278