Created
April 21, 2019 13:51
-
-
Save kajornsakp/0b896f305bcff22ebdf5a058dc5d828d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func insertMessage(sender: Sender, text: String) { | |
let date = Date.init() | |
let message = Message(sender: sender, messageId: "1", sentDate: date, kind: .text(text)) | |
messages.append(message) | |
conversation.append(TextMessage(text: text, timestamp: date.timeIntervalSince1970, userID: sender.id, isLocalUser: isJohn)) | |
messagesCollectionView.reloadData() | |
handleSmartReply() | |
} | |
func handleSmartReply() { | |
naturalLanguage.smartReply().suggestReplies(for: conversation) { result, error in | |
guard error == nil, let result = result else { | |
return | |
} | |
if (result.status == .notSupportedLanguage) { | |
// The conversation's language isn't supported, so the | |
// the result doesn't contain any suggestions. | |
} else if (result.status == .success) { | |
// Successfully suggested smart replies. | |
// ... | |
let suggestions = result.suggestions.prefix(3).map{return $0.text} | |
let suggestionsView = suggestions.map { return self.makeButton(named: $0)} | |
self.messageInputBar.setStackViewItems(suggestionsView, forStack: .top, animated: true) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment