I am attempting to pass a context variable at the start of a conversation from my iOS Swift application to the Watson Conversation service. So far I have figured out you have to import RestKit to create the JSON object required and use the Context initializer. Below is a sample of the code I have to start the conversation (I have included the try! for brevity):
func startWatsonConv(){
var cvar = JSON(json: ["shotInfo":"Pneumovax"])
context = try! Context(json: cvar)
let failure = { (error: Error) in print(error) }
conversation.message(withWorkspace: conWorkspace, failure: failure) { response in
self.context = response.context
print ("start of conversation", response.context)
}
}
I am getting the following error in the console:
fatal error: 'try!' expression unexpectedly raised an error: RestKit.JSON.Error.keyNotFound("conversation_id"): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.63/src/swift/stdlib/public/core/ErrorType.swift, line 178
Any example of how to successfully pass this context variable would be greatly appreciated!