Add Dialogflow to a Firebase project with correct permissions
If you’re trying to add Dialogflow to an existing Firebase project the chances are you’ll run into this permissions issue when attempting to communicate with your bot:
> code: 7,
> details: "IAM permission 'dialogflow.sessions.detectIntent' on 'projects/etho-bot-8fa3f/agent' denied.",
> metadata: Metadata {
> internalRepr: Map(1) { 'grpc-server-stats-bin' => [Array] },
> options: {}
> }
To remedy this follow these steps:
- Ensure your Dialogflow project is linked to the Firebase (Google) project you want to use.
- Go to
console.cloud.google.com
and select the correct project (Blue top bar, left side - drop down / select widget). - From the hamburger menu (Blue top bar, absolute left) select ‘IAM & Admin’.
- You should be greeted with a list of ‘Members’, assuming you’ve already initialized the Firebase Admin SDK, you will see a member with the name
firebase-adminsdk
. Click the pencil icon to the far right of that. - Click the ‘Add Another Role’ button and in the resulting smart select, type ‘Dialogflow admin’ and add the role ‘Dialogflow API Admin’.
Final thoughts
Using Firebase in tandem with Dialogflow works really well because you can create a bot with Firebase as it’s back end and utilise all of the nice things that come with that.
For example, you can use Cloud Functions (serverless functions) to record your users’ chat sessions to the Firestore database, then use background functions to trigger things like mail or Cloud Messaging (push notifications) as enquiries are logged with the bot.
If that sounds interesting check out this repo for a great starting point.