Chat History
Table of contents
Overview
History management is out of the SDKs scope.
The SDK enables the Host app to provide its own implementation, and maintain an updated chat history, by listening to triggered events whenever chat elements changes.
You can checkout an implementation example here.
How is it done
The hosting App provides a ChatElementDelegate
implementation, on ChatController creation. This delegate should be fully implemented in order to be notified of all chat changes.
The SDK interacts with this delegate in order to fetch chat history on chat load, and to update history records, when chat elements were changed.
ChatElementDelegate overview
The ChatElementDelegate
will be used for the following operations.
-
Fetch chat elements from stored history on chat load.
CallingChatElementDelegate.fetch
-
Notifies of an addition of chat element to the chat.
CallingChatEleChatElementDelegatementListener.didReceive
-
Notifies of removal of stored element from the chat.
CallingChatElementDelegate.didRemoveChatElement
-
Notifies of an update on chat element data.
CallingChatElementDelegate.didUpdateChatElement
-
Notifies of an update on chat element feedabck.
CallingChatElementDelegate.didUpdateFeedback
Basic Implementation
The following classes/interfaces are the public API for history managment:
ChatController
- Use this class to setChatElementDelegate
.- Implement
StorableChatElement
to have your own storable chat element. (optional)
Register To Delegate
override func viewDidLoad() {
controller.chatElementDelegate = self
}
Implement ChatElementDelegate
extension HistoryDemoViewController: ChatElementDelegate {
func fetch(_ from: Int, handler: (([Any]?) -> Void)!) {
print("fetch")
}
func didReceive(_ item: StorableChatElement!) {
print("receive")
}
func didRemoveChatElement(_ timestampId: TimeInterval) {
print("remove")
}
func didUpdateChatElement(_ timestampId: TimeInterval, newTimestamp: TimeInterval, status: StatementStatus) {
print("update")
}
func didUpdateFeedback(_ articleId: String!, feedbackState: FeedbackStatus) {
print("feedback")
}
}