actions-on-google / actions-on-google-nodejs

Node.js client library for Actions on Google
https://actions-on-google.github.io/actions-on-google-nodejs
Apache License 2.0
900 stars 197 forks source link

Issues serving multiple Actions project using the same webhook #388

Open j-a-h-i-r opened 4 years ago

j-a-h-i-r commented 4 years ago

My current setup is like this. I have multiple actions project on Google Actions. They are all using the Actions SDK and using the same fulfillment webhook.

I am using account linking (with Google Sign In) on the actions projects. The guideline here initializes the actionssdk with a static clientId like this:

const app = actionssdk({
  // REPLACE THE PLACEHOLDER WITH THE CLIENT_ID OF YOUR ACTIONS PROJECT
  clientId: CLIENT_ID,
});

But for my use case, I have to dynamically set the clientId based the the projectId of the actions project. I can extract the projectId inside the actions.intent.MAIN intent and retrieve the stored clientId from DB there.

What is the best way to achieve this?


What I have tried additionally:

I initialized the actionssdk with a dummy clientId like this:

const app = actionssdk({
    clientId: 'placeholder.apps.googleusercontent.com'
})

After that, inside actions.intent.MAIN intent, I've replaced it with an actual clientId

app.intent('actions.intent.MAIN', async conv => {
    app.auth.client.id = global.gConfig.GOOGLE_ACTION_CLIENT_ID;
})

This approach works initially for a single project. But is fails with Error: Wrong recipient, payload audience != requiredAudience as soon as nodemon reloads the express app.


Some information regarding my setup: