The Sendsay Javascript Client provides convenient access to the Sendsay API from applications written in JavaScript.
Official Sendsay API Documentation (Russian)
If you're using Sendsay on a web page, you can install the library via:
You can use any NPM-compatible package manager, including NPM itself and Yarn.
yarn add sendsay-api
Then:
import Sendsay from 'sendsay-api';
Or, if you're not using ES6 modules:
const Sendsay = require('sendsay-api');
Minified:
<script type="text/javascript" src="https://image.sendsay.ru/app/js/v1/sendsay-api.min.js"></script>
Unminified:
<script type="text/javascript" src="https://image.sendsay.ru/app/js/v1/sendsay-api.js"></script>
Node.js compatible. Install the fetch polyfill:
yarn add isomorphic-fetch
...DON'T FORGET TO APPLY THE POLYFILL:
require('isomorphic-fetch'); // Apply the polyfill.
const Sendsay = require('sendsay-api');
const sendsay = new Sendsay({ apiKey: 'secret' });
sendsay.request({ action: 'sys.settings.get', list: ['about.id']}).then(function(res) {
console.log(res.list['about.id']);
})
Using API key (the recommended way):
var sendsay = new Sendsay({ apiKey: '...' });
sendsay.request({ action: 'sys.settings.get', list: ['about.id']}).then(function(res) {
console.log(res.list['about.id']);
})
Using login and password:
Sendsay client will automatically create a new session right before the first request sent.
NOTE: All the methods below don't automatically renew sessions. This feature will be implemented in the next releases.
var sendsay = new Sendsay({
auth: {
login: 'login',
sublogin: 'optional',
password: 'secret',
}
});
sendsay.request({ action: 'sys.settings.get', list: ['about.id']}).then(function(res) {
console.log(res.list['about.id']);
})
There is also a special method for authentication via a login:
var sendsay = new Sendsay();
sendsay.login({
login: 'login',
sublogin: 'optional',
password: 'secret',
}).then(function() {
// The sendsay instance is authenticated. Do a request.
})
sendsay.setSessionFromCookie(); // By default the cookie's name is 'sendsay_session'.
sendsay.setSessionFromCookie('custom_cookie_name');
sendsay.setSession('secret');
var req = sendsay.request({
action: 'sys.settings.get',
list: [
'about.confirm',
'about.id',
'about.label.member',
'about.name',
'about.open.dt',
'about.open.visitor',
'about.owner.email',
'about.tarif',
'about.user',
'anketa.id.base',
'anketa.id.custom',
'interface.type',
'interface.type.user',
'issue.email.sender.moderation',
'issue.pte.datakey',
'lbac.inuse',
'lbac.on',
'member.hard.limit',
'member.hard.rest',
'member.noconfirm.limit',
'member.noconfirm.rest',
'pase.autopayment',
'pase.destination',
'pase.left',
'pase.state',
'about.chat.on',
],
});
req.then(function(res) {
var settings = res.list;
console.log(settings);
});
There are a number of configuration parameters which can be set for the Sendsay client, which can be passed as an object to the Sendsay constructor, i.e.:
var sendsay = new Sendsay({ apiUrl: 'https://api.development.sendsay.ru' })
Default: 'https://api.sendsay.ru'
The url to the Sendsay API server.
The api key for authentication.
The auth credentials (login
, sublogin
, password
) for authentication.