I'm trying to write a firebase function to send a transactional e-mail with SendGrid whenever it gets triggered by a HTTP request, but at the moment I'm having real difficulty getting the function to be able to access the configuration variables that I've set with the sendgrid key which is obviously a real problem...
I've set the config variable with the below command:
$ firebase functions:config:set sendgrid.key="KEY_HERE"
When I run firebase functions:config:get to list all the config values, it returns the correct value in the terminal:
{
"sendgrid": {
"key": "KEY_HERE"
}
}
But when I try to access it from my function (tried with both TypeScript & Vanilla JS setups), functions.config() just returns an empty object.
Has anyone encountered & solved this issue before, or am I doing something wrong? In either case, if anyone could give me a pointer then that'd be much appreciated!
Edit the first
I have deployed the function, and called it while hosted and looking at the logs, you can see the correct values. However, I still see the problem when I call the function when served locally on my machine for testing, which is a problem as I'd like to not have to deploy a function just to see if it works...
Related
I have written a simple cloud function which I also deployed already to firebase and the code works. It is the following function:
exports.testfunction = functions.https.onCall(async (data) => {
const mydata = JSON.parse(data)
const mydata1 = JSON.parse({const1: "AAA", const2: "BBB", const3: "CCC"})
return{mydata1}
});
Now that I want to test this function localy, Im running the following command in my terminal: firebase emulators:start and I get no errors so far. Anyways as soon as I try to call the function with http://localhost:5001/MYPROJECTNAME/us-central1/testfunction in my browser, Im receiving the following error message which I can not find any workaround for:
{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
The thing is, the function itself is working great if I deploy it and call it from inside my app, but Im failing to run it from my firebase emulator inside the console.
What am I doing wrong here?
As explained in the documentation for Callable Cloud Functions:
It's important to keep in mind that HTTPS callable functions are
similar but not identical to HTTP functions. To use HTTPS callable
functions you must use the client SDK for your platform together with
the functions.https backend API (or implement the protocol).
So, if you want to directly call the function via it's URL, your HTTP Request needs to follow the protocol specification for https.onCall.
I am developing a REST API with AWS Lambda, API Gateway, RDS (MySQL). I am using Node.js. I am also using AWS SAM tool.
In my API I have lambda functions that accept URL parameters and that do not accept them.
I noticed that I can deploy these to AWS without an issue, and then execute from POSTMAN.
However when I try to locally run them, I am running into problems.
When I execute sam local invoke, it says Error: You must provide a function logical ID when there are more than one functions in your template. So I had to execute them one by one, like sam local invoke FunctionName
When I try to invoke a function that accepts URL parameters, it says TypeError: Cannot destructure property 'id' of 'event.queryStringParameters' as it is undefined. Here the id is the name of the URL Param.
So,
How can I locally invoke all node.js functions, instead of one by one?
How can I make sure that functions with URL Params also can be locally invoked?
In Node.JS, it is not possible to locally invoke all at once. sam local invoke FUNCTION_NAME is the way to go.
Since the question is about a REST API, if you want to check how thE rest api is working, all you have to do is this
sam build
sam local start-api
I normally run the following without build since it helps to view the changes during development:
sam local start-api 2>&1 | tr “\r” “\n”
I'm trying to deploy my first function with firebase cloud functions.
I deployed the standard function "helloWorld" without problem, but then, when I added this:
const admin = require("firebase-admin");
admin.initializeApp();
firebase deploy didn't work anymore and caused this error:
Missing expected firebase config value databaseURL, config is actually{"projectId":"PROJECT-ID","storageBucket":"PROJECT-ID.appspot.com","locationId":"europe-west"}
If you are unit testing, please set process.env.FIREBASE_CONFIG
How can I set config or the value of databaseURL? I don't find anywhere the file where these things are written... I also looked in documentation but I didn't find anything useful
I tried also with
admin.initializeApp(process.env.FIREBASE_CONFIG);
but this give me this error:
Error: Error occurred while parsing your function triggers.
Error: Invalid Firebase app options passed as the first argument to initializeApp() for the app named "[DEFAULT]". Options must be a non-null object.
It looks like you're being affected by a change that was made a few months ago where the databaseURL is no longer auto-created when you create a new project.
If that is the case, you you can force the databaseURL to be generated by going to the Realtime Database panel in the Firebase console. If this indeed fixes the problem, it might be worth filing a bug report with the Firebase support team.
It looks like you don't have a default database created. Visit your firebase console and create at least one real-time database.
You can explicit select a database instance with functions.database.instance() View Docs
I'm using the JavaScript version of the botframework. I've followed the documentation to enable telemetry logging in Application Insights. When I access the logs I can see that custom events are being logged.
The issue is that the bot specific identifiers, such as user_Id, session_Id and conversation_Id are not being logged. This can be seen in the screen capture below
In the applicationInsightsTelemetryClient.js file there is a function called addBotIdentifiers. As far as I can tell, it is this function that is responsible for adding the bot specific identifiers.
The first lines of the function look like this:
function addBotIdentifiers(envelope, context) {
if (context.correlationContext && context.correlationContext.activity) {
Inspecting this function shows that the context argument is always null.
This leads me to my questions.
Why is it null?
Any suggestions on what I need to do to have it set appropriately?
Update
In digging into this further it appears the code starting at line 26 in the applicationInsightsTelemetryClient.js file isn't being called. Could this be the cause of the missing context later on in the addBotIdentifiers function?
Looks like the documentation has a missing line in step 7. We will correct the document ASAP. Meanwhile, please add the below in your index.js following https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/21.corebot-app-insights/index.js#L113
// Enable the Application Insights middleware, which helps correlate all activity
// based on the incoming request.
server.use(restify.plugins.bodyParser());
Further investigation has shown what the issue was. It's not immediately obvious.
I compared the code in my index.js file with the one in the 21.corebot-app-insights BotBuilder sample.
Note that the setup of the Restify server happens after the creation of the adapter bot adapter. It is also after the configuration of the main dialog and the middleware.
In my code the setup of the Restify server and the bot adatper / dialogs was intermingled. This appears to have been the cause of the problem.
The main lesson here for me, and for anyone who stumbles across this post later, is that the setup of the Restify server should be at the end of the index.js file. To ensure all of the bot framework is setup first.
I have a JavaScript client which connects to my local Parse server just fine. Login works, Parse.Query works, however calling any Cloud Code function with Parse.Cloud.run does not work -- instead I get the error 100/XMLHttpRequest failed. Calling CC functions from commandline using curl does work, indicating that the overall server setup is correct.
It's obviously a client configuration problem on my part, but I just can't figure out what the problem might be. Client setup is simple enough:
Parse.initialize('myappid');
Parse.serverURL = 'http://localhost:1337/parse';
Any ideas?
The problem was that my CC funtion requires a Date argument but I passed in a moment object... now I converted it to Date and all is well again. Silly me, but 100/XMLHttpRequest failed/ConnectionFailed is also a very misleading error message for this!