DialogFlow "Webhook call failed. Error: UNKNOWN." - firebase

I have a DialogFlow setup using a firebase function for fulfillments.
I attempted to add two regions to .region() in my index.js file. This led to me deleting my existing firebase function (which had been running on "us-central-1") and adding two new ones for the newly added regions.
After doing so, my dialogflow setup completely fails to do fulfillments. Instead, i get "Webhook call failed. Error: UNKNOWN" with no other details. I tried removing .region() in my index.js, thereby creating a new firebase function similar to the original, but without luck.
I have also tried to add my fulfillment code directly in the inline editor, but this does not work either.
I am at a loss for what to do here. Has anyone experienced similar issues or perhaps know a fix? Please note that the setup worked completely fine prior to adding .region() and deleting the existing firebase function.
NOTE: I am getting a weird error when deploying through the inline editor: "Permission 'cloudfunctions.functions.SetIamPolicy' denied on resource '(my resource)' (or resource may not exist)."

Regarding the following error:
Permission 'cloudfunctions.functions.SetIamPolicy' denied on resource '(my resource)' (or resource may not exist).
I also encountered this when I deleted the function and tried to redeploy it.
I discovered that this occurs when the user (i.e. you) deploying the function does not have sufficient permissions to set IAM policies. In my case, the project was owned by another user whilst I had limited access. After being given owner access, although you likely only need permissions to manage IAM, the function deploys without any errors.

Although you moved the location of the function, you don't mention that you changed the URL for the webhook in Dialogflow to reflect this new location. The URL for Firebase Cloud Functions include the region where the function runs, so if you change the region, you also need to change the fulfillment URL.

Related

Cloud function triggered by firestore, path gets changed on deployment

I am trying to deploy a Cloud function written in Python and deployed with Cloud console which is triggered whenever a document is added to a subcollection.
I have specified the path as
users/{userID}/contactDump/{dumpID}
which should mean that whenever a new document is added to the contactDump subcollection for any user, the function should trigger.
According to Google's documentation, this is a valid path structure. Their own documentation has the following
users/{username}/addresses/{addressId}: valid trigger. Monitors all
address documents.
But whenever I deploy the function (which happens fine) the path gets changed to just {dumpID}
N.B the same happens if I try to deploy a function triggered on users/{userID} , after deployment the path gets changed to just {userID}
This issue only happens in the Cloud Console, and it's easy to reproduce by creating a new function with a Firestore Trigger with the following set up:
Once the function is deployed, the trigger section shows the path is not the one added during the function trigger creation, but the one shown is {addressId}.
After getting this result, it made me think that is the same issue you are facing, because although using different Event types, the Document path seems to be changed and only shows the last part of the path we entered in the first place, in this case {addressId}.
For this, as you said that the the function was working fine, I wanted to get the Cloud Function data performing a GET request using the API Explorer from the Cloud Functions documentation where in the request parameters I added the Cloud Function created details.
After executing the API call the response will contain the eventTrigger with the full trigger path.
In the example before, the result is:
{
"eventTrigger": {
"eventType": "providers/cloud.firestore/eventTypes/document.create",
"resource": "projects/<PROJECT_ID>/databases/(default)/documents/users/{username}/addresses/{addressId}",
"service": "firestore.googleapis.com",
"failurePolicy": {}
}
}
The “eventTrigger” from the response contains the original path, users/{username}/addresses/{addressId}, not the one displayed in the console.
This makes me think that the reason why we see only the shortened path in the Cloud Console doesn’t mean that it has been changed, apparently it is only showing the part after the last “/” slash of the path, even though the path present in the Cloud Function is longer.
Since this looks like an issue with how the console displays the path, I've raised this public issue.
If you need to recover the original path, you can use the API, or the gcloud tool:
gcloud functions describe FUNCTION_ID --format 'value(eventTrigger.resource)'

Authenticating Google Cloud Storage in R Studio

