Google Sign-In in Jovo

account-linking
google-assistant

#1

Is there a way to implement Google Sign-in via voice using Jovo framework?
If not - is there a way to use Actions on Google node.js sdk inside a Jovo app?


How to get user logged in email in Jovo web hook handler?
#2

answering my own question, I found something in the docs: https://www.jovo.tech/docs/reference/GoogleAction.html#main

I already enabled Sign In with voice in Action on Google console, and used this:
this.$googleAction.askForSignIn(speech)
in my app. First test returned a prompt from AoG to sign up :slight_smile:
I’ll update with full solution when I get it - unless someone can do it quicker :smiley:


#3

so the next step is to create an intent:
ON_SIGN_IN () {
…
}

And inside try to get user profile data, hoping to provide access to email address.
The intent works, but I can’t get user profile data.

I tried this:
let profile = await this.$googleAction.$user.getProfile()
but it returns undefined.

Please help.


#4

Can you paste the full request JSON here?


#5

I found the problem, and the the solution too!

here’s the working ask for sign-in and sign-in confirmation intent:

async ASK_FOR_SIGNIN () {
  const speech = 'To receive emails'
  this.$googleAction.askForSignIn(speech)
}

async ON_SIGN_IN () {
    if (this.$googleAction.getSignInStatus() === 'OK') {
      // get token
      const tokenId = this.$originalRequest.user.idToken

      // decode token
      const tokenUrl = 'https://oauth2.googleapis.com/tokeninfo?id_token=' + tokenId
      try {
        const response = await axios.get(tokenUrl)
        const tokenData = response.data;
        // pull email from the decoded token
        this.tell(`User email is: ${tokenData.email}`);
      } catch (error) {
        console.error(error);
        this.tell(`Can't decode the token`);
      }
    } else {
      this.tell('There was an error.');
    }
  },

I’m not sure if that’s the recommended way of doing it, but it works :slight_smile:


#6

thanks for sharing this! we will take a look :slight_smile:


Getting user email address in google action
#7

Hi, just wondering if you had a chance to look at this. I just recently installed Jovo and this is my first issue encountered while migrating my current code. Thanks in advance.


#8

I missed that one.

I will publish an update (beginning of next week) that returns the following object:

this.$googleAction.$user.getGoogleProfile()

export interface GoogleAccountProfile {
  email: string;
  email_verified: boolean;
  name: string;
  picture: string;
  given_name: string;
  family_name: string;

  [key: string]: string | boolean;
}

thanks @MarekMis. I took the relevant part from your snippet.