Search code examples
actions-on-googlegoogle-assistant-sdk

Getting Undefined value for SignIn.status during account linking


I am working on the Account Linking & set google Sign-IN in Linking type in Google.

I have created two intents, one will call the google Sign-In feature and the second one will read the data from google account for. eg. email id, name.

In Intent 1, I have enabled the webhook call for this intent.

In Intent 2, I have set Event to actions_intent_SIGN_IN & enabled the webhook call for this intent.

Though my these functions (Intents results) in Inline Editors are successfully executing, still I am getting Undefined value for SignIn.status, code is given below, please help.


'use strict';
const {dialogflow, SignIn} = require('actions-on-google');

const app = dialogflow({  
  clientId: "174911074867-tuffsr7ec28vg7brppr0ntkjutthfq8n.apps.googleusercontent.com",
}); 
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });

function accountlinking(agent) {      
  var signin=new SignIn('To get your account details'); 
}  
function testsignData(agent) {    
   console.log("status :"+SignIn.status); 
} 
  let intentMap = new Map();  
  intentMap.set('Intent1', accountlinking);  
  intentMap.set('Intent2', testsignData);  

  agent.handleRequest(intentMap); 
});

1). On my Action calling, it is asking for the Google Account linking first and after linking process only it is moving ahead. But I need to get into the action, have a little conversation and when required only then asking for the Linking. I need to call via my intent. How to do that?

2). Though my these functions (Intents results) are successfully executing, still I am getting Undefined value for SignIn.status


Solution

  • Your testSigninData() function is calling Signin.status, but you don't have any variable called SignIn in this function, so that is why it is undefined. Try changing your function so it accepts a conv, params and signin object that are given during a sign-in.

    If you have a look at the account linking documentation you can see which parameters are provided during the accountlinking process.

    Example accountlinking setup for Actions on Google

    const {dialogflow, SignIn} = require('actions-on-google');
    const app = dialogflow({
      // REPLACE THE PLACEHOLDER WITH THE CLIENT_ID OF YOUR ACTIONS PROJECT
      clientId: CLIENT_ID,
    });
    
    // Intent that starts the account linking flow.
    app.intent('Start Signin', (conv) => {
      conv.ask(new SignIn('To get your account details'));
    });
    // Create a Dialogflow intent with the `actions_intent_SIGN_IN` event.
    app.intent('Get Signin', (conv, params, signin) => {
      if (signin.status === 'OK') {
        const payload = conv.user.profile.payload;
        conv.ask(`I got your account details, ${payload.name}. What do you want to do next?`);
      } else {
        conv.ask(`I won't be able to save your data, but what do you want to do next?`);
      }
    });
    
    

    The above code uses the actions on google dialogflow handler called app. In your code you are using the WebhookClient object to handle dialogflow intents. I'm not sure if you can use the WebhookClient for actions on google accountlinking.

    If it still doesn't work after you changed the testSigninDate function parameters, it might be worth trying to remove the webhookclient and see if you can use the app.intent() calls to handle your intents just like the above code example.