@sobol/sdk
v2.0.0
Published
A SDK for writing Sobol apps.
Downloads
6
Keywords
Readme
@sobol/sdk
A JavaScript SDK for developing integrations with Sobol.
For our Starter App, see @sobol/app.
Installation
npm install @sobol/sdk
Webhook
To bootstrap a webhook, use the webhook
class as follows:
const Client = require('@sobol/client');
const Webhook = require('@sobol/sdk/webhook');
const {
WEBHOOK_MESSAGE_TYPE
} = require('@sobol/sdk/constants');
// === Configure Webhook ===
Webhook.configure({
url: 'https://example.com/production/events/sobol',
events: [
'goal:created',
'goal:updated',
'goal:deleted',
],
client: Client, // must be already configured
});
// === Event Handler ===
// - upon receiving some webhook event, verify handshake
const msg = '<some message object from sobol>';
const { type } = msg;
if (type === WEBHOOK_MESSAGE_TYPE.UrlVerification) {
Webhook.verify(msg); // perform handshake
} else {
console.log(msg);
}
Options
| Option | Type | Description | Default |
|------------------|----------|--------------------------------------------------------------|-------------------------------------------|
| url
| String | Webhook URL | ''
|
| events
| String | Webhook Events | []
|
| client
| Object | @sobol/client | |
Webhook Server
To bootstrap a webhook server, use the webhook/server
class as follows:
const Webhook = require('@sobol/sdk/webhook');
const WebhookServer = require('@sobol/sdk/webhook/server');
// === Server Setup ===
WebhookServer.configure({
port: 8080,
webhook: Webhook, // must be already configured
}, (/* server, app, router */) => {
// customize express app here
});
// === Register Webhook Handler ===
WebhookServer.registerWebhook((msg) => {
log(`[${APP_NAME}] ... sobol webhook event received:`, JSON.stringify(msg));
});
// === Start Server ===
WebhookServer.listen();
Options
| Option | Type | Description | Default |
|------------------|----------|--------------------------------------------------------------|-------------------------------------------|
| port
| Number | Port to listen | 8085
|
| prefix
| String | Prefix for route | /:env/events
|
| webhook
| Object | @sobol/sdk/webhook | |
Help and Feedback
For help and feedback, please send us an email to [email protected] and we will respond as soon as possible.