runtime-less-stuff
v1.2.1
Published
Javascript wrapper for Smooch API
Downloads
2
Readme
Smooch Core
Smooch Core is the most basic for interaction possible for the Smooch API. It wraps the public API in a convenient Javascript API.
This library is meant to be isomorphic, which means it can be used in the browser and server-side with Node.js. However, the webhooks API and the JWT utils are not available in the browser to reduce the bundle size. Those actions should not be done in the browser anyway.
Installation
$ npm install smooch-core --save
Usage
In the browser (using browserify or webpack)
var SmoochCore = require('smooch-core');
// using app token
var smoochCore = new SmoochCore({
appToken: 'some-token'
});
// using generated JWT
var smoochCore = new SmoochCore({
jwt: 'some-jwt'
});
// ...
smoochCore.appUsers.init(options).then(function(response) {
// do something with the response.
});
Server-side
var SmoochCore = require('smooch-core');
// using app token
var smoochCore = new SmoochCore({
appToken: 'some-token'
});
// using generated JWT
var smoochCore = new SmoochCore({
jwt: 'some-jwt'
});
// using JWT components
// Only available server-side. NEVER put your keyId and secret
// in you client-side code.
var smoochCore = new SmoochCore({
keyId: 'some-key',
secret: 'some-secret',
scope: 'appUser', // app or appUser
userId: 'some-id' // not necessary if scope === 'app'
});
// ...
smoochCore.webhooks.get(id).then(function(response) {
// do something with the response.
});
API
This is an overview of what the library has to offer. A better documentation will be available soon.
| Module | Method | Endpoint |
|-------- |-------- |-------------|
| appUsers | init | POST /v1/init
|
| | get | GET /v1/appusers/:id
|
| | update | PUT /v1/appusers/:id
|
| | trackEvent | POST /v1/appusers/:id/events
|
| conversations | get | GET /v1/appusers/:id/conversation
|
| | sendMessage | POST /v1/appusers/:id/conversation/messages
|
| webhooks | list | GET /v1/webhooks
|
| | create | POST /v1/webhooks
|
| | get | GET /v1/webhooks/:id
|
| | update | PUT /v1/webhooks/:id
|
| | delete | DELETE /v1/webhooks/:id
|