Firebase deploy not giviing a webhook URL - javascript

I am using Dialogflow to create an action for the Google assistant. I am following this tutorial: https://medium.com/voice-tech-podcast/get-current-location-of-a-user-using-helper-intents-in-actions-on-google-19fe9a8ea99f
When I use the command firebase deploy in step 5, this is the output that I get:
=== Deploying to 'location-tracker-xxxx'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> eslint .
✔ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing functions directory for uploading...
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/location-tracker-xxxx/overview
I am supposed to get Webhook URL which I can use as webhook URL in Dialogflow.
This is my index.js:
const functions = require("firebase-functions");
const { dialogflow, Permission, SimpleResponse } = require("actions-on-google");
const app = dialogflow();
app.intent("Default Welcome Intent", conv => {
conv.data.requestedPermission = "DEVICE_PRECISE_LOCATION";
conv.ask(new SimpleResponse('Welcome to location tracker'));
return conv.ask(
new Permission({
context: "to locate you",
permissions: conv.data.requestedPermission
})
);
});
I have read this Stackoverflow but it did not solve my problem because there is not shown what the solution was science the code referred to is not available anymore.
Thanks!

As Doug alluded to in the comments, you need to ensure that you have a function exported in your code. This can be added to the bottom:
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
The ActionsOnGoogleFulfillment is the name of your function. It will be deployed when you run that command.
You can view all functions in the Firebase console, and you should expect it to be in the format:
https://us-central1-**PROJECT_ID**.cloudfunctions.net/**FUNCTION_NAME**

Related

Firebase function deploy error "Error: Refresh token must contain a "client_id" property."

I tried deploying a Firebase function, but I got the following error.
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Refresh token must contain a "client_id" property.
The full terminal output after running deployment is like
✔ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing codebase default for deployment
⚠ functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions#latest in your functions directory.
⚠ functions: Please note that there will be breaking changes when you upgrade.
i functions: Loaded environment variables from .env.development.
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Refresh token must contain a "client_id" property.
I'm using the following versions for firebase.
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.18.0",
The app initialization code looks like
import * as admin from "firebase-admin";
admin.initializeApp();
Deployment was working about a month ago, so I cloned my git repo again. But, even trying to deploy the same code is giving me the error.
I have proper authentication on my CLI because when I run firebase projects:list, it shows me the correct list of projects, and firebase use <PROJECT_NAME> also works.
I also tried manually setting the firebase config in app initialization part by doing
import * as admin from "firebase-admin";
const firebaseConfig = {
apiKey: <VALUE_FROM_FIREBASE_CONSOLE>,
authDomain: <VALUE_FROM_FIREBASE_CONSOLE>,
projectId: <VALUE_FROM_FIREBASE_CONSOLE>,
storageBucket: <VALUE_FROM_FIREBASE_CONSOLE>,
messagingSenderId: <VALUE_FROM_FIREBASE_CONSOLE>,
appId: <VALUE_FROM_FIREBASE_CONSOLE>
};
admin.initializeApp(firebaseConfig);
This is fixed in V11.5.0 released on the 19th of January 2023. After the bug was found and reported on this Github issue.
Please reinstall/update Firebase to fix.
npm install firebase-admin#latest

Firebase deploy functions doesn't deploy

