Skip to content

The web SDK

crm-sdk puts PurrCRM inside your website or web app. It is headless: it talks to PurrCRM and keeps the state, and your app draws every screen, with whatever it is built with (React, Vue, Svelte, plain DOM). You hand it your signed-in user’s token, and it does the rest:

  • In-app messages: banners, posts, carousels and surveys your team writes. The SDK checks in for them, decides which shows next, walks a carousel or a survey as your team drew it, and tells PurrCRM what people did with each.
  • The messenger: conversations with your team, replies arriving live while a conversation is open, typing and Seen, pictures and files, ratings, a help bot, the user’s tickets and new tickets from your team’s forms.
  • The help center: collections, featured articles, search and articles, in the user’s language.
  • Product events: the page opening and closing, screens, permission changes, taps on pushes and links opened, sent in batches by itself, plus events of your own.
  • Pushes: web pushes through your Firebase project; it recognises PurrCRM‘s, keeps the unread counts right, and opens the page a tapped push names. Every push is also kept in an inbox of notices.
  • Links: links into your app that your team saves, emails’ clicks, links your users share, and referrals.
  • Preferences: the user’s consent to offers by push, and the topics they hear about.

The one thing the SDK draws itself is the setup check, a panel for developers that shows only when you turn debug on.

The SDK hands you plain, typed, read-only objects and calls to make; how they look is yours.

You drawFrom
The unread badgecrm.unread
The messenger’s home: open conversations, reply time, cards, featured articles, ticketscrm.messenger.state
A conversation: its parts, the composer, pictures, the help bot’s buttons, a rating promptcrm.conversation(id).state
The tickets, and one ticketcrm.tickets(), crm.ticket(id)
The help center, a search, a collection, an articlecrm.helpCenter(), crm.collection(slug), crm.article(slug)
Banners, posts, carousels and surveyscrm.inApp.banner, crm.inApp.next, crm.inApp.carousel(m), crm.inApp.survey(m)
The inbox of notices and its bellcrm.notices
A preferences screencrm.preferencesEditor()
The words for a failuremessage.sentence, a kind such as offline or signInAgain, never the words

Every piece of state is a Value<T>: value is what it is now, and subscribe(listener) calls the listener at once and on every change, and answers the function that stops it. That one small type binds to any UI library. In React, for example:

src/useValue.ts
import { useSyncExternalStore } from "react";
import type { Value } from "crm-sdk";
export function useValue<T>(v: Value<T>): T {
return useSyncExternalStore(
(changed) => v.subscribe(() => changed()),
() => v.value,
() => v.value, // on the server
);
}
src/MessagesButton.tsx
import { crm } from "./crm";
import { useValue } from "./useValue";
export function MessagesButton() {
const unread = useValue(crm.unread);
return (
<a href="/messages">
Messages {unread > 0 && <span className="badge">{unread}</span>}
</a>
);
}

The SDK has no words of its own either (apart from the setup check’s): the strings your users read are yours, in your languages.

  • A browser from 2018 or later: Chrome and Edge 66, Firefox 60, Safari 12.1 (iOS 12.2). The package is ES2017.
  • https (or localhost while you develop) for web pushes and for declaring your app’s places to your team: both need a secure context.
  • Your PurrCRM address, https://app.purrcrm.com, and your app’s key, from the App key card on Settings › your app › Developers › Install.
  • Your site named under Web origins on the same page (Install).
  • A backend that signs a short token for your signed-in users (Sign users in).
  • For pushes, Firebase’s JavaScript SDK and a service worker of yours (Push).
  1. Install the package, and name your site in Web origins.
  2. Initialise it as your app starts.
  3. Sign users in.
  4. Turn on debug and open the setup check: it says what is wired and what is not.
  5. Check it works: the setup list on PurrCRM‘s overview ticks Install the SDK in a build when the first request from your app arrives, and names the SDK it saw, such as “Web 0.3.0”.

Then add what you need: push, links, the messenger, the help center, in-app messages, events, preferences and test mode.

API at a glance lists every public type and member. Setting up the rest of PurrCRM for your app is in Set up your app.