KBProvider
KBProvider Class reference for Kustomer Chat iOS Core API .
public class KBProvider
kb
Get articles and categories for the root of the Knowledge Base.
let kb = KBProvider.shared
kb.getArticlesAndCategories(completion: { r in
switch r {
case .success(let items):
kdump(items)
case .failure(let error):
kdump(error)
}
})
kb.getArticlesAndCategories
Get articles and categories whose parent is categoryId
kb.getArticlesAndCategories(parentCategoryId: "123", completion: •)
Search for articles and categories
kb.getArticlesAndCategories(searchText: "red", completion: •)
kb.getArticle
Get article.
kb.getArticle(id: "5ec9b137c07af60013270753", completion: { r in
switch r {
case .success(let article):
kdump(article)
case .failure(let error):
kdump(error)
}
})
kb.getCategory
Get category.
kb.getCategory(id: “5ec9b138c07af60013270758”, completion: { r in switch r { case .success(let category): kdump(category) case .failure(let error): kdump(error) } })
kb.update
The Knowledge Base is stored entirely in a local data store. The first time you make a request for KB data, the local data store is populated.
Manually populates the Knowledge Base.
kb.update({ result in
switch result {
case .success:
kprint("updated. lastUpdateAt is now \(kb.lastUpdateAt)")
case .failure(let error):
kprint(error.localizedDescription)
}
})
kb.clearLocalDataStore()
Manually clears the Knowledge Base.
kb.clearLocalDataStore()
kb.hasNeverUpdated
Info about the local data store. See kb.lastUpdateAt.
kb.lastUpdateAt
Info about the local data store.
If the data store has been loaded at least once, you must manage updating it periodically on your own.
completeObject()
Extended KB article properties and category properties
There are many extended attributes for articles and categories. the completeObject()
method on KUSKBArticle and KUSKBCategory objects lets you access this. The rawJSON
property is the same, but not parsed into a dictionary.
Article properties: https://apidocs.kustomer.com/?version=latest#959b0560-da94-41bc-965f-234d0025c5aa
Category properties: https://apidocs.kustomer.com/?version=latest#0f9a0b2d-9d26-4f7d-abd1-1f3f0102958b
shared
public static let shared: KBProvider
The central object for managing Kustomer Knowledge Base-related activities.
Getting Knowledge Base data
getArticlesAndCategories(parentCategoryId:searchText:completion:)
Searches for articles and categories with the parent category id passed. If the parent category id is nil, searches for articles and categories belonging to the root category. To filter by a search string, pass a searchText
parameter.
See also KUSKBItemBase.
public func getArticlesAndCategories(parentCategoryId: String? = nil, searchText: String? = nil, completion: @escaping ((Result<[KUSKBItemBase], KError>) -> Void))
getArticle(id:completion:)
public func getArticle(id: String, completion: @escaping ((Result<KUSKBArticle, KError>) -> Void))
Gets a KUSKBArticle from the local database.
See also KUSKBArticle.
getCategory(id:completion:)
public func getCategory(id: String, completion: @escaping ((Result<KUSKBCategory, KError>) -> Void))
Gets a KUSKBCategory from the local database.
See also KUSKBCategory.
Updating
lastUpdateAt
Last time the local Knowledge Base data store was completely refreshed
public var lastUpdateAt: Date? { get }
hasNeverUpdated
If true, the Knowledge Base data store is empty and you’ve never asked the server for the data
public var hasNeverUpdated: Bool { get }
update(_:)
Updates the local Knowledge Base data store
public func update(_ completion: @escaping ((Result<Void, KError>) -> Void))
clearLocalDataStore()
Clears entire local data store
public func clearLocalDataStore()
Updated almost 4 years ago