1
0
mirror of synced 2024-11-28 15:16:01 +03:00
mg-bot-api-client-js/README.md
2019-02-08 15:08:52 +03:00

59 lines
1.5 KiB
Markdown

[![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)
[![Node version](https://img.shields.io/node/v/mg-bot-api-client-js.svg?style=flat-square)](https://www.npmjs.com/package/mg-bot-api-client-js)
# retailCRM Message Gateway Bot API JS client
This is js retailCRM bot API client.
# Installation
```
npm install --save mg-bot-api-client-js
```
In your file
```
var RetailcrmBotApiClient = require('mg-bot-api-client-js');
```
# Usage
#### Get users
```javascript
var api = new RetailcrmBotApiClient({
host: 'https://api.example.com',
token: 'your bot token',
apiVersion: 'v1' // optional
}).getClient();
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
}).getClient();
var message = {
chat_id: 1,
content: 'Text message',
scope: 'public',
type: 'text'
};
api.sendMessage(message)
.then(function (result) {
console.log(result);
})
.catch(function (e) {
console.log(e);
});
```