aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: ca4aba46ccaa25dfd79b66300841132a093c39c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# III Client
<p align="justify">
    <a href="https://www.npmjs.com/package/iii-client">
        <img alt="NPM" src="https://img.shields.io/npm/v/iii-client.svg">
    </a>
    <a href="https://travis-ci.org/valentineus/iii-client">
        <img alt="Build Status" src="https://travis-ci.org/valentineus/iii-client.svg?branch=master">
    </a>
    <a href="https://www.codacy.com/app/valentineus/iii-client">
        <img alt="Codacy Badge" src="https://api.codacy.com/project/badge/Grade/81b2fdc2f5dd42a6bdc8fdb43640b282">
    </a>
    <a href="https://www.codacy.com/app/valentineus/iii-client/files">
        <img alt="Codacy Coverage Badge" src="https://api.codacy.com/project/badge/Coverage/81b2fdc2f5dd42a6bdc8fdb43640b282">
    </a>
    <a href="https://david-dm.org/valentineus/iii-client?type=dev">
        <img alt="devDependencies Status" src="https://david-dm.org/valentineus/iii-client/dev-status.svg">
    </a>
</p>
<p align="justify">
    <a href="https://www.libhive.com/providers/npm/packages/iii-client">
        <img alt="libhive Badge" src="https://www.libhive.com/providers/npm/packages/iii-client/examples/badge.svg">
    </a>
    <a href="https://runkit.com/npm/iii-client">
        <img alt="RunKit Badge" src="https://badge.runkitcdn.com/stripe.svg">
    </a>
    <a href="https://gitter.im/valentineus/iii-client">
        <img alt="Gitter Badge" src="https://badges.gitter.im/Join%20Chat.svg">
    </a>
</p>

Simple API for communicating with the bot of the \"iii.ru\" service.

## Features
- A small and light library.
- Works, both in NodeJS, and in the browser.
- Getting session ID.
- Sending and receiving messages.
- Does not process incoming errors.

## Installation
NodeJS:
```bash
npm install --save iii-client
```

Browser:
```html
<script src="https://unpkg.com/iii-client@latest/dist/bundle.js">
    /* iiiClient - This is the global name for accessing the package */
</script>
```

## Using
An example of a connection, receiving session identification and sending a bot message:
```javascript
import { connect, send } from 'iii-client';

var uuid = '109cd867-0ef3-4473-af71-7543a9b2fccd';
var text = 'Hello, World!';

/* We connect to the system and get a session */
connect(uuid, (request) => {
    console.info(`Session: ${request}`);
    /* Send the message and process the response */
    if (request.result) {
        var cuid = request.result.cuid;
        send(cuid, text, (answer) => {
            console.info(`Answer: ${answer}`);
        });
    }
});
```

## API
## Functions
<dl>
    <dt>
        <a href="#connect">connect(uuid, callback)</a>
    </dt>
    <dd>
        <p>Connection to the service and retrieves the session identifier.</p>
    </dd>
    <dt>
        <a href="#send">send(cuid, text, callback)</a>
    </dt>
    <dd>
        <p>Sends a message to bot and returns a response.</p>
    </dd>
</dl>

<a name="connect"></a>

## connect(uuid, callback)
Connection to the service and retrieves the session identifier.

| Param | Type | Description |
| --- | --- | --- |
| uuid | <code>String</code> | Bot ID |
| callback | <code>function</code> | Function handler |

<a name="send"></a>

## send(cuid, text, callback)
Sends a message to bot and returns a response.

| Param | Type | Description |
| --- | --- | --- |
| cuid | <code>String</code> | Session ID |
| text | <code>String</code> | Send messages |
| callback | <code>function</code> | Function handler |

## License
[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/eslint/eslint)

[MIT](LICENSE.md).
Copyright (c)
[Valentin Popov](https://valentineus.link/).