Skip to content

Help center

The help center is your team’s articles, grouped in collections, written on PurrCRM (Set up the inbox and help center). The SDK fetches them; you draw the pages, and keep each page’s own state (loading, the results, the query).

Its places are .helpCenter, .collection and .article, with the slug as id: navigate is asked to open them from a link in a reply, a bot’s suggestion, a push or your own menu (Initialise). The help center needs the part switched on (crm.has(.helpCenter)).

crm.help is a CrmHelp. Each call throws a CrmFailure when it cannot answer:

CallAnswers
collections()[Collection]: slug, title, description, and how many articles.
collection(slug)CollectionArticles: the collection and its articles.
featured()[ArticleSummary]: the featured articles, for the help center’s front.
search(query)[ArticleSummary] matching the query; the featured ones for an empty query.
article(slug)Article: title, summary, blocks to draw, its collection, related articles, updatedAt, and its language among languages.
rate(slug, helpful:)Says whether the article helped.

Articles come in the user’s language (CrmConfig.languageTag) where your team translated them.

HelpViewController.swift
final class HelpViewController: UITableViewController, UISearchResultsUpdating {
private var articles: [ArticleSummary] = []
private var searching: Task<Void, Never>?
override func viewDidLoad() {
super.viewDidLoad()
Task { await show { try await crm.help.featured() } }
}
func updateSearchResults(for controller: UISearchController) {
let query = controller.searchBar.text ?? ""
searching?.cancel()
searching = Task {
try? await Task.sleep(nanoseconds: 300_000_000) // wait for the typing to settle
if Task.isCancelled { return }
await show { try await crm.help.search(query) }
}
}
private func show(_ load: () async throws -> [ArticleSummary]) async {
do {
articles = try await load()
} catch {
showFailure(tellCrmFailure(error, attempt: .help))
}
tableView.reloadData()
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Task { await crm.open(.article(articles[indexPath.row].slug)) }
}
}

Debounce the search as the user types: the SDK sends each call you make.

An article’s blocks are drawn as in-app messages’ are (Content blocks); a link in one goes through crm.openLink(_:), which opens another article, one of PurrCRM‘s places, a place of yours or a web page. An article that is gone fails with a CrmProblem whose sentence for .help is .articleGone.

Ask “Did this help?” at the article’s foot, and send the answer with try await crm.help.rate(slug, helpful: true).