Required for running this action This action uses Firebase Cloud Functions to make an HTTP request to a non-Google service. The free Firebase Spark Plan only allows outbound network calls to Google services. If you plan to run the sample, you will need to temporarily upgrade to a Firebase plan that allows for outbound networking, such as the Blaze Plan, also called Pay as you go.
- Node.js (> v8.10)
- Firebase CLI
- Rocket Chat Server updated to Release 1.0.0-rc3 or later
- From the Actions on Google Console, add a new project > Create Project > under More options > Conversational
- From the left navigation menu under Build > Actions > Add Your First Action > BUILD (this will bring you to the Dialogflow console) > Select language and time zone > CREATE.
- In the Dialogflow console, go to Settings ⚙ > Export and Import > Restore from zip using the
agent.zip
in this sample's directory.
-
Set up and initialize the Firebase CLI. If the following command fails with an EACCES error, you may need to change npm permissions.
npm install -g firebase-tools
-
Authenticate the firebase tool with your Google account:
firebase login
-
Clone repository to your local machine.
git clone https://github.com/PrajvalRaval/google-action-rocketchat.git
-
Then, change directory to google-action-rocketchat.
cd google-action-rocketchat
-
Initialize Firebase
firebase init
-
You'll be asked to select which Firebase CLI features you want to setup for your Actions project. Choose Functions then press Enter to confirm and continue.
-
Associate the firebase tool with your Actions project by selecting it using the arrow keys to navigate the projects list.
- Note: You can skip this step by selecting [don't setup a default project], but then you will need to do this association later using the command firebase use --project.
-
After choosing the project, the firebase tool will start the Functions setup asking you what language you want to use. Select JavaScript using the arrow keys and press Enter to continue.
-
For Do you want to use ESLint to catch probable bugs and enforce style? type N and press enter.
-
For File functions/package.json already exists. Overwrite? type N and press enter.
-
For File functions/index.js already exists. Overwrite? type N and press enter.
-
Get the project dependencies by typing Y to the prompt:
-
Do you want to install dependencies with npm now?.
-
Once the setup is completed, you'll see an output similar to the following:
✔ Firebase initialization complete!
-
Install the actions-on-google dependency by using following commands,
cd functions
npm install actions-on-google
-
Get the fulfillment dependencies and deploy the fulfillment function:
npm install
In Order to deploy our config we need to set some temporary Firebase Environment Variables by running the following command:
firebase functions:config:set envariables.server_url="temp_url" envariables.oauth_service_name="temp_oauth" envariables.clientid="temp_clientid"
Then run,
firebase deploy --only functions
-
The deployment takes a few minutes. Once completed, you'll see output similar to the following. You'll need the Function URL to enter in Dialogflow.
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/myprojectname-ab123/overview
Function URL (factsAboutGoogle): https://us-central1-myprojectname-ab123.cloudfunctions.net/dialogflowFirebaseFulfillment
- In the Dialogflow console's navigation menu, click Fulfillment, toggle the Webhook button to ENABLED , and replace the url in the URL field with your Function URL that was returned after the deploy command > SAVE..
- From the left navigation menu, click Integrations > Integration Settings under Google Assistant > Enable Auto-preview changes. (If not already enabled)
-
Go to your Firebase Console and select your project from list.
-
In the bottom side of left menu you will see an Upgrade button and select Blaze Plan from the list.
-
Login to your Action Developer Console and select Rocket Chat project on the list.
-
Go to Settings ⚙ -> Project Setting and Copy Project ID and paste it somewere safe as we will need it later.
-
Now click on Advance Options on Bottom left of the screen and select Account Linking from the list.
-
In Account creation,
-
Select No, I only want to allow account creation on my website
-
Click Next.
-
In Linking type, Select OAuth from the list and Set Authorisation code as grant type. Click Next.
-
Now we need to fill up the Authorization URI, Access Token URI, Client ID, Client Secret which we will generate on our rocket chat server.
- Note You need to be admin of the server to proceed with the further steps.
- In a new tab go to your Server -> Three Dot Menu -> Administration.
- Click on OAuth Apps.
-
Click on New Application on top right. Now we need to give it an Application Name and a Redirect URI.
-
For Application Name use "rcgoogleaction". This can be anything else as well.
- For the Redirect URI, copy
https://oauth-redirect.googleusercontent.com/r/YOUR_PROJECT_ID
and paste it in the Redirect URI field. (Paste the Project Id we copied earlier here)
-
You'll see it automatically generating Client ID, Client Secret, Authorization URL, and Access Token URL. Now copy these from the oauth app page and paste it in the Client ID, Client Secret, Authorization URL and Access Token URL fields in the Client information on Google Action Console Page. Click Next.
-
Copy Client ID and paste it somewhere safe as we will be using it for setting up Firebase Environent Variables.
-
In Configure your client (optional) section,
-
Tick mark(✔) Google to transmit clientID and secret via HTTP basic auth header
-
Click Next.
- In Testing instructions,
-
Provide an Email Id and Password as per instructions
-
Click on Save.
-
We are done on setting our OAuth App which will give us the access token to use for logging in. But for that we need to also enable custom oauth login for our server which we will do in the next steps.
-
Go to your Server -> Three Dot Menu -> Administration. Scroll down on your left and select OAuth and on top right click on Add custom OAuth.
-
Give a unique name in lower case for the custom oauth. For example enter "googleaction". Click on Send. Copy and paste this name somewhere safe as we will be using it for setting up Firebase Environent Variables.
-
You will now be provided a few fields some of which will be prefilled. We only need to change a few.
-
Change the Enable to true.
-
In the URL field enter
https://yourserverurl/api/v1
-
Finally at the bottom switch Merge users to true. We don't need to make any other changes here.
-
Click on Save Changes on top.
-
Go to your console add your Server URL,OAuth Service Name and Client ID to the following command and run,
firebase functions:config:set envariables.server_url="https://YOUR.SERVER.chat" envariables.oauth_service_name="YOUR_CUSTOM_OAUTH_NAME" envariables.clientid="YOUR_CLIENT_ID"
Then run,
firebase deploy --only functions
- WE ARE DONE FINALLY !
- You can test your Action on any Google Assistant-enabled device on which the Assistant is signed into the same account used to create this project. Just say or type, “OK Google, talk to my test app”.
- You can also use the Actions on Google Console simulator to test most features and preview on-device behavior.
-
./functions/index.js
- Add new handlers for intents, modify intent logic to customize the skill.
-
./functions/helperFunctions.js
- Enhance the functionality of the source code by adding functions that are required for sending requests and various other logics.
-
./functions/config.js
- Imports Firebase config into our code.
-
./functions/apiEndpoints.js
- REST API endpoint URLs.
-
./functions/locales/*.json
- Contains responses for different locales. If you are planning to contribute to your locale you will need to change response strings here.
By default we support development for EN
,PT
and HI
locales and are included in our Dialogflow agent. But we do have developed a base locale resource file for every supported Google Action locale, for developers worldwide to develop this action in their own language. If you are interested in contributing to your locale please follow this steps.
-
Go to your Dialogflow Console
-
In Dialogflow console click on
+
(Below Settings ⚙ Sign) > Select Additional Language > Your Locale after that click on SAVE -
You will need to add Training phrases one by one to every intent. Select Intents > select one intent from the list > Training phrases. Add some training phrases that include every Parameter required as headers data to send a
POST
request to the server, in the utterance and make sure it is native speaker friendly. -
While creating Training Phrases, make sure that you give composite entities parameters to the utterances. E.g. If your creating an utterance with
username
andchannelname
, select@sys.any
as their entity type. Refer toEN
locale training phrases for more depth understanding. -
For Backend setup, go to
./functions/index.js
and add your locale name toi18n.configure
>locales
array.i18n.configure({ locales: ['en-US', 'en-GB', 'en-AU', 'en-CA', 'en-IN', 'pt-BR', 'hi-IN'], directory: __dirname + '/locales', defaultLocale: 'en-US', objectNotation : true });
NOTE: It is same name as in locales folder.
-
Locale File:
./functions/locales/*.json
,It is highly likely that your locale may be behind because of new function additions, so we highly suggest to make sure that every object in your locale is up-to-date with our English locale file. If not make sure to add those JSON blocks to your locale before deployment. To do that simply copy and paste missing blocks from English locale file and simply translate the response strings into your own language.
We have developed those base locales using a translation software and translations of response may not be always accurate so feel free to update those response strings correctly as per your native language.
For more details on i18n please check out Fulfillment Localization and I18n-node
- Rocket Chat API Documentation
- Axios Documentation
- i18n Documentation
- Questions? Go to StackOverflow, Assistant Developer Community on Reddit or Support.
- For bugs, please report an issue on Github.
- Actions on Google Documentation
- Actions on Google Codelabs
- Webhook Boilerplate Template for Actions on Google
Are you an Alexa Developer, We also have an Alexa Repository for you to contribute on. Any form of help is appreciated.