npm

Need private packages and team management tools?Check out npm Orgs. »

This package has been deprecated

Author message:

SupportKit is now Smooch! Please use https://www.npmjs.com/package/smooch

supportkit

1.0.0 • Public • Published

SupportKit Javascript SDK

SupportKit adds beautifully simple messaging to your app to keep your users engaged and coming back.

Circle CI npm version Bower version

Usage

Script Tag

Add the following code towards the end of the body section on your page. Placing it at the end allows the rest of the page to load first.

<script src="https://cdn.supportkit.io/supportkit.min.js"></script>

Initialize the plugin using this code snippet

<script>
    SupportKit.init({appToken: 'your_app_token'});
</script> 

In Node.js and Browserify

Install from npm

npm install supportkit

Require and init

var SupportKit = require('supportkit');
 
SupportKit.init({appToken: 'your_app_token'});

Bower

Install from bower

bower install supportkit

Include in JS using preferred method and init

SupportKit.init({appToken: 'your_app_token'});

API

Individual functions

init(options)

Initializes the SupportKit widget in the web page using the specified options. It returns a promise that will resolve when the widget is ready.

var skPromise = SupportKit.init({
    appToken: 'your_app_token',
    givenName: 'Cool',
    surname: 'Person',
    email: 'their_email@whatever.com',
    // For secure mode
    jwt: 'your_jwt',
    userId: 'user_id',
    // Additional properties
    properties: {
        'anything': 'whatever_you_want'    
    }
});
 
 
skPromise.then(function() {
    // do something
});
 
// pass it around...
 
skPromise.then(function() {
    //do something else
});
 
 

open()

Opens the conversation widget

SupportKit.open();

close()

Closes the conversation widget

SupportKit.close();

login(userId [, jwt])

Logs a user in the widget, retrieving the conversation that user already had on other browsers and/or devices. This will destroy and reinitialize the widget with the user's data. Note that you don't need to call this after init, it's already done internally. This returns a promise that resolves when the widget is ready again.

SupportKit.login('some-id');

// in case you are using the jwt authentication
SupportKit.login('some-id', 'some-jwt');

logout()

Logs out the current user and reinitialize the widget with an anonymous user.This returns a promise that resolves when the widget is ready again.

SupportKit.logout();

destroy()

Destroys the widget and makes it disappear. The widget has to be reinitialized with init to be working again because it also clears up the app token from the widget.

SupportKit.destroy();

sendMessage(text)

Sends a message on the user's behalf

SupportKit.message('hello');

updateUser(user)

Updates user information

SupportKit.updateUser({
    givenName: 'Updated',
    surname: 'Name',
    email: 'updated@email.com',
    properties: {
      'justGotUpdated': true
    }
});

track(eventName)

Tracks an event for the current user.

SupportKit.track('item-in-cart');

Events

If you want to make sure your events are triggered, try to bind them before calling SupportKit.init.

ready

// This event triggers when init completes successfully... Be sure to bind before calling init!
SupportKit.on('ready', function(){
    console.log('the init has completed!');
});

SupportKit.init(...);

destroy

// This event triggers when init completes successfully... Be sure to bind before calling init!
SupportKit.on('destroy', function(){
    console.log('the widget is destroyed!');
});

SupportKit.destroy();

How to contribute

Clone the git repo

git clone https://github.com/supportkit/supportkit-js

Install Node.js and run the following

npm install npm install -g grunt

Essential Grunt Tasks

  • grunt build dumps a plain and a minified file from all files in the folder src to dist/supportkit.min.js
  • grunt clean removes all files in the folder dist
  • grunt test:unit runs karma tests

install

npm i supportkit

Downloadsweekly downloads

33

version

1.0.0

license

http://supportkit.io/terms.html

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability