0

I've made a Google Log in for my actions on google project, and I want to save the account info to a firestore database.

I looked at Google's example of how to do this (example here, at the very bottom under heading "Handle Data Access Requests"), but when you actually try to deploy it to firebase, you realize that it's actually has invalid syntax (or at least that's what the dialogflow inline editor is saying.....)

Here's what the error says specifically when I try to deploy this code:

The deployment of your Cloud Function failed:
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:34
app.intent('Get Sign In', async (conv, params, signin) => {
^

SyntaxError: Unexpected token (

Any suggestions?

Thanks for the help!

Please note: I am using only the code that the tutorial has said to PLUS I added the actions on google library and the fulfillment line (ie:

 // Other libraries...
const {
  dialogflow,
  BasicCard,
  Permission,
  Suggestions,
  Carousel,
  SignIn
  } = require('actions-on-google');

// ** code from tutorial / link **     

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)
Landon G
  • 819
  • 2
  • 12
  • 31
  • What's your Firebase configuration/version of node your are deploying to. I'm wondering if you are deploying to Node 6 where JavaScript doesn't but TypeScript does have `async/await`, see: [Cloud Functions for Firebase Async Await style](https://stackoverflow.com/q/44444273/295004) – Morrison Chang Nov 28 '18 at 06:18
  • I was running/ am running Node 6, I solved the problem and will be posting it below. – Landon G Nov 28 '18 at 06:22

1 Answers1

1

I figured out how to do this, however it was a different method than the actions on google example. If anyone knows how to do this easier or knows what was wrong with the code in the link I posted (if anything..) please let me know / add an answer!

I decided to just write to firestore directly and put it under a "Get Signin" function (also mentioned in the tutorial for dialogflow).

Here is the function I used to get the user to sign in and also log the information into firestore:

app.intent('Get Signin', (conv, params, signin) => {
    if (signin.status === 'OK') {
        const payload = conv.user.profile.payload;
        conv.ask(`Welcome back ${payload.name}. What can I help you with??`);
        const databaseEntry = conv.user.profile.payload; // Account info, loaded to firestore
        const accountRef = db.collection('Accounts').doc('account_info'); //How you want the info in firestore to appear
        return db.runTransaction(t => {
            t.set(accountRef, {entry: databaseEntry});
            return Promise.resolve('Write complete');
            }).then(doc => {

            }).catch(err => {
                 console.log(`Error writing to Firestore: ${err}`);
     });
    } else {
          conv.close(`To continue, you need to make an account with the app.`);
    }
Landon G
  • 819
  • 2
  • 12
  • 31