Comparing version 2.3.3 to 2.3.4
{ | ||
"name": "botact", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "Botact enables developers to focus on writing reusable application logic instead of spending time building infrastructure.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
344
README.md
@@ -1,8 +0,3 @@ | ||
[![botact](https://img.shields.io/npm/v/botact.svg?style=flat-square)](https://www.npmjs.com/package/botact/) | ||
[![botact](https://img.shields.io/node/v/botact.svg?style=flat-square)](https://nodejs.org/en/) | ||
[![botact](https://img.shields.io/npm/dm/botact.svg?style=flat-square)](https://www.npmjs.com/package/botact/) | ||
[![botact](https://img.shields.io/travis/bifot/botact.svg?branch=master&style=flat-square)](https://travis-ci.org/bifot/botact/) | ||
[![botact](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/) | ||
[![botact](https://img.shields.io/npm/v/botact.svg?style=flat-square)](https://www.npmjs.com/package/botact/) [![botact](https://img.shields.io/node/v/botact.svg?style=flat-square)](https://nodejs.org/en/) [![botact](https://img.shields.io/npm/dm/botact.svg?style=flat-square)](https://www.npmjs.com/package/botact/) [![botact](https://img.shields.io/travis/bifot/botact.svg?branch=master&style=flat-square)](https://travis-ci.org/bifot/botact/) [![botact](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/) | ||
# botact.js | ||
@@ -12,21 +7,19 @@ | ||
## Table of content | ||
## Table of content | ||
* [Install](#install) | ||
* [Usage](#usage) | ||
* [Botact API](#botact-api) | ||
* [Botact Flow API](#botact-flow-api) | ||
* [TypeScript](#typescript) | ||
* [Tests](#tests) | ||
* [Donate](#donate-) | ||
* [License](#license) | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [Botact API](#botact-api) | ||
- [Botact Flow API](#botact-flow-api) | ||
- [TypeScript](#typescript) | ||
- [Tests](#tests) | ||
- [Donate](#donate-) | ||
- [License](#license) | ||
## Install | ||
```sh | ||
$ npm i botact | ||
$ npm i botact -S | ||
``` | ||
## Usage | ||
@@ -55,40 +48,49 @@ | ||
## Botact API | ||
## Botact API | ||
### Methods | ||
**Core** | ||
* [constructor(settings)](#constructorsettings) | ||
* [.api(method, settings)](#apimethod-settings) | ||
* [.execute(method, settings, callback)](#executemethod-settings-callback) | ||
* [.reply(user_id, message, attachment)](#replyuser_id-message-attachment) | ||
* [.listen(req, res)](#listenreq-res) | ||
- [constructor(settings)](#constructorsettings) | ||
- [.api(method, settings)](#apimethod-settings) | ||
- [.execute(method, settings, callback)](#executemethod-settings-callback) | ||
- [.reply(user_id, message, attachment)](#replyuser_id-message-attachment) | ||
- [.listen(req, res)](#listenreq-res) | ||
**Actions** | ||
* [.before(callback)](#beforecallback) | ||
* [.command(command, callback)](#commandcommand-callback) | ||
* [.event(event, callback)](#eventevent-callback) | ||
* [.hears(command, callback)](#hearscommand-callback) | ||
* [.on(type, callback)](#ontype-callback) | ||
* [.use(callback)](#usecallback) | ||
- [.before(callback)](#beforecallback) | ||
- [.command(command, callback)](#commandcommand-callback) | ||
- [.event(event, callback)](#eventevent-callback) | ||
- [.hears(command, callback)](#hearscommand-callback) | ||
- [.on(type, callback)](#ontype-callback) | ||
- [.use(callback)](#usecallback) | ||
**Options** | ||
* [[getter] options](#getter-options) | ||
* [[setter] options](#setter-options) | ||
* [.deleteOptions(settings)](#deleteoptionssettings) | ||
- [[getter] options](#getter-options) | ||
- [[setter] options](#setter-options) | ||
- [.deleteOptions(settings)](#deleteoptionssettings) | ||
**Upload helpers** | ||
* [.uploadCover(file, settings)](#uploadcoverfile-settings) | ||
* [.uploadDocument(file, peer_id ,type)](#uploaddocumentfile-peer_id-type) | ||
* [.uploadPhoto(file, peer_id)](#uploadphotofile-peer_id) | ||
--- | ||
- [.uploadCover(file, settings)](#uploadcoverfile-settings) | ||
- [.uploadDocument(file, peer_id ,type)](#uploaddocumentfile-peer_id-type) | ||
- [.uploadPhoto(file, peer_id)](#uploadphotofile-peer_id) | ||
-------------------------------------------------------------------------------- | ||
## Botact API: Core [↑](#botact-api) | ||
### constructor(settings) | ||
Create bot. | ||
Botact Flow: | ||
Turn `settings.redis` to true, if you will use [Botact Flow](#botact-flow-api). | ||
Create bot. | ||
Botact Flow:<br> | ||
Turn `settings.redis` to true, if you will use [Botact Flow](#botact-flow-api).<br> | ||
For detailed redis config see [this](https://github.com/NodeRedis/node_redis#options-object-properties) | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
@@ -106,4 +108,5 @@ constructor (settings: { | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -119,13 +122,17 @@ const { Botact } = require('botact') | ||
### .api(method, settings) | ||
Call API method (https://vk.com/dev/methods). | ||
Definition: | ||
Call API method (<https://vk.com/dev/methods>). | ||
**Definition:** | ||
```typescript | ||
async api ( | ||
method: string, // required | ||
method: string, // required | ||
options?: object, // api call parameters | ||
): Promise<any>; // Promise with response/error | ||
``` | ||
Usage: | ||
```js | ||
**Usage:** | ||
```javascript | ||
const user_data = await bot.api('users.get', { | ||
@@ -137,15 +144,18 @@ user_ids: 1 | ||
### .execute(method, settings, callback) | ||
Call API by [execute](https://vk.com/dev/execute). | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
async execute ( | ||
method: string, // required | ||
method: string, // required | ||
options?: object, // api call parameters | ||
callback?: function | ||
): Promise<any>; // Promise with response/error | ||
``` | ||
``` | ||
Usage: | ||
```js | ||
**Usage:** | ||
```javascript | ||
bot.execute('users.get', { | ||
@@ -165,14 +175,17 @@ user_ids: 1 | ||
### .reply(user_id, message, attachment) | ||
Sends message to user | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
async reply ( | ||
user_id: number, | ||
message: string, // required, if attachment not setten | ||
attachment: string // required, if message not setten | ||
user_id: number, | ||
message: string, // required, if attachment not setten | ||
attachment: string // required, if message not setten | ||
): Promise<any> // Promise with response/error | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -192,5 +205,7 @@ bot.command('start', (ctx) => { | ||
### .listen(req, res) | ||
Start listen [Express](https://github.com/expressjs/express/) server. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
@@ -203,3 +218,4 @@ listen ( | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -209,8 +225,10 @@ bot.listen(req, res) | ||
## Botact API: Actions [↑](#botact-api) | ||
## Botact API: Actions [↑](#botact-api) | ||
### .before(callback) | ||
Add callback before bot will start. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
@@ -221,4 +239,6 @@ before ( | ||
``` | ||
Usage: | ||
```js | ||
**Usage:** | ||
```javascript | ||
bot.before(() => new Date()) | ||
@@ -232,12 +252,16 @@ | ||
### .command(command, callback) | ||
Add command w/ strict match. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
command ( | ||
command: string | string[], | ||
command: string | string[], | ||
callback: function | ||
): Botact | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -248,12 +272,16 @@ bot.command('start', ({ reply }) => reply('This is start!')) | ||
### .event(event, callback) | ||
Add [event](https://vk.com/dev/groups_events) handler . | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
event ( | ||
event: string | string[], | ||
event: string | string[], | ||
callback: function | ||
): Botact; | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -264,12 +292,16 @@ bot.event('group_join', ({ reply }) => reply('Thanks!')) | ||
### .hears(command, callback) | ||
Add command w/ match like RegEx. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
hears ( | ||
hear: string | RegExp | (string | RegExp)[], | ||
hear: string | RegExp | (string | RegExp)[], | ||
callback: function | ||
): Botact; | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -280,8 +312,10 @@ bot.hears(/(car|tesla)/, ({ reply }) => reply('I love Tesla!')) | ||
### .on(type, callback) | ||
Add reserved callback. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
on ( | ||
type: string, | ||
type: string, | ||
callback: function | ||
@@ -296,3 +330,5 @@ ): Botact; | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -304,5 +340,7 @@ bot.on(({ reply }) => reply('What?')) | ||
### .use(callback) | ||
Add middleware. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
@@ -313,4 +351,6 @@ use ( | ||
``` | ||
Usage: | ||
```js | ||
**Usage:** | ||
```javascript | ||
bot.use(ctx => ctx.date = new Date()) | ||
@@ -323,4 +363,4 @@ | ||
## Botact API: Options [↑](#botact-api) | ||
## Botact API: Options [↑](#botact-api) | ||
### [getter] options | ||
@@ -330,3 +370,3 @@ | ||
```js | ||
```javascript | ||
bot.options | ||
@@ -343,3 +383,3 @@ // { | ||
```js | ||
```javascript | ||
bot.options = { foo: 'bar' } | ||
@@ -354,5 +394,7 @@ // { | ||
### .deleteOptions(settings) | ||
Delete keys settings. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
@@ -363,4 +405,6 @@ deleteOptions ( | ||
``` | ||
Usage: | ||
```js | ||
**Usage:** | ||
```javascript | ||
bot.deleteOptions([ 'token', 'confirmation' ]) | ||
@@ -372,8 +416,10 @@ // { | ||
## Botact API: Upload helpers [↑](#botact-api) | ||
## Botact API: Upload helpers [↑](#botact-api) | ||
### .uploadCover(file, settings) | ||
Upload and save cover. | ||
See detailed settings [here](https://vk.com/dev/photos.getOwnerCoverPhotoUploadServer). | ||
Definition: | ||
Upload and save cover. See detailed settings [here](https://vk.com/dev/photos.getOwnerCoverPhotoUploadServer). | ||
**Definition:** | ||
```typescript | ||
@@ -385,3 +431,5 @@ async uploadCover ( | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -391,6 +439,6 @@ await bot.uploadCover('./cover.jpg', { crop_x2: 1590 }) | ||
// images: [ | ||
// { | ||
// { | ||
// url: "URL", | ||
// width: 1920, | ||
// height: 1080 | ||
// height: 1080 | ||
// }, | ||
@@ -406,22 +454,26 @@ // [Object], | ||
### .uploadDocument(file, peer_id, type) | ||
Uploads document to peer. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
async uploadDocument ( | ||
filepath: string, // Path to file | ||
peer_id: number, | ||
peer_id: number, | ||
type: 'doc' | 'audio_message' // 'doc' by default | ||
): Promise<any>; // Promise with response/error | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
await bot.uploadDocument('./book.pdf', 1234) | ||
// { | ||
// { | ||
// response: | ||
// [{ | ||
// [{ | ||
// id: 1234, | ||
// owner_id: 1234, | ||
// title: "", | ||
// ... | ||
// ... | ||
// }] | ||
@@ -432,5 +484,7 @@ // } | ||
### .uploadPhoto(file, peer_id) | ||
Uploads photo to peer. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
@@ -442,3 +496,5 @@ async uploadPhoto ( | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -454,3 +510,4 @@ await bot.uploadPhoto('./picture.png', 1234) | ||
--- | ||
-------------------------------------------------------------------------------- | ||
## Botact Flow API | ||
@@ -460,2 +517,13 @@ | ||
```javascript | ||
const bot = new Botact({ | ||
..., | ||
redis: true // enable redis | ||
flowTimeout: 20 // timeout for delete documents | ||
redisConfig: { // redis config | ||
port: 1234 | ||
} | ||
}) | ||
``` | ||
```sh | ||
@@ -466,7 +534,8 @@ $ redis-server | ||
### Methods | ||
* [.addScene(name, ...callbacks)](#addscenename-callbacks) | ||
* [.joinScene(ctx, scene, session, step, now)](#joinscenectx-scene-session-step-now) | ||
* [.nextScene(ctx, body)](#nextscenectx-body) | ||
* [.leaveScene(ctx)](#leavescenectx) | ||
- [.addScene(name, ...callbacks)](#addscenename-callbacks) | ||
- [.joinScene(ctx, scene, session, step, now)](#joinscenectx-scene-session-step-now) | ||
- [.nextScene(ctx, body)](#nextscenectx-body) | ||
- [.leaveScene(ctx)](#leavescenectx) | ||
### Example | ||
@@ -483,6 +552,7 @@ | ||
token: process.env.TOKEN, | ||
flowTimeout: 20, // document will be deleted after 20 secs | ||
redis: true, | ||
flowTimeout: 20, // document will be deleted after 20 secs | ||
redisConfig: { | ||
host: '127.0.0.1', // default host for redis | ||
port: 8080 // custom port for redis | ||
host: '127.0.0.1', // default host for redis | ||
port: 8080 // custom port for redis | ||
}, | ||
@@ -507,16 +577,21 @@ }) | ||
app.listen(process.env.PORT) | ||
``` | ||
``` | ||
## Botact Flow API: Methods | ||
### .addScene(name, ...callbacks) | ||
Add scene. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
addScene ( | ||
name: string, | ||
name: string, | ||
...args: function[] | ||
): Botact; | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -536,10 +611,12 @@ bot.addScene('wizard', | ||
### .joinScene(ctx, scene, session, step, now) | ||
Enter scene. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
async joinScene ( | ||
ctx: object, | ||
scene: string, | ||
session?: object, // {} by default | ||
ctx: object, | ||
scene: string, | ||
session?: object, // {} by default | ||
step?: number, // 0 by default | ||
@@ -549,3 +626,5 @@ instantly?: boolean // true by default | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -561,12 +640,16 @@ bot.command('join', (ctx) => { | ||
### .nextScene(ctx, body) | ||
Navigate scene. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
async nextScene ( | ||
ctx: object, | ||
session?: object, // {} by default | ||
ctx: object, | ||
session?: object, // {} by default | ||
): Promise<Botact>; | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -584,5 +667,7 @@ bot.addScene('wizard', | ||
### .leaveScene(ctx) | ||
Leave scene. | ||
Definition: | ||
**Definition:** | ||
```typescript | ||
@@ -593,3 +678,5 @@ async leaveScene( | ||
``` | ||
Usage: | ||
**Usage:** | ||
```javascript | ||
@@ -606,7 +693,8 @@ bot.addScene('wizard', | ||
--- | ||
-------------------------------------------------------------------------------- | ||
## TypeScript | ||
Botact includes [TypeScript](https://www.typescriptlang.org/) definitions. | ||
## Tests | ||
@@ -618,3 +706,2 @@ | ||
## Donate 💰 | ||
@@ -624,9 +711,8 @@ | ||
* **Bitcoin:** 1C26xXoA42Ufz5cNNPhAJY8Ykqh2QB966L | ||
* **Ethereum:** 0x331FeA1a0b0E9E66A647e964cF4eBE1D2E721579 | ||
* **Qiwi:** 79522232254 | ||
- **Bitcoin:** 1C26xXoA42Ufz5cNNPhAJY8Ykqh2QB966L | ||
- **Ethereum:** 0x331FeA1a0b0E9E66A647e964cF4eBE1D2E721579 | ||
- **Qiwi:** 79522232254 | ||
## License | ||
MIT. |
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
702971
678
43