Search code examples
swiftibm-cloudwatson-conversation

How can I access Bluemix Conversation variables from Swift


I have defined a Conversation dialog, in which I set the variable repeat in one node:

{
  "output": {
    "text": "You said: <?input_text?>. Let's fix the @product. "
  },
  "context": {
    "repeat": "<?input.text?>"
  }
}

and have displayed the variable $repeat in a subsequent node:

{
  "output": {
    "text": "repeat: $repeat"
  }
}

How can I access this variable $repeat in Swift? I can access response.input.text, which contains the same text, but I'd like to access $repeat, in order to be more flexible.

Input:

radio broken

Output:

You said: radio broken. Let's fix the radio.
repeat: radio broken

Swift code: var context: Context? // initial definition ...

func next_dialog(input_text: String) {
    conversation = Conversation(username: username, password: password, version: version)
    let failure = { (error: NSError) in print(error) }
    conversation.message(workspaceID, text: input_text, context: self.context, failure: failure) { response in 
         self.context = response.context  // update with response.context

...

Context:

enter image description here


Solution

  • Unfortunately, the Watson Developer Cloud iOS SDK does not currently support accessing user-defined context variables from the Conversation service. It's a feature that we are working on, though, and hope to release soon.

    The best place to track progress is by following this GitHub issue.

    It's not a solution, but I hope that helps!