2017-12-06 12 views
-1

그래서 필자는 매개 변수 섭취가 필요한 대화방 응용 프로그램을 작성하고 페이로드를 통해 전송 된 게시 요청에서이 매개 변수를 사용합니다.컨텍스트 변수 중반 대화를 잡아 내 신속한 프로그램에서 어떻게 사용할 수 있습니까?

신속한 컨텍스트 변수에서 컨텍스트 값을 가져 오는 데 문제가 있으며 컨텍스트 변수의 값을 가져 와서 해당 컨텍스트의 값을 기반으로 작업을 실행하는 방법에 대해 궁금합니다.

이의 예는 다음과 같은 대화 흐름을 것 ...

나 :이

봇 트리거 : 좋아, 나에게 줄 PARAM X

나 : X

봇 : 좋아요. 저는 x param을 가지고 있습니다. 이제는 직장을 게시 할 것입니다.

이것은 응용 프로그램 백그라운드에서 백그라운드에서 일어나는 일종의 흐름입니다. 그러나 잡는 방법을 모르겠습니다. 값 x는 내 사용자가 입력 한 후입니다.

+0

스택 오버플로에 오신 것을 환영합니다. [둘러보기] (https://stackoverflow.com/tour)를 보내주십시오. – Xcoder

답변

0

왓슨 개발자 클라우드에서 iOS SDK을 사용한다고 가정합니다. 당신의 대화에

, 노드에 추가 :

{ 
    "context": { 
    "myVariable": "<? input.text ?>" 
    }, 
    "output": { 
    "text": { 
     "values": [ 
     "My context variable value is $myVariable." 
     ], 
     "selection_policy": "sequential" 
    }, { "etc": "etc" } 

것을 제외 : input.text는 모든 사용자 유형을 캡처합니다, 당신은 정확하게 당신이 원하는 무엇을 보려고 추출물에 대한 정규식을 사용할 필요가 내 this answer의 예. 이 예에 따라 볼 수있는 아이폰 OS SDK에

그리고 : 그래서

func testMessage() { 
    let description1 = "Start a conversation." 
    let expectation1 = self.expectation(description: description1) 

    let response1 = ["Hi. It looks like a nice drive today. What would you like me to do?"] 
    let nodes1 = ["node_1_1467221909631"] 

    var context: Context? 
    conversation.message(workspaceID: workspaceID, failure: failWithError) { 
     response in 

     // verify input 
     XCTAssertNil(response.input?.text) 

     // verify context 
     XCTAssertNotNil(response.context.conversationID) 
     XCTAssertNotEqual(response.context.conversationID, "") 
     XCTAssertNotNil(response.context.system) 
     XCTAssertNotNil(response.context.system.additionalProperties) 
     XCTAssertFalse(response.context.system.additionalProperties.isEmpty) 

     // verify entities 
     XCTAssertTrue(response.entities.isEmpty) 

     // verify intents 
     XCTAssertTrue(response.intents.isEmpty) 

     // verify output 
     XCTAssertTrue(response.output.logMessages.isEmpty) 
     XCTAssertEqual(response.output.text, response1) 
     XCTAssertEqual(response.output.nodesVisited!, nodes1) 

     context = response.context 
     expectation1.fulfill() 
    } 

, 당신은 사용하여 환경 변수에 액세스 할 수 있습니다

  • context.myVariable 
    response.context.myVariable 
    
    왓슨 회화에 methods에 대한 자세한 내용을 참조하십시오 이리.
  • iOS SDK (Watson Developer Cloud)