Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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:

import Sendsay from 'sendsay-api';

Or, if you're not using ES6 modules:

const Sendsay = require('sendsay-api');

CDN

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

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']);
})

Usage

Authentication

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.
})

Retrieve session from cookies

sendsay.setSessionFromCookie(); // By default the cookie's name is 'sendsay_session'.
sendsay.setSessionFromCookie('custom_cookie_name'); 

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 = new 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.

About

Official Sendsay Javascript Client

Resources

License

Stars

Watchers

Forks

Packages

No packages published