2017-12-06 9 views
-1

私は、パラメータの摂取を必要とするチャットボットアプリケーションを作成しており、ペイロード経由で送信されたポストリクエストでこれらのパラメータを使用します。どのように私は会話中のコンテキスト変数を取得し、私の迅速なプログラムでそれを使用できますか?

私は、コンテキスト変数からコンテキスト変数を取得する際に問題があり、コンテキスト変数の値を取得し、そのコンテキストの値に基づいてアクションを実行する方法について不思議でした。

この例は次のダイアログの流れのようになり...

ミー:この

ボットをトリガ:[OK]を、私に与えるの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" } 

OBS:input.textは、すべてそのユーザーの種類をキャプチャします、あなたは私を見てみてください、正確に何をしたいの抽出物のための正規表現を使用する必要がありますthis answerの例

そして、iOSの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ワトソンデベロッパークラウド
関連する問題