1
votes

I have managed to make Account Linking on Android using actions on google sdk and Dialogflow but can't make it work using the new Dialogflow V2 webhook. It does ask permission to link account and the account linking does happen but I cannot access the user data like given_name, email, etc. I have done everything required including creating the intent with actions_intent_SIGN_IN which gets called as expected except that I don't get the information that I should.

This is the code that is called to create sign in

function googleSignIn() {
    console.log('In googleSignIn')
    const conv = agent.conv()
    // conv.ask(new SignIn('To get your account details'))
    // conv.ask('Hello')

    var payload = {
      "expectUserResponse": true,
      "systemIntent": {
        "intent": "actions.intent.SIGN_IN",
        "data": {}
      }
    }

    // agent.add(payload)
    console.log('add googleSignIn payload')
    agent.add('Placeholder_google_payload')
    agent.add(new Payload(agent.ACTIONS_ON_GOOGLE, payload))
  }

This gets called when the intent is fired by Actions on Google

function getSignIn(agent) {
    console.log('In function getSignin: ')
    const conv = agent.conv()
    console.log('conv parts: ', JSON.stringify(conv.user))
    agent.add('User profile:', conv.user);
    // console.log('conv access token: ', JSON.stringify(conv.user.access.token))
  }

With help from Prisoner I managed to solve the problem. You basically just get the token which has to be decoded. This is the relevant code.

var jwt = require('jsonwebtoken'); // use npm i jsonwebtoken to get 
const profile = jwt.decode(conv.user.profile.token);
console.log('Profile: ', profile); 
// you can then get the elements from the profile (instead of payload)
// e.g.
console.log('Name: ', profile.name);
1
Aer you using Account Linking via OAuth or Google Sign In for Assistant?Prisoner
Thanks Prisoner, I was actually checking your profile to see if you have answered any questions about this because your answers are good! I am keeping it simple and using Google Sign in for Assistant. Basically when I did this using Actions on google it was easy to define the app = dialogflow({client:....) and then the app object gave me all the information about sign in. I don't know how to do the same thing with Webhook. I tried using app the same way but it says undefined object. I am sure I am missing something very simple here to get to the Google sign in data.user3631034

1 Answers

3
votes

Once the user has signed in once using Google Sign In for Assistant, all further requests will contain an id token.

If you are using the actions-on-google library, the token will be in the conv object as conv.user.profile.id and the profile information itself (the "payload" of the id token) will be in conv.user.profile.payload.

If you're using the dialogflow-fulfillment library, you can get the conv object from agent.getConv().

If you're using the multivocal library, the user profile is stored in the environment under User/Profile with the id token available under User/IdentityToken and User/IsAuthenticated will be set to true.

This will be sent to you for this session, and any future session as long as the user doesn't disconnect your Action from their account.