I'm learning firebase for my new project, I need to deploy 1 function and when I run firebase deploy --only functions:updateDatabase I get this output in the terminal:
deploying functions
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
+ functions: required API cloudfunctions.googleapis.com is enabled
+ functions: required API cloudbuild.googleapis.com is enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (75 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: cleaning up build files...
+ Deploy complete!
but the function is not deployed. I tried to reinstall node-modules, npm i. I have access to the project itself on the firebase, but can't figure out why tihs function is not deploying and there is no error message. Any help and advise is greatly appreciated.
Based on the question above, The possible root cause for this issue is you didn't export the functions properly. Properly export the function and deploy. See example code below.
const functions = require("firebase-functions");
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
exports.helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
firebase deploy --only functions:helloWorld
This would deploy because the function is exported properly.
However, by deploying a function like below:
const functions = require("firebase-functions");
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
function helloWorld() {
functions.logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
};
will result to:
i deploying functions
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
i functions: cleaning up build files...
✔ Deploy complete!
Thus, the function is not properly deployed.
You may check Get started: write, test, and deploy your first functions for more information.

Can I locally emulate cloud function and hosting at the same time?

I am writing a simple web app with firebase hosting and cloud functions. My functions are onCreate , onDelete and httpsServer. I wan't to test my app by running it locally. How can I do this since firebase serve only works with https function and hosting.
I have tried running firebase serve and firebase functions:shell at the same time on different bash terminals. This causes firebase functions:shell to fail.
The create function :
exports.created = functions.firestore.document('Books/{bookID}')
.onCreate((snapshot, context) => {
FUNCTION_BODY
});
The Delete Function :
exports.deleted = functions.firestore.document('Books/{bookID}')
.onDelete((snapshot, context) => {
FUNCTION_BODY
});
The https Function :
exports.app = functions.https.onRequest(app);
The error thrown from bash :
$ firebase functions:shell
i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.13.0 but Google Cloud Functions only supports v6.11.5.
! functions: Failed to emulate created
! functions: Failed to emulate deleted
! functions: Failed to emulate app
i functions: No functions to emulate.
No functions emulated.
Output from second bash :
i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.13.0 but Google Cloud Functions only supports v6.11.5.
i hosting: Serving hosting files from: public
+ hosting: Local server: http://localhost:5000
info: initalised
info: rendering home...
+ functions: app: http://localhost:5001/book-shelf-be347/us-central1/app
info: Worker for app closed due to file changes.
Note: These are separate bash terminals running at the same time on the same machine.
I did some digging through the firebase documentation and could not find any solution. This is probably because there is no official tools that let you do this. So I finally solved the problem by running the hosting using nodemon and then using
firebase serve --functions
This solved the problem of using same port since it is handled by nodemon.
Hope firebase will provide new tools in the future.

Can't deploy Cloud Functions for Firebase

I was deploying functions just fine, but then it stopped working, and I don't know why. I've reverted back to the sample code (from here or here):
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// Listens for new messages added to /messages/:pushId/original and creates an
// uppercase version of the message to /messages/:pushId/uppercase
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
const original = event.data.val();
console.log('Uppercasing', event.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return event.data.ref.parent.child('uppercase').set(uppercase);
});
But now, when I run firebase deploy --only functions I get:
=== Deploying to 'mydb'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
i runtimeconfig: ensuring necessary APIs are enabled...
+ runtimeconfig: all necessary APIs are enabled
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (2.04 KB) for uploading
! functions: Upload Error: Cannot read property 'response' of undefined
i starting release process (may take several minutes)...
i functions: updating function makeUppercase...
! functions[makeUppercase]: Deploy Error: Function load error: Node.js module defined by file index.js is expected to export function named makeUppercase
+ functions: 0 function(s) deployed successfully.
Functions deploy had errors. To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
What is wrong?
The console shows the same error messages, without any more explanations:
Version 3.6.0 of the Firebase Tools just came out... after installing that version, the deploy worked fine!
Inside your project by the terminal:
npm install
firebase deploy
It's much helpful to examine the actual logs by viewing the log
firebase functions:log
The specific issue will be visible there. I sometimes had error as simple as a missing package

Cloud Functions for Firebase Error occurred while parsing your function triggers

I had been trying to send emails to the users in Firebase using Cloud Functions for Firebase. I am referring to the repository of firebase function at https://github.com/firebase/functions-samples/tree/master/quickstarts/email-users
I install all the node packages for the firebase email function as required and explained on the repository.
I edited TODO in the index.js file in functions as
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
// Configure the email transport using the default SMTP transport and a GMail account.
// For other types of transports such as Sendgrid see https://nodemailer.com/transports/
// TODO: Configure the `gmail.email` and `gmail.password` Google Cloud environment variables.
firebase functions:config:set gmail.email="email#gmail.com" gmail.password="gmailPassword"
const gmailEmail = encodeURIComponent(functions.config().gmail.email);
const gmailPassword = encodeURIComponent(functions.config().gmail.password);
const mailTransport = nodemailer.createTransport(
`smtps://${gmailEmail}:${gmailPassword}#smtp.gmail.com`);
When I try to deploy the function using the command
firebase deploy
It shows me the following error
Error occurred while parsing your function triggers.
Could anyone please help me out in solving this.
The functions:config is a command that you run with the Firebase CLI from the command prompt, not from your Functions code.
So in your command prompt/terminal:
firebase functions:config:set gmail.email="email#gmail.com" gmail.password="gmailPassword"

Categories

Resources