Launch Brevz Application

Javascript SDK: Documentation

We explore the Brevz's SDK


When you integrate Brevz into your website, you'll have a new object available that'll allow you to drive Brevz engine, we call it the Javascript SDK.

It's purpose is for integration, we'll discover it's usages. It's a little limited right now, we are working on it.

BrevzSDK

Brevz's SDK is available client-side through: window.brevzSDK.

Changelogs Functions

These functions will only be usefull if you use the Changelog feature from Brevz.

show

Type: () => void

Effect to show the Brevz message panel.

Returns void;

Example
brevzSDK.show();

hide

Type: () => void

Effect to hide the Brevz message panel.

Returns void;

Example
brevzSDK.hide();

Notification Functions

These functions will only be usefull if you use the Notification feature from Brevz.

askNotification

Type: () => Promise<Either<Error, boolean>>

Ask for a notification from the browser, you can trigger this function to show the default notification asking prompt. If the result is true you can send a notification, if it's false you can't.

In a future release of the product, you'll be able to show a customized prompt.

The Either type is from the fp-ts ecosystem It's a simple union type which is described here

Returns Promise<Either<Error,boolean>>;

Example
const result = await brevzSDK.askNotification();
switch (result._tag) {
  case 'Left':
    console.log(result.value); // It'll be an Error
  case 'Right':
    // It's a boolean, if it's true we can send a notification.
    console.log(result.value);
}

Users Functions

These functions will allow you to add multiples data from your user which you'll be able to use in Brevz.

userData.setUser

Type: (user: UserProps) => void

type UserProps = {
  key?: string;
  firstname?: string;
  lastname?: string;
  // Must be an email or will not be saved by the server
  email?: string;
  // Must be a timezone or will not be saved by the server
  timezone?: string;
  avatar?: string;
  custom?: Record<string, string>;
}

With this function you'll be able to set everything you want for your user. It may not be immediately active, the Brevz' client-side runtime will save it to the server as soon as possible.

You must ensure the key your user use does not change every time he goes back to your website. If you do not use a key, it'll be assumed it's an anonymous user.

Each time a new browser set his user key to an existing one, we link this browser to our Brevz user, and the new data incoming from this new browser will be merge with the existing user.

Even if you know the key from a user, you can't get the data associated to it as a visitor.

Returns void;

Example
setUser({
  key: "a-unique-id",
  firstname: "Jane",
  lastname: "Doe",
  timezone: "Europe/Paris",
  custom: {
    awesome: ["some_awesome_data"],
  }
});

userData.setKey

Type: (key: string) => void

You must ensure the key your user use does not change every time he goes back to your website. If you do not use a key, it'll be assumed it's an anonymous user.

Each time a new browser set his user key to an existing one, we link this browser to our Brevz user, and the new data incoming from this new browser will be merge with the existing user.

Even if you know the key from a user, you can't get the data associated to it as a visitor. *This data is never transmitted to new users even if they give us the same key.*

Returns void;

Example
setKey("a-unique-key");

userData.getKey

Type: () => string | undefined

Get the registered key.

Returns string;

Example
getKey();

userData.setFirstname

Type: (firstname: string) => void

Set the firstname of your user.

Returns void;

Example
setFirstname("Jane");

userData.getFirstname

Type: () => string | undefined

Get the firstname of your user.

Returns string | undefined;

Example
getFirstname();

userData.setLastname

Type: () => string | undefined

Set the lastname of your user.

Returns void;

Example
setLastname("Doe");

userData.getLastname

Type: () => string | undefined

Get the lastname of your user.

Returns string | undefined;

Example
getLastname();

userData.setEmail

Type: (email: string) => void

Set the email of your user. Must be a valid email.

Returns void;

Example
setEmail("jane@doe.com");

userData.getEmail

Type: () => string | undefined

Get the email of your user.

Returns string | undefined;

Example
getEmail();

userData.setTimezone

Type: (timezone: string) => void

Set the timezone of your user. Must be a valid timezone.

Returns void;

Example
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
setTimezone(tz);

userData.getTimezone

Type: () => string | undefined

Get the timezone of your user.

Returns string | undefined;

Example
getTimezone(); // "Europe/Paris"

userData.setCustomData

Type: (key: string) => (value: string | number | boolean) => void

Set a custom data for this user with a key and a value.

Returns void;

Example
setCustomData('github_role')('admin');

userData.getCustomData

Type: (key: string) => () => Array<(string | number | boolean)> | string | number | boolean | undefined

Get a custom data for this user with a key.

Returns Array<(string | number | boolean)> | string | number | boolean | undefined;

Example
const role = getCustomData('github_role')();