I know a similar question has been asked (link), but the response didn't work for me.
TLDR: I keep running into errors when trying to authenticate Google Cloud Storage in RStudio. I'm not sure what is going wrong and would love advice.
I have downloaded both the GCS_AUTH_FILE (created a service account with service admin privileges'--downloaded the key associated with the service account) and also downloaded GAR_CLIENT_WEB_JSON by creating a OAuth 2.0 Client ID and downloading that associated JSON file.
I've tried authenticating my Google Cloud Storage in several ways and hit different errors.
Way 1-automatic setup:
gcs_setup()
Then I select any one of the options, and get the error: Error in if (file.exists(local_file)) { : argument is of length zero And that error happens no matter which of the three options I select.
Way 2 - basic, following manual setup instructions from the package:
Sys.setenv("GCS_DEFAULT_BUCKET" = "my-default-bucket",
"GCS_AUTH_FILE" = "/fullpath/to/service-auth.json")
gcs_auth()
In this case, GCS_AUTH_FILE is the file that I mentioned at the beginning of this post, and the GCS_DEFAULT_BUCKET is the name of the bucket. When I run the first line, it seems to be working (nothing goes awry and it runs just fine), but when I run gcs_auth() I get taken to a web browser page that states:
"Authorization Error
Error 400: invalid_request
Missing required parameter: client_id"
Way 3: Following the method from the post that I linked above
This way involves manually setting the .Renviron file w/ the GCS_AUTH_FILE and GAR__CLIENT_WEB_JSON locations, and then running gar_auth(). And yet again, I get the exact same error as in Way 2.
Any ideas about what could be going wrong? Thanks for your help. I wasn't sure how to put in totally reproducible code in this case, so if there is a way I should do that, please let me know.

(firebase functions) Error: Forbidden Your client does not have permission to get URL /

I have problem when invoking deployed function in firebase. I have an editor role in the firebase project and when I deployed functions, didn't have any problem with invoking them. When I deployed a new function yesterday, I got the error message that says
Error: Forbidden
Your client does not have permission to get URL / < Function Name > from this server.
Nothing has been changed to my role. It is strange that since yesterday, whatever function I deployed, threw those errors.
In gcp console/cloud functions, where you can see permissions of the function that was selected, I've noticed that "cloud functions invoker" was not assigned to that function. I thought this should be added to any function by default as long as I have an editor access but strangely it does not add them anymore. other functions that were deployed since yesterday have the same issue
any suggestions or advices will be appreciated. Thank you
Please Review Allowing unauthenticated function invocation
As of January 15, 2020, HTTP functions require authentication by default. You can specify whether a function allows unauthenticated invocation at or after deployment.
So here's the answer from the firebase team
The issue you are experiencing is likely caused by the fact that after January 15, 2020, Google Cloud Functions automatically creates HTTP functions to be >private by default.
Please, update the CLI, by running the following command:
npm install -g firebase-tools
This will ensure that future HTTP functions that are created will be publicly accessible.
Lastly, for the existing functions that has the permission issues, you will need >to manually set a function to public using Cloud Console or gcloud CLI.
If you have any questions or you are still facing this issue, please, don’t >hesitate to write back.
edited*
There could be several reasons to cause this issue.
check your function endpoint url make sure there's no typo or space
In the gcp console, make sure you have permission to invoke function https://console.cloud.google.com/functions/list?project=<YOUR_PROJECT_ID>
If the above two are checked, delete your function and redeploy your them again
Unfortunately, you can't do this in Firebase, you have to go into the Google Cloud project which 'hosts' your firebase project. You can follow this guide by Google, and have a look at the screenshots below:
You should see Allow unauthenticated now
To allow unauthenticated invocation of a function, you add the special allUsers member id to the function and grant it the Cloud Functions Invoker role:
You can limit domain access in your function, for example:
exports.myTest= async(req, res) => {
res.set('Access-Control-Allow-Origin', 'foo.com');
...etc
I defined my Firebase cloud functions in typescript/JS and deploy using Firebase CLI. I got this error after customizing the deployment settings, and I fixed it by specifying invoker="public" - I did not need to dig into IAM settings or use the console or CLI to fix.
export const serve = functions
.region("us-west2")
.runWith({
invoker: "public", // this is the magic line
})
.https.onRequest(
async (request: functions.Request, response: functions.Response) => {
// ...
})
updating firebase-tools wasn't enough in my case because i already deployed that function and updating it didn't fix the issue, i had to delete it and deploy again

Firebase functions - new functions added are not being allowed to run

Weird case. I've got a number of firebase cloud functions. I've added a new one today. It deploys fine, but doesn't run. It's not possible to even call it for some reason. To isolate potential code errors in the new function, I've dropped another working function into this new one and it doesn't run either. If I replace the contents of an existing function by the new one's contents, then it runs. It's as if Firebase had silently introduced a limit on having new functions or just stopped running any new ones. I've tried it on two different instances so far and the issue persists.
To replicate, take an existing project with some functions. Duplicate one of the functions - say a simple https request and give it a new name. The new function will be identical to the old one, but it won't run with the browser saying "Error: Forbidden
Your client does not have permission to get URL /newFunction from this server."
It's quite a weird behaviour especially as it's possible to get a new function to run only by replacing an older function with the contents of the new one and calling the older function. Then it runs fine and without any complaints from the server.
Anyone know what might be causing this and how to fix this strange behaviour?
Apparently, Firebase introduced a change as of January 15, 2020 that HTTP functions require authentication by default.
You have to specify whether a function allows unauthenticated invocation at or after deployment. This can be done in the dashboard of all the functions or via console.
It would be good if the error message they provide explained all of that - would have saved me many hours of trouble-shooting.

Getting "Resource not found error" while using Azure File Sync

Facing a very strange issue.
Following this guide https://azure.microsoft.com/en-in/documentation/articles/app-service-mobile-xamarin-forms-blob-storage/ to implement File Sync in Xamarin Forms app.
The Get method in my service (GetUser, default get method in App service controller) is being called thrice & on the 3rd iteration it gives me a 404 resource not found error. First 2 iterations work fine.
This is the client call
await userTable.PullAsync(
null,
userTable.Where(x => x.Email == userEmail), false, new System.Threading.CancellationToken(), null);
If I remove the following line,
// Initialize file sync
this.client.InitializeFileSyncContext(new TodoItemFileSyncHandler(this), store);
then the code works just fine, without any errors.
I will need some time doing a sample project, meanwhile if anyone can shed some light, it will be of help.
Thanks
This won't be an answer, because there isn't enough information to go on. When you get a 404, it's because the backend returned a 404. The ideal situation is:
Turn on Diagnostic Logging in the Azure Portal for your backend
Use Fiddler to monitor the requests
When the request causes a 404, look at what is actually happening
If you are using an ASP.NET backend (and I'm assuming you are because all the File tutorials use ASP.NET), then you can set a breakpoint on the appropriate method in the backend and follow it through. You will need to deploy a debug version of your code.
this is sorted now, eventually I had to give it what it was asking for. I had to create a storage controller for User too, although I don't need one as I don't need to save any files in storage against the users.
I am testing the app further now to see if this sorts my problem completely or I need a storage controller for every entity I use in my app.
In which case it will be really odd as I don't intend to use the storage for all my entities.

Resources