Skip to content

Instantly share code, notes, and snippets.

@kajornsakp
Created April 21, 2019 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kajornsakp/0b896f305bcff22ebdf5a058dc5d828d to your computer and use it in GitHub Desktop.
Save kajornsakp/0b896f305bcff22ebdf5a058dc5d828d to your computer and use it in GitHub Desktop.
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