How to use the Watson Conversation inside iOS Swif

2019-08-16 03:02发布

问题:

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) {