Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [Enabling Billing](#enabling-billing)
* [Configuring Account Linking](#configuring-account-linking)
* [Development](#development)
* [Testing locally with ngrok](#testing-locally-with-ngrok)
* [Files](#files)
* [i18n](#i18n)
* [Running this Action](#running-this-action)
Expand Down Expand Up @@ -220,6 +221,21 @@ Function URL (factsAboutGoogle): https://us-central1-myprojectname-ab123.cloudfu

## Development

#### Testing locally with ngrok
You can test your changes in the local development environment by going through the following steps :
1. Install the dev dependencies from `./functions/package.json`

2. Open terminal and run `firebase functions:config:get > runtimeconfig.json`

3. Open `./functions/config.js` and replace the values for the local config variables by the respective values from `runtimeconfig.js` file you obtained in step 2.

4. Cd into `/functions` directory and run `export IS_LOCAL_DEV=true` in the terminal.

5. From the same directory, run `npm run dev` in the terminal. Open another terminal from the same directory and run `npm run tunnel`.

6. You can now use the link generated via ngrok for fulfillment in the Dialogflow console. A new link will be generated each time you close the ngrok terminal. You will need to change that in the Dialogflow console each time.


#### Files
1. `./functions/index.js`
+ Add new handlers for intents, modify intent logic to customize the skill.
Expand Down
25 changes: 20 additions & 5 deletions functions/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
// Environment Variables
const functions = require('firebase-functions');

module.exports = {
SERVER_URL : functions.config().envariables.server_url,
CLIENT_ID : functions.config().envariables.clientid,
OAUTH_SERVICE_NAME : functions.config().envariables.oauth_service_name
};
let config_vars;

// Manually provided configuration variables for local testing
if(process.env.IS_LOCAL_DEV === "true") {
config_vars = {
SERVER_URL : "your-server-url",
CLIENT_ID : "your-client-id",
OAUTH_SERVICE_NAME : "your-oauth-service-name"
}
}
// Production configuration variables
else {
config_vars = {
SERVER_URL : functions.config().envariables.server_url,
CLIENT_ID : functions.config().envariables.clientid,
OAUTH_SERVICE_NAME : functions.config().envariables.oauth_service_name
}
}

module.exports = config_vars;
16 changes: 15 additions & 1 deletion functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
MediaObject,
} = require('actions-on-google');
const functions = require('firebase-functions');

const helperFunctions = require('./helperFunctions');
const envVariables = require('./config');
const {
Expand All @@ -25,6 +24,14 @@ const app = dialogflow({
const i18n = require('i18n');
const moment = require('moment');

// Express server for local testing running at PORT
const express = require("express");
const bodyParser = require("body-parser");
const expressApp = express().use(bodyParser.json());
const cors = require('cors');
expressApp.use(cors());
expressApp.post("/", app);

i18n.configure({
locales: ['en-US', 'pt-BR', 'hi-IN'],
directory: __dirname + '/locales',
Expand Down Expand Up @@ -2239,5 +2246,12 @@ app.intent('Post Group Emoji Message Intent', async (conv, params) => {

});

// Run local server at PORT
if (process.env.IS_LOCAL_DEV === "true") {
const PORT = 8000;
expressApp.listen(PORT, () =>
console.log(`*** SERVER RUNNING LOCALLY ON PORT ${PORT} ***`)
);
}

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Loading