2017-11-30 19 views
4

username、emailなどdialogflow(api.ai)にいくつかのパラメータを送信しようとしていますが、わかりませんでした。問題は、Dialogflow v2 Nodejs SDKで特定のデータ(ユーザー名、電子メールなど)を取得/設定できないことです。 queryParams.payload(v1:originalRequest)を使用しようとしましたが、何とか機能しませんでした。また、のカスタムイベントをデータでトリガーしようとしましたが、応答のイベントデータを取得できませんでした。誰かがdialogFlowでセッショントークのための特定のデータを送信する方法を知っていますか?ダイアログフローのパラメータをwebhookに送信するsdk v2

例EVENT

const projectId = 'test-bot-test-1111'; 
    const sessionId = user.uuid; 
    const languageCode = 'en-GB'; 

    const sessionClient = new dialogFlow.SessionsClient(); 
    const sessionPath = sessionClient.sessionPath(projectId, sessionId); 

const request = { 
    session: sessionPath, 
    queryInput: { 
     event: { 
     name: 'custom_event', 
     languageCode, 
     parameters: { 
      name: 'sam', 
      user_name: 'sam', 
      a: 'saaaa' 
     } 
     } 
    }, 
    queryParams: { 
     payload: { 
     data: user 
     } 
    } 
    }; 

    let resultReq; 

    console.log('request :: ', request, '\n\n'); 

    try { 
    resultReq = await sessionClient.detectIntent(request); 
    } catch (err) { 
    // eslint-disable-next-line no-console 
    return console.error('ERROR:', err); 
    } 

答えて

3

の例

const projectId = 'test-bot-test-1111'; 
    const sessionId = user.uuid; 
    const languageCode = 'en-GB'; 

    const sessionClient = new dialogFlow.SessionsClient(); 
    const sessionPath = sessionClient.sessionPath(projectId, sessionId); 

    const request = { 
    session: sessionPath, 
    queryInput: { 
     text: { 
     text: query, 
     languageCode 
     } 
    }, 
    queryParams: { 
     payload: { 
     data: { 
      username: 'bob', 
      email: '[email protected]' 
     } 
     } 
    } 
    }; 

    let resultReq; 

    console.log('request :: ', request, '\n\n'); 

    try { 
    resultReq = await sessionClient.detectIntent(request); 
    } catch (err) { 
    // eslint-disable-next-line no-console 
    return console.error('ERROR:', err); 
    } 

ペイロードのDialogflowのV2 APIはgRPCを使用し、あなたがに実行したそのうちの一ついくつかの癖を持っています。 Node.jsライブラリのサンプルを見ると、これを回避する方法が分かります。 jsonToStructProtoメソッドをインプリメントしてJavaScriptオブジェクトをproto構造体に変換するか、the structjson.js file in the sampleをコピーする必要があります。以下はstructjson.jsファイルを使用した完全に動作する例です:

// Imports the Dialogflow library 
const dialogflow = require('dialogflow'); 

// Import the JSON to gRPC struct converter 
const structjson = require('./structjson.js'); 

// Instantiates a sessison client 
const sessionClient = new dialogflow.SessionsClient(); 

// The path to identify the agent that owns the created intent. 
const sessionPath = sessionClient.sessionPath(projectId, sessionId); 

// The text query request. 
const request = { 
    session: sessionPath, 
    queryInput: { 
    event: { 
     name: eventName, 
     parameters: structjson.jsonToStructProto({foo: 'bar'}), 
     languageCode: languageCode, 
    }, 
    }, 
}; 

sessionClient 
    .detectIntent(request) 
    .then(responses => { 
    console.log('Detected intent'); 
    logQueryResult(sessionClient, responses[0].queryResult); 
    }) 
    .catch(err => { 
    console.error('ERROR:', err); 
    }); 
+0

ありがとう! –

関連する問題