Sendsay Javascript Client
The Sendsay Javascript Client provides convenient access to the Sendsay API from applications written in JavaScript.
Official Sendsay API Documentation (Russian)
Installation
Web
If you're using Sendsay on a web page, you can install the library via:
Yarn (or NPM)
You can use any NPM-compatible package manager, including NPM itself and Yarn.
yarn add sendsay-api
Then:
;
Or, if you're not using ES6 modules:
const Sendsay = ;
CDN
Minified:
Unminified:
Node.js
Node.js compatible. Install the fetch polyfill:
yarn add isomorphic-fetch
...DON'T FORGET TO APPLY THE POLYFILL:
; // Apply the polyfill.const Sendsay = ; const sendsay = apiKey: 'secret' ; sendsay
Usage
Authentication
Using API key (the recommended way):
var sendsay = apiKey: '...' ; sendsay
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 = auth: login: 'login' sublogin: 'optional' password: 'secret' ; sendsay
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.
})
Retrieve session from cookies
sendsay; // By default the cookie's name is 'sendsay_session'.
sendsay;
Set session manually.
sendsay.setSession('secret');
Simple request
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);
});
Configuration
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 = apiUrl: 'https://api.development.sendsay.ru'
apiUrl
(String)
Default: 'https://api.sendsay.ru'
The url to the Sendsay API server.
apiKey
(String)
The api key for authentication.
auth
(Object)
The auth credentials (login
, sublogin
, password
) for authentication.