1
0
mirror of synced 2024-11-25 22:06:02 +03:00
mg-bot-api-client-js/index.html

136 lines
5.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Home</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Home</h1>
<h3> </h3>
<section>
<article><p><a href="https://travis-ci.org/retailcrm/mg-bot-api-client-js"><img src="https://img.shields.io/travis/retailcrm/mg-bot-api-client-js/master.svg?logo=travis&amp;style=flat-square" alt="Build Status"></a>
<a href="https://github.com/retailcrm/mg-bot-api-client-js/releases"><img src="https://img.shields.io/github/release/retailcrm/mg-bot-api-client-js.svg?style=flat-square" alt="GitHub release"></a>
<a href="https://www.npmjs.com/package/mg-api-client"><img src="https://img.shields.io/node/v/mg-api-client.svg?style=flat-square" alt="Node version"></a></p>
<h1>retailCRM Message Gateway Bot API JS client</h1><p>This is js retailCRM bot API client.</p>
<h1>Installation</h1><pre class="prettyprint source"><code>npm install --save mg-api-client</code></pre><p>In your file</p>
<h6>CommonJS</h6><pre class="prettyprint source"><code>var MgBotApiClient = require('mg-api-client');</code></pre><h6>es6</h6><pre class="prettyprint source"><code>import MgBotApiClient from 'mg-api-client';</code></pre><h1>Usage</h1><h4>Get users</h4><pre class="prettyprint source lang-javascript"><code>const api = new MgBotApiClient({
host: 'https://api.example.com',
token: 'your bot token',
apiVersion: 'v1' // optional
}).client;
api.getUsers()
.then(function (users) {
console.log(users);
})
.catch(function (e) {
console.log(e);
});</code></pre><h4>Send message</h4><pre class="prettyprint source lang-javascript"><code>const api = new MgBotApiClient({
host: 'https://api.example.com',
token: 'your bot token',
apiVersion: 'v1' // optional
}).client;
let 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);
});</code></pre><h4>Websocket Example</h4><pre class="prettyprint source lang-javascript"><code>const WebSocket = require('ws');
const api = new MgBotApiClient({
host: 'https://api.example.com',
token: 'your bot token',
apiVersion: 'v1' // optional
}).client;
const wsData = api.getWebsocketData([MgBotApiClient.types().wsMessageNew]);
const ws = new WebSocket(wsData.get('url'), {
headers: wsData.get('headers')
});
ws.on('message', function (content) {
let event = JSON.parse(content);
let data = event.data;
if (event.type === 'message_new' && data.message.from.type !== 'bot') {
let message = {
chat_id: data.message.chat_id,
content: 'Bonjour!',
scope: 'public',
type: 'text'
};
api.sendMessage(message).then(function (res) {
console.log(res);
}).catch(function (e) {
console.log(e);
})
}
});</code></pre></article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Client.html">Client</a></li></ul><h3>Global</h3><ul><li><a href="global.html#messageScopePrivate">messageScopePrivate</a></li><li><a href="global.html#messageScopePublic">messageScopePublic</a></li><li><a href="global.html#msgTypeCommand">msgTypeCommand</a></li><li><a href="global.html#msgTypeFile">msgTypeFile</a></li><li><a href="global.html#msgTypeImage">msgTypeImage</a></li><li><a href="global.html#msgTypeOrder">msgTypeOrder</a></li><li><a href="global.html#msgTypeProduct">msgTypeProduct</a></li><li><a href="global.html#msgTypeSystem">msgTypeSystem</a></li><li><a href="global.html#msgTypeText">msgTypeText</a></li><li><a href="global.html#wsBotUpdated">wsBotUpdated</a></li><li><a href="global.html#wsChannelUpdated">wsChannelUpdated</a></li><li><a href="global.html#wsChatCreated">wsChatCreated</a></li><li><a href="global.html#wsChatUnreadUpdated">wsChatUnreadUpdated</a></li><li><a href="global.html#wsChatUpdated">wsChatUpdated</a></li><li><a href="global.html#wsCustomerUpdated">wsCustomerUpdated</a></li><li><a href="global.html#wsDialogAssign">wsDialogAssign</a></li><li><a href="global.html#wsDialogClosed">wsDialogClosed</a></li><li><a href="global.html#wsDialogOpened">wsDialogOpened</a></li><li><a href="global.html#wsMessageDeleted">wsMessageDeleted</a></li><li><a href="global.html#wsMessageNew">wsMessageNew</a></li><li><a href="global.html#wsMessageUpdated">wsMessageUpdated</a></li><li><a href="global.html#wsSettingsUpdated">wsSettingsUpdated</a></li><li><a href="global.html#wsUserJoinedChat">wsUserJoinedChat</a></li><li><a href="global.html#wsUserLeftChat">wsUserLeftChat</a></li><li><a href="global.html#wsUserOnlineUpdated">wsUserOnlineUpdated</a></li><li><a href="global.html#wsUserUpdated">wsUserUpdated</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Mar 07 2019 08:12:08 GMT+0000 (UTC)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>