How to use the Watson Conversation inside iOS Swift?

你说的曾经没有我的故事 提交于 2019-12-24 20:34:11

问题


I am going to update my customised sample based on Build a home assistant mobile application with Watson and IoT Platform services

In this code I get the message:

Can not convert value of type 'String' to expected argument type 'InputData?'

How to solve this problem? Inside the documentation of developer cloud/conversation/api I can find the definition of InputData, but NO sample how to realize this in Swift iOS?

    // Based on API Changes
    // ====================
    // Incorrect argument label in call (have 'text:context:', expected 'input:context:')
    // Cannot convert value of type 'String' to expected argument type 'InputData?'
    let request = MessageRequest(input: text, context: self.context)
    self.conversation?.message(workspaceID: Credentials.ConversationWorkspaceID,
                               request: request,
                               failure: failure) {
                                response in
                                print(response.output.text)
                                self.didReceiveConversationResponse(response.output.text)
                                self.context = response.context
                                // issue command based on intents and entities
                                // Additional Properties:
                                // response.context.json -> response.context.additionalProperties
                                print("appl_action: \(response.context.additionalProperties["appl_action"])")
                                self.issueCommand(intents: response.intents, entities: response.entities)
    }

回答1:


The input parameter of the MessageRequest constructor takes an InputData object, which is easy to construct from a text string. Try

let input = InputData(text: text)
let request = MessageRequest(input: input, context: self.context)
self.conversation?.message(workspaceID: Credentials.ConversationWorkspaceID,
                           request: request,
                           failure: failure) {


来源:https://stackoverflow.com/questions/48223371/how-to-use-the-watson-conversation-inside-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!