如何从 Swift 访问 Bluemix Conversation 变量

How can I access Bluemix Conversation variables from Swift

我定义了一个对话对话框,在其中我在一个节点中设置了变量 repeat:

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

并在后续节点中显示变量 $repeat:

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

如何访问 Swift 中的变量 $repeat? 我可以访问 response.input.text,其中包含相同的文本,但我想访问 $repeat,以便更加灵活。

输入:

radio broken

输出:

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

Swift代码: var 上下文:上下文? // 初始定义 ...</p> <pre><code>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

...

上下文:

好的,根据您所展示的内容,我相信您正在做的是从 Conversation 中设置上下文变量。

但是状态需要在应用层维护。所以你需要在你的对话输入中发送上下文变量,否则它不会被发回。

如果不是这种情况,那么您需要再次使用示例输入 + 输出更新您的问题。

遗憾的是,Watson Developer Cloud iOS SDK 目前不支持从对话服务访问用户定义的上下文变量。不过,这是我们正在努力的一项功能,希望尽快发布。

跟踪进度的最佳位置是关注 this GitHub issue

这不是解决方案,但希望对您有所帮助!