UNPKG

2.43 kBMarkdownView Raw
1# [SupportKit Javascript SDK](supportkit.io)
2Build status: [![Circle CI](https://circleci.com/gh/supportkit/supportkit-js.svg?style=svg)](https://circleci.com/gh/supportkit/supportkit-js)
3## Usage
4
5### Script Tag
6
7Add the following code in between the ```<head>...</head>``` tags on your page.
8
9```html
10<script src="https://cdn.supportkit.io/supportkit.min.js"></script>
11```
12
13Initialize the plugin using this code snippet
14
15```html
16<script>
17 SupportKit.init({appToken: 'your_app_token'});
18</script>
19```
20
21### In Node.js and Browserify
22
23Install from npm
24
25```
26npm install supportkit-js
27```
28
29Require and init
30
31```javascript
32var SupportKit = require('supportkit-js');
33
34SupportKit.init({appToken: 'your_app_token'});
35```
36
37### Bower
38
39Install from bower
40
41```
42bower install supportkit-js
43```
44
45Include in JS using preferred method and init
46
47```javascript
48SupportKit.init({appToken: 'your_app_token'});
49```
50
51## API
52
53### Individual functions
54
55#### init(options)
56Initializes the SupportKit widget in the web page using the specified options
57
58```javascript
59SupportKit.init({
60 appToken: 'your_app_token',
61 givenName: 'Cool',
62 surname: 'Person',
63 email: 'their_email@whatever.com',
64 // Additional properties
65 properties: {
66 'anything': 'whatever_you_want'
67 }
68});
69```
70
71#### open()
72Opens the conversation widget
73
74```javascript
75SupportKit.open();
76```
77
78#### close()
79Closes the conversation widget
80
81```javascript
82SupportKit.close();
83```
84
85#### sendMessage(text)
86Sends a message on the user's behalf
87
88```javascript
89SupportKit.message('hello');
90```
91
92#### updateUser(user)
93Updates user information
94
95```javascript
96SupportKit.updateUser({
97 givenName: 'Updated',
98 surname: 'Name',
99 email: 'updated@email.com',
100 properties: {
101 'justGotUpdated': true
102 }
103});
104```
105
106### Events
107
108```
109// This event triggers when init completes successfully... Be sure to bind before calling init!
110SupportKit.on('ready', function(){
111 console.log('the init has completed!');
112});
113```
114
115## How to contribute
116
117### Clone the git repo
118```git clone https://github.com/supportkit/supportkit-js```
119
120### Install Node.js and run the following
121
122```npm install```
123```npm install -g grunt```
124
125### Essential Grunt Tasks
126
127* ```grunt build``` dumps a plain and a minified file from all files in the folder ```src``` to dist/supportkit.min.js
128* ```grunt clean``` removes all files in the folder ```dist```
129* ```grunt test:unit``` runs karma tests
130
\No newline at end of file