2019-02-08 14:53:02 +03:00
|
|
|
[![Build Status](https://img.shields.io/travis/retailcrm/mg-bot-api-client-js/master.svg?logo=travis&style=flat-square)](https://travis-ci.org/retailcrm/mg-bot-api-client-js)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/retailcrm/mg-bot-api-client-js.svg?style=flat-square)](https://github.com/retailcrm/mg-bot-api-client-js/releases)
|
2019-02-08 15:41:00 +03:00
|
|
|
[![Node version](https://img.shields.io/node/v/mg-bot-api-client-js.svg?style=flat-square)](https://www.npmjs.com/package/mg-api-client)
|
2019-02-08 14:53:02 +03:00
|
|
|
|
|
|
|
|
2018-09-04 10:26:32 +03:00
|
|
|
# retailCRM Message Gateway Bot API JS client
|
|
|
|
|
2019-02-08 14:37:43 +03:00
|
|
|
This is js retailCRM bot API client.
|
2019-02-06 14:54:15 +03:00
|
|
|
|
|
|
|
# Installation
|
|
|
|
```
|
|
|
|
npm install --save mg-bot-api-client-js
|
|
|
|
```
|
|
|
|
In your file
|
|
|
|
```
|
2019-02-06 14:55:26 +03:00
|
|
|
var RetailcrmBotApiClient = require('mg-bot-api-client-js');
|
2019-02-06 14:54:15 +03:00
|
|
|
```
|
|
|
|
# Usage
|
|
|
|
#### Get users
|
|
|
|
```javascript
|
|
|
|
var api = new RetailcrmBotApiClient({
|
|
|
|
host: 'https://api.example.com',
|
|
|
|
token: 'your bot token',
|
|
|
|
apiVersion: 'v1' // optional
|
2019-02-08 13:31:38 +03:00
|
|
|
}).getClient();
|
2019-02-06 14:54:15 +03:00
|
|
|
|
|
|
|
api.getUsers()
|
|
|
|
.then(function (users) {
|
|
|
|
console.log(users);
|
|
|
|
})
|
|
|
|
.catch(function (e) {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Send message
|
|
|
|
```javascript
|
|
|
|
var api = new RetailcrmBotApiClient({
|
|
|
|
host: 'https://api.example.com',
|
|
|
|
token: 'your bot token',
|
|
|
|
apiVersion: 'v1' // optional
|
2019-02-08 13:31:38 +03:00
|
|
|
}).getClient();
|
2019-02-06 14:54:15 +03:00
|
|
|
|
|
|
|
var message = {
|
|
|
|
chat_id: 1,
|
|
|
|
content: 'Text message',
|
|
|
|
scope: 'public',
|
|
|
|
type: 'text'
|
2019-02-08 13:31:38 +03:00
|
|
|
};
|
2019-02-06 14:54:15 +03:00
|
|
|
|
|
|
|
api.sendMessage(message)
|
|
|
|
.then(function (result) {
|
|
|
|
console.log(result);
|
|
|
|
})
|
|
|
|
.catch(function (e) {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
```
|