mirror of
https://github.com/valentineus/iii-for-vk.git
synced 2025-04-28 01:41:25 +03:00
Release of version 0.0.1.
This commit is contained in:
commit
a078043572
28
.eslintrc.json
Normal file
28
.eslintrc.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
4
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
]
|
||||
}
|
||||
}
|
61
.gitignore
vendored
Normal file
61
.gitignore
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# Compiled files
|
||||
lib/
|
64
.npmignore
Normal file
64
.npmignore
Normal file
@ -0,0 +1,64 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# Source
|
||||
src/
|
||||
|
||||
# Example of use
|
||||
example.js
|
4
CHANGELOG.md
Normal file
4
CHANGELOG.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Description of releases
|
||||
## 0.0.1 (05-06-2017)
|
||||
|
||||
Release.
|
25
CONTRIBUTING.md
Normal file
25
CONTRIBUTING.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
* (a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
* (b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
* (c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
* (d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
6
LICENSE.md
Normal file
6
LICENSE.md
Normal file
@ -0,0 +1,6 @@
|
||||
Copyright 2017 [Valentin Popov](https://valentineus.link/)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
121
README.md
Normal file
121
README.md
Normal file
@ -0,0 +1,121 @@
|
||||
# iii-for-vk
|
||||
## Description
|
||||
This package contains a minimalistic and simple API for the rapid deployment of the bot under the social network VK.
|
||||
Created to demonstrate the possibilities of using the `iii-client` package.
|
||||
|
||||
The functionality of the existing API is easily extended to the needs of the developer.
|
||||
|
||||
Want to own a bot under the social network? Take my package and expand it, as you wish.
|
||||
|
||||
## Installation and usage example
|
||||
Installation is performed by the command:
|
||||
```bash
|
||||
npm install --save iii-for-vk
|
||||
```
|
||||
|
||||
A simple example that implements an answering machine is at the root of the repository.
|
||||
This is the file `example.js`.
|
||||
In the NPM package it is not included to reduce the volume:
|
||||
```bash
|
||||
$ git clone https://github.com/valentineus/iii-for-vk.git
|
||||
$ cd ./iii-for-vk
|
||||
# Edit the file example.js
|
||||
$ node ./example.js
|
||||
```
|
||||
|
||||
## Expanding functionality
|
||||
### Events
|
||||
There is an event channel called `events`.
|
||||
All incoming account events pass through it.
|
||||
Event details: https://vk.com/dev/using_longpoll
|
||||
|
||||
An example of a filter for certain events can be seen in the example of the `_filterMessages` function.
|
||||
|
||||
### Social Network API
|
||||
After declaring the main class and executing the `init` function, you can use the inner class` _vk` to work with the social network API.
|
||||
|
||||
Work Details: [nodejs-vksdk](https://github.com/57uff3r/nodejs-vksdk)
|
||||
|
||||
Example:
|
||||
```javascript
|
||||
var bot = new ChatBot({
|
||||
// Variables
|
||||
});
|
||||
|
||||
// Request 'users.get' method
|
||||
bot._vk.request('users.get', {'user_id' : 1}, function(_o) {
|
||||
console.log(_o);
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### new Bot()
|
||||
Class representing a Bot.
|
||||
|
||||
### bot.init(callback)
|
||||
Initial initialization of all systems and services.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| callback | <code>requestCallback</code> | The callback that handles the response. |
|
||||
|
||||
### bot.getMessageByID(id, callback)
|
||||
Receive a message by its ID.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| id | <code>Number</code> | The message ID. |
|
||||
| callback | <code>requestCallback</code> | The callback that handles the response. |
|
||||
|
||||
### bot.sendMessageToVK(options, callback)
|
||||
Simplifies the sending of a message to the user.
|
||||
The social network API is used.
|
||||
More information: https://vk.com/dev/messages.send
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | <code>Object</code> | Object with parameters. |
|
||||
| options.user_id | <code>Object</code> | User ID. |
|
||||
| options.message | <code>Object</code> | Message text. |
|
||||
| callback | <code>requestCallback</code> | The callback that handles the response. |
|
||||
|
||||
### bot.sendMessageToBot(options, callback)
|
||||
Simplifies sending a message to the bot.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | <code>Object</code> | Object with parameters. |
|
||||
| options.cuid | <code>Object</code> | Session identifier. |
|
||||
| options.text | <code>Object</code> | Message text. |
|
||||
| callback | <code>requestCallback</code> | The callback that handles the response. |
|
||||
|
||||
### bot._eventLoop()
|
||||
The event startup service.
|
||||
|
||||
### bot._filterMessages()
|
||||
Filter events for incoming messages.
|
||||
|
||||
*Fires:**: Bot#messages
|
||||
|
||||
### bot._getLongPollServer(callback)
|
||||
Obtaining the Long Poll server address.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| callback | <code>requestCallback</code> | The callback that handles the response. |
|
||||
|
||||
### bot._getEvents([ts])
|
||||
Waiting and returning the event.
|
||||
|
||||
*Fires:**: Bot#events
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [ts] | <code>String</code> | The ID of the last event. |
|
||||
|
||||
## License
|
||||
[](https://github.com/eslint/eslint)
|
||||
|
||||
[MIT](LICENSE.md).
|
||||
Copyright (c) [Valentin Popov](https://valentineus.link/).
|
56
example.js
Normal file
56
example.js
Normal file
@ -0,0 +1,56 @@
|
||||
var ChatBot = require('./lib/core.js');
|
||||
|
||||
var bot = new ChatBot({
|
||||
appID: "id", // The application ID
|
||||
appSecret: "secret", // Secret application key
|
||||
uuid: "uuid", // Bot 's ID
|
||||
token: "token" // The authorization key for the user profile
|
||||
});
|
||||
|
||||
bot.init(function(cuid) {
|
||||
// We view all events with messages
|
||||
bot.on('messages', function(raw) {
|
||||
// We receive the message by ID
|
||||
bot.getMessageByID(raw[1], function(message) {
|
||||
if (!message.out) {
|
||||
answer({
|
||||
cuid: cuid,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* We respond to the user with a delay.
|
||||
* @param {Object} options - Object with parameters.
|
||||
* @param {Object} options.cuid - Session ID
|
||||
* @param {Object} options.message - Incoming message.
|
||||
*/
|
||||
function answer(options) {
|
||||
setTimeout(function() {
|
||||
var text = options.message.body || ':-|';
|
||||
// Sending a message to the bot
|
||||
bot.sendMessageToBot({
|
||||
cuid: options.cuid,
|
||||
text: text
|
||||
}, function(message) {
|
||||
// Sending a response to the user
|
||||
bot.sendMessageToVK({
|
||||
user_id: options.message.user_id,
|
||||
message: message.text.tts
|
||||
});
|
||||
});
|
||||
}, random(1000, 5000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random number in the specified range.
|
||||
* @param {Number} min - Minimum value.
|
||||
* @param {Number} max - Maximum value.
|
||||
* @returns {Number} - Random number.
|
||||
*/
|
||||
function random(min, max) {
|
||||
return Math.floor(Math.random() * (max - min)) + min;
|
||||
}
|
2306
package-lock.json
generated
Normal file
2306
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
package.json
Normal file
40
package.json
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "iii-for-vk",
|
||||
"version": "0.0.1",
|
||||
"description": "Simple automatic reply to incoming messages.",
|
||||
"homepage": "https://github.com/valentineus/iii-for-vk",
|
||||
"main": "lib/core.js",
|
||||
"scripts": {
|
||||
"check": "eslint ./src/lib/core.js",
|
||||
"compile": "npm run check && babel --presets es2015 --minified --no-comments --source-maps --out-dir ./lib/ ./src/lib/",
|
||||
"prepublish": "npm run compile"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/valentineus/iii-for-vk.git"
|
||||
},
|
||||
"keywords": [
|
||||
"simple",
|
||||
"bot",
|
||||
"iii",
|
||||
"vk"
|
||||
],
|
||||
"author": "Valentin Popov <info@valentineus.link>",
|
||||
"bugs": {
|
||||
"url": "https://github.com/valentineus/iii-for-vk/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"iii-client": "^1.0.0",
|
||||
"inherits": "^2.0.3",
|
||||
"querystring": "^0.2.0",
|
||||
"url-parse-lax": "^1.0.0",
|
||||
"vksdk": "^5.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.24.1",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"eslint": "^3.19.0"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user