6

In my DialogFlow V1 Webhook, I used to get the user's access token like this (node.js):

exports.voxGoogleHomeWebhook = functions.https.onRequest((req, res) => {    
  const app = new WebhookClient({request: req, response: res});    
var accessToken = app.getUser().accessToken   

This does not work in DialogFlow V2. getUser() is not available on instance of WebhookClient.

I can not find in their documentation, how to get the accessToken of the Logged In user: https://dialogflow.com/docs/fulfillment

I tried getting app.session, but that's just the unique session string Identifier of the user's session. It's not their access token.

How can I get the accessToken in V2?

Prisoner
  • 49,922
  • 7
  • 53
  • 105
FranticRock
  • 3,233
  • 1
  • 31
  • 56
  • Which library are you using? – Prisoner Mar 16 '18 at 22:41
  • @Prisoner dialogflow-fulfillment : their go-forward beta v2 library. – FranticRock Mar 16 '18 at 22:42
  • And are you trying to get the user information sent by the Google Assistant? (You tagged it google-home, but I want to be sure.) – Prisoner Mar 16 '18 at 22:46
  • @Prisoner i am using DialogFlow into Actions on Google. I am not using Android’s Assistant. I am using the Actions on Google simulator and the Google Home mini device to test this. Webhook deployed on GCP. – FranticRock Mar 16 '18 at 22:50

1 Answers1

4

It looks like the portion of the request object that contains this info isn't (yet) handled by the library. I've opened a bug on the issue, and you may wish to follow or comment on it.

In the meantime, you can access the user information by looking at the req.body object. Specifically you can look at req.body.originalDetectIntentRequest.payload.user to get the User object. The accessToken field there is the one you're looking for.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Thanks. In my case it was in: req.body.originalDetectIntentRequest.payload.user.accessToken. I am using Auth0 as the provider. Perhaps you can ammend your answer with my path as well, and we will accept the answer. I found it by inspecting the contents of the JSON object: originalDetectIntentRequest. – FranticRock Mar 17 '18 at 16:17
  • Whoops! Was a cut and paste error on my part. Fixed. – Prisoner Mar 19 '18 at 22:41
  • 1
    With the dialogflow-fulfillment version 0.3.0-beta.3 , it is var accessToken = app.conv().user.access.token; https://actions-on-google.github.io/actions-on-google-nodejs/classes/conversation.access.html#token – ocihangir May 18 '18 at 12:36