Help center
The help center is switched on for the app on PurrCRM (Help center, in the Name and features card on Settings › your app › General). It answers in the user’s language where your team translated the articles: the SDK asks in CrmConfig.languageTag’s language, the phone’s unless you set it, and crm.languages lists the languages your help center is written in.
What you draw: the help center’s first screen (collections, featured articles and a search box), a collection’s list of articles, an article, and its “Was this helpful?” question. Articles come as content blocks, never HTML: you draw each block natively, in your own type and colours.
The first screen
Section titled “The first screen”crm.help.state is a StateFlow<HelpCenterState>: collections, featured articles, loaded, loading and message (why the last read failed); and for the search, query (as typed), results, searching, searched (the query the results answer) and searchMessage. isSearch says whether to show the results rather than the collections.
crm.help.load()reads the collections and the featured articles together.crm.help.search(query)searches at once. Debounce typing yourself: an answer to a query since replaced is dropped, and an empty query clears the results.
@Composablefun HelpCenterScreen(crm: Crm, openArticle: (String) -> Unit, openCollection: (String) -> Unit) { val help by crm.help.state.collectAsState() var typed by remember { mutableStateOf("") } LaunchedEffect(Unit) { crm.help.load() } LaunchedEffect(typed) { delay(300) // debounce crm.help.search(typed) } Column { OutlinedTextField(value = typed, onValueChange = { typed = it }, label = { Text("Search for help") }) LazyColumn { if (help.isSearch) { items(help.results, key = { it.id }) { a -> ListItem(headlineContent = { Text(a.title) }, modifier = Modifier.clickable { openArticle(a.slug) }) } } else { items(help.collections, key = { it.id }) { c -> ListItem( headlineContent = { Text(c.title) }, supportingContent = { Text("${c.articles} articles") }, modifier = Modifier.clickable { openCollection(c.slug) }, ) } } } }}A Collection has its slug, title, description and the number of articles; an ArticleSummary its slug, title, summary, collection and updatedAt.
A collection
Section titled “A collection”crm.help.collectionFetcher(slug) is a Fetcher<CollectionArticles>: call load(), and observe state (value, loading, message). value has the collection and its articles.
An article
Section titled “An article”crm.help.articleSession(slug) answers an ArticleSession for your article screen:
load()reads it (again);state(ArticleState) has thearticle,loadingandmessage;rate(helpful)answers “Was this helpful?”, once at a time and only once the article is read;helpfulis the answer PurrCRM kept (null before one),ratingis true while one is on its way, andrateMessagesays why one failed;close()when the screen goes.
An Article has its title, summary, blocks, collection, related articles, updatedAt, and the language it is in of the languages it was written in.
Drawing content blocks
Section titled “Drawing content blocks”Articles, posts, banners, carousels and ticket descriptions are lists of ContentBlocks. Draw each by its type, and skip a type you do not know (drawnBlocks(blocks) leaves them out), so a block a later PurrCRM adds never breaks your screen:
BlockType | Fields | Draw |
|---|---|---|
Paragraph | spans | A paragraph |
Heading | level (1 to 3), spans | A heading |
Bullets, Numbers, Checklist | items (each with its spans) | A list |
Image | imageUrl, alt, link | A picture; alt as its content description |
Button | label, link | A button |
Divider, Spacer | size for a spacer | A line, or space |
Eyebrow | spans | A small label above a heading |
Callout | spans, emoji, tone or color | A tinted box |
Emoji | emoji | A large emoji |
A Span is a run of text with bold, italic, underline, strike, highlight, a color and a link. In a carousel or a post, a block may also carry size, color, align, weight, aspect, fit, shape and style; elsewhere they are empty, and your defaults apply. A color is a ColorToken word (accent, ink, muted…) to map to your theme, or a fixed #rrggbb. plainText(blocks) is the words alone, for a preview.
Follow a span’s or a button’s link with crm.openLink(link): one of PurrCRM‘s pages opens through navigate, a path of your app’s through followable and openInApp, and an https address in the browser. In an in-app message, use the message’s own calls instead (In-app messages).
Reading without state
Section titled “Reading without state”For a screen that keeps its own state, the same reads answer at once, and throw the CrmFailure they end with: crm.help.collections(), crm.help.collection(slug), crm.help.featured(), crm.help.find(query), crm.help.article(slug) and crm.help.rate(slug, helpful).
Opened by a link
Section titled “Opened by a link”A link to /help, /help/collections/<slug> or /help/<slug>, in a reply, a push or a message, reaches your navigate hook as CrmPlace.HelpCenter, Collection or Article, with the slug as its id (Initialise).