actions-on-google / dialogflow-helper-intents-nodejs

Helper Intents sample (using Dialogflow) in Node.js
Apache License 2.0
13 stars 8 forks source link

undefined access token #6

Closed nish17 closed 5 years ago

nish17 commented 5 years ago
if (signin.status !== "OK") {
    conv.ask("You need to sign in before using the app.");
  } else {
    const payload = conv.user.profile.payload;
    const access = conv.user.access.token;
    console.log(payload);
    conv.ask(
      `Great! Welcome. Thanks for signing in. accessToken is ${access}, payload is ${payload}
      }`
    );
  }
});

In the response, I'm getting Undefined access token I'm trying to develop an AoG which can manage(read, edit, delete) events in the user's calendar. First of all i'm thinking of getting the user logged in, once that's done, and after getting access token, I can use google calendar API, passing the access token and required parameters I can get the required data.

But the problem is I'm unable to proceed because of undefined access token. Please help me here.

Fleker commented 5 years ago

It looks like the syntax is conv.user.access: https://actions-on-google.github.io/actions-on-google-nodejs/classes/conversation.user.html#access

nish17 commented 5 years ago

app.intent("actions.intent.SIGN_IN", (conv, params, signin) => { if (signin.status !== "OK") { conv.ask("You need to sign in before using the app."); } else { const payload = conv.user.profile.payload; const access = conv.user.access; conv.ask(Great! Welcome here's your accessToken ${conv.user.access}, stringified: ${JSON.stringify(conv.user.access)} );`

tried that too, still it's undefined

nish17 commented 5 years ago

and btw the link u mentioned in the previous comment, on that page, there's not a single statement which says, conv.user.access. Maybe u shared the wrong link.

aradwyr commented 5 years ago

Have you seen the Google Sign In sample? All you might be missing is async-await:

app.intent('Get Sign In', async (conv, params, signin) => {
  if (signin.status !== 'OK') {
    return conv.close(`Let's try again next time.`);
  }
  const color = conv.data[Fields.COLOR];
  await conv.user.ref.set({[Fields.COLOR]: color});
  conv.close(`I saved ${color} as your favorite color for next time.`);
});
aradwyr commented 5 years ago

Duplicate RE: https://github.com/actions-on-google/dialogflow-helper-intents-nodejs/issues/5