Help center
Your team writes help articles in PurrCRM and groups them in collections (Set up the inbox and help center). The SDK reads them for the user signed in, in their language where your team translated them; your app draws the help center’s first screen, the search, a collection and an article.
| Your screen | Its state |
|---|---|
| The first screen and the search | crm.helpCenter().state (HelpCenterState) |
| A collection | crm.collection(slug).state |
| An article, and “Did this help?” | crm.article(slug).state (ArticleState) |
Mount them where navigate sends them (Initialise): /help, /help/collections/<slug> and /help/<slug>. The help center is a part your team switches on for the app; crm.has("help_center") says whether the user has it.
The first screen and the search
Section titled “The first screen and the search”import { isSearch } from "crm-sdk";
const help = crm.helpCenter();const stop = help.state.subscribe((s) => { if (isSearch(s)) { drawResults(s.results, s.searching, s.searchMessage); // what the last search found } else { drawCollections(s.collections); // each with slug, title, description and how many articles drawFeatured(s.featured); } if (s.message !== null) drawFailure(s.message);});await help.load();
searchInput.oninput = () => help.search(searchInput.value);
// When the screen goes:stop();help.close();search(query) waits until the user stops typing (350 ms) before it asks, and an empty query clears the search. query is what was typed, searched the words the results are for, and searching is on while a search waits or is on its way. crm.helpCenter({ debounceMs: 500 }) waits longer.
A collection
Section titled “A collection”const collection = crm.collection(slug); // a CrmFetchcollection.state.subscribe(({ value, loading, message }) => { if (value !== null) drawCollection(value.collection, value.articles);});await collection.load();An article
Section titled “An article”import { drawnBlocks } from "crm-sdk";
const view = crm.article(slug);view.state.subscribe((s) => { if (s.article === null) return s.loading ? drawSpinner() : drawFailure(s.message); drawTitle(s.article.title); drawBlocks(drawnBlocks(s.article.blocks)); // see "Drawing rich text" below drawRelated(s.article.related); drawHelped(s.helpful, s.rating); // what the user said, and whether an answer is on its way});await view.load();
yesButton.onclick = () => view.rate(true); // it helpednoButton.onclick = () => view.rate(false);An Article has title, summary, blocks, its collection, related articles, language (the one it is in) and languages (those it has), and updatedAt. An article that is not there gives a message whose sentence is articleGone.
Drawing rich text
Section titled “Drawing rich text”Articles, posts, banners, a carousel’s screens and replies carry their words as ContentBlock[]. Each block has a type:
| Type | What it draws |
|---|---|
paragraph, heading (with level), eyebrow | Words, as spans |
bullets, numbers, checklist | A list of items, each with spans |
image | A picture: imageUrl, alt, aspect, fit, shape |
button | A button: label, link, style |
callout | A box with a tone (info, good, warn) |
divider, spacer, emoji | A line, a space of some size, a large emoji |
A Span is text with bold, italic, underline, strike, highlight, a color token and a link. drawnBlocks(blocks) leaves out a block of a type this SDK does not know, as PurrCRM means; plainText(blocks) is their words alone, a line each, for a preview or a screen reader’s summary. Follow a link with crm.openLink(link), and ask crm.linkTargetOf(link) first to draw one that goes nowhere as plain words (Links).
When there is nobody signed in
Section titled “When there is nobody signed in”The help center is read for a signed-in user. For readers who are not signed in, PurrCRM hosts a public help center of its own.