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.
What you draw
Section titled “What you draw”The SDK hands you plain, typed, read-only objects and calls to make; how they look is yours.
| You draw | From |
|---|---|
| The unread badge | crm.unread |
| The messenger’s home: open conversations, reply time, cards, featured articles, tickets | crm.messenger.state |
| A conversation: its parts, the composer, pictures, the help bot’s buttons, a rating prompt | crm.conversation(id).state |
| The tickets, and one ticket | crm.tickets(), crm.ticket(id) |
| The help center, a search, a collection, an article | crm.helpCenter(), crm.collection(slug), crm.article(slug) |
| Banners, posts, carousels and surveys | crm.inApp.banner, crm.inApp.next, crm.inApp.carousel(m), crm.inApp.survey(m) |
| The inbox of notices and its bell | crm.notices |
| A preferences screen | crm.preferencesEditor() |
| The words for a failure | message.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:
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 );}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.
Requirements
Section titled “Requirements”- A browser from 2018 or later: Chrome and Edge 66, Firefox 60, Safari 12.1 (iOS 12.2). The package is ES2017.
- https (or
localhostwhile 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).
Where to start
Section titled “Where to start”- Install the package, and name your site in Web origins.
- Initialise it as your app starts.
- Sign users in.
- Turn on
debugand open the setup check: it says what is wired and what is not. - 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.