Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFlow Webhook API V2 - How to get Authorized User's accessToken?

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?

like image 316
FranticRock Avatar asked Mar 16 '18 21:03

FranticRock


1 Answers

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.

like image 143
Prisoner Avatar answered Sep 22 '22 02:09

Prisoner