2017-12-18 180 views
0

我試圖讓火力地堡的用戶ID來我的谷歌用戶,但顯然它是不確定的獲取用戶ID GoogleActions

dialogflowFirebaseFulfillment 
ReferenceError: userId is not defined 
    at IncomingMessage.resp.on (/user_code/index.js:73:17) 
    at emitNone (events.js:91:20) 
    at IncomingMessage.emit (events.js:185:7) 
    at endReadableNT (_stream_readable.js:974:12) 
    at _combinedTickCallback (internal/process/next_tick.js:80:11) 
    at process._tickDomainCallback (internal/process/next_tick.js:128:9) 

這是我的代碼

const REQUEST_PERMISSION_ACTION = 'request_permission'; 
    const userUID = app.getUser().userId; 
    const userName = app.getUserName().displayName; 
    console.log(userUID, 'USERRRRRRID'); 

我能做些什麼來獲取用戶標識?

+0

見https://stackoverflow.com/questions/47749476/i-can-not-get-information-with-dialogflowapp-getuser-method/47752302 – Bart

+0

我試圖讓我的令牌但顯然它是空的(TypeError:無法讀取null屬性的'accessToken') –

+0

我指的是關於'const app = new App({request:req,response:res})的囚徒的帖子;'嘗試添加更多的代碼給您的帖子,以便我們可以幫助更好,如果這不起作用。 – Bart

回答

0

這是我的代碼

function processV1Request (request, response) { 
    let action = request.body.result.action; // https://dialogflow.com/docs/actions-and-parameters 
    let parameters = request.body.result.parameters; // https://dialogflow.com/docs/actions-and-parameters 
    let inputContexts = request.body.result.contexts; // https://dialogflow.com/docs/contexts 
    let requestSource = (request.body.originalRequest) ? request.body.originalRequest.source : undefined; 
    const googleAssistantRequest = 'google'; // Constant to identify Google Assistant requests 
    const app = new DialogflowApp({request: request, response: response}); 
    // Create handlers for Dialogflow actions as well as a 'default' handler 
    const actionHandlers = { 
    // The default welcome intent has been matched, welcome the user (https://dialogflow.com/docs/events#default_welcome_intent) 
    'input.welcome':() => { 
    sendGoogleResponse(' Bonjour, Que puis je faire pour vous ?'); 
    }, 
    'input.what':() => { 

    const http = require('http'); 
    const https = require('https'); 
    https.get('https://bnpparibas-api.openbankproject.com/obp/v3.0.0/my/banks/bnpparibas.07.fr/accounts/cbf874f8-9eb1-4fdf-899c-54b8c5e7c2c8/account', (resp) => { 
    let data = ''; 
    const app = new ActionsSdkApp({request: request, response: response}); 



    // A chunk of data has been recieved. 
    resp.on('data', (chunk) => { 
    data += chunk; 

    }); 
+1

如果你在你的http調用之前放置'const userUID = app.getUser()。userId;'它應該工作嗎? – Bart

+0

Ohhhh完美的作品<3感謝Bart! –

+1

僅供將來參考 - 您不應將後續信息作爲答案,您可以編輯原始問題。 Bart應該將其作爲答案發布,以便您可以接受答案,而其他人則可以對此作出迴應。隱藏在評論中,其他人可能找不到它。 – Prisoner

0

你要問助手,引導用戶授予權限爲您的應用程序來獲取此信息更大的作用。

看看here

+1

不,你不知道。這隻有當你想要用戶名或其他信息。 userId可以在任何時候獲得,沒有任何額外的權限。 – Bart

+0

對不起,你是對的,只有在獲得其他信息時。 –