Я создаю чат-бота в реактивном режиме с использованием IBM Watson Assistant. Поскольку хорошей библиотеки не было, я решил создать мост самостоятельно.
Итак, проблема, с которой я сталкиваюсь здесь, в iOS, я могу получить ответ, но я хочу, чтобы он был в формате json. Я пользуюсь swift 4.
Формат, который я получаю:
(input: Optional(AssistantV1.MessageInput(text: Stupid)), intents: [], entities: [], alternateIntents: nil, context: AssistantV1.Context(conversationID: Optional("2380129380139312kjh123"), system: Optional(AssistantV1.SystemResponse(additionalProperties: ["_node_output_map": RestKit.JSON.object(["Welcome": RestKit.JSON.object(["1": RestKit.JSON.array([RestKit.JSON.int(0), RestKit.JSON.int(0), RestKit.JSON.int(1), RestKit.JSON.int(2)])])]), "initialized": RestKit.JSON.boolean(true), "branch_exited": RestKit.JSON.boolean(true), "dialog_stack": RestKit.JSON.array([RestKit.JSON.object(["dialog_node": RestKit.JSON.string("root")])]), "dialog_turn_counter": RestKit.JSON.int(1), "dialog_request_counter": RestKit.JSON.int(1), "branch_exited_reason": RestKit.JSON.string("completed")])), additionalProperties: ["error_question": RestKit.JSON.string(""), "my_name": RestKit.JSON.string("username"), "my_email": RestKit.JSON.string("useremail"), "my_credentials": RestKit.JSON.object(["password": RestKit.JSON.string("3120834hbdi37dyd"), "user": RestKit.JSON.string("uwq9383ueh9833298e")]), "err_cnt": RestKit.JSON.int(0)]), output: AssistantV1.OutputData(logMessages: [], text: ["Sorry, I am constantly learning."], generic: Optional([AssistantV1.DialogRuntimeResponseGeneric(responseType: "image", text: nil, time: nil, typing: nil, source: Optional("someurl"), title: nil, description: nil, preference: nil, options: nil, messageToHumanAgent: nil, topic: nil, suggestions: nil), AssistantV1.DialogRuntimeResponseGeneric(responseType: "text", text: Optional("Sorry, I am constantly learning."), time: nil, typing: nil, source: nil, title: nil, description: nil, preference: nil, options: nil, messageToHumanAgent: nil, topic: nil, suggestions: nil)]), nodesVisited: Optional(["Welcome"]), nodesVisitedDetails: nil, additionalProperties: [:]), actions: nil, additionalProperties: [:])
Формат, который я хочу:
{"entities":[],"output":{"generic":[{"source":"someurl","response_type":"image"},{"response_type":"text","text":"Sorry, I am constantly learning."}],"text":["Sorry, I am constantly learning."],"nodes_visited":["node_1_1535596064008"],"log_messages":[]},"intents":[{"intent":"Negative_Feedback","confidence":1}],"context":{"system":{"dialog_turn_counter":3,"initialized":true,"dialog_stack":[{"dialog_node":"root"}],"dialog_request_counter":3,"_node_output_map":{"node_2_1536025247756":{"0":[0]},"Welcome":{"1":[0,0,1,2]},"node_1_1535596064008":{"1":[0,0]}},"branch_exited":true,"branch_exited_reason":"completed"},"my_name":"username","err_cnt":0,"conversation_id":"13212230293","error_question":"","my_email":"useremail","my_credentials":{"user":"123192312b3283y12b129","password":"dadu8sdsadjb283"}},"input":{"text":"Stupid"}}