156 lines
5.8 KiB
HTML
156 lines
5.8 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://github.com/retailcrm/mg-bot-api-client-js/actions"><img src="https://github.com/retailcrm/mg-bot-api-client-js/workflows/ci/badge.svg" alt="Build Status"></a>
|
|
<a href="https://codecov.io/gh/retailcrm/mg-bot-api-client-js"><img src="https://img.shields.io/codecov/c/gh/retailcrm/mg-bot-api-client-js/master.svg?logo=codecov&logoColor=white" alt="Coverage"></a>
|
|
<a href="https://npmjs.com/package/mg-api-client"><img src="https://img.shields.io/npm/v/mg-api-client.svg?logo=npm&logoColor=white" alt="Latest stable"></a>
|
|
<a href="https://www.npmjs.com/package/mg-api-client"><img src="https://img.shields.io/node/v/mg-api-client.svg?logo=node.js&logoColor=white" alt="Node version"></a>
|
|
<a href="https://retailcrm.github.io/mg-bot-api-client-js/"><img src="https://img.shields.io/badge/doc-github_pages-green" alt="JS Doc"></a></p>
|
|
<h1>Message Gateway Bot API JavaScript client</h1>
|
|
<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/jsdoc/jsdoc">JSDoc 3.6.6</a> on Tue Dec 15 2020 10:36:21 GMT+0000 (Coordinated Universal Time)
|
|
</footer>
|
|
|
|
<script> prettyPrint(); </script>
|
|
<script src="scripts/linenumber.js"> </script>
|
|
</body>
|
|
</html> |