The Firebase Cloud Function is failing to trigger on the onCreate event within the Firebase Realtime Database

I recently deployed a function to Firebase with the following code:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

console.log('FILE LOADED');

const serviceAccount = require('../cargo-tender-firebase-adminsdk-8e307-c6b82762d2.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://cargo-tender.firebaseio.com'
});

console.log('INITIALIZED');

export const onMessageCreate = functions.database
  .ref('/chat')
  .onCreate((snapshot, context) => {

    console.log('onCreate TRIGGERED');

    const token = 'myToken';
    const payload = {
        notification: {
        title: 'Title',
        body: 'come check it',
        badge: '0',
        sound: 'default',
        }
    };

    console.log('trying to send push notification');

    return admin
      .messaging()
      .sendToDevice(token, payload).then((response) => {
        console.log('Message sent');
        console.log(response);
      }).catch((error) => {
        console.error('Error occurred while sending the message');
        console.error(error);
      });
  });

  console.log('FUNCTION COMPLETE');

However, when I attempt to create a record under /user-chat, the function does not run and the push notification is not sent. The logs also do not show the function being called.

If I manually trigger the function from the Firebase console (using test function), it runs without any issues, the push notification is received, and the logs display the expected output:

3:07:56.902 PM onMessageCreate FILE INCLUDED
3:07:57.112 PM onMessageCreate INITIALIZED
3:07:57.113 PM onMessageCreate FUNCTION COMPLETE
3:07:57.273 PM onMessageCreate onCreate RUN
3:07:57.273 PM onMessageCreate trying to send push notification
3:07:57.757 PM onMessageCreate Message sent
3:07:57.759 PM onMessageCreate { results: [ { messageId: '0:1561550877745153%be2b376ebe2b376e' } ],
  canonicalRegistrationTokenCount: 0,
  failureCount: 0,
  successCount: 1,
  multicastId: 5684437879493655000 }
3:07:57.771 PM onMessageCreate Function execution took 1008 ms, finished with status: 'ok'

I am unsure why the onCreate event is not being triggered when adding a record to /user-chat. I have even tried using a different path, like /chat, but that did not resolve the issue either.

Any insights or advice on this matter would be greatly appreciated.

Thank you!

Answer №1

Problem solved! I successfully implemented a mask, for example /user-chat/{anything}.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to implementing angularjs app.service and $q in typescript

I am fairly new to TypeScript and AngularJS and I am struggling to find the correct answer for my issue. Below is the relevant code snippet: export class SidenavController { static $inject = ['$scope', '$mdSidenav']; constructor(p ...

"Troubleshooting: State array in ReactJS/NextJS not rendering correctly following setState

I am facing challenges with rendering my objects using .map() within React / NextJS. Within my code, I have a function where I retrieve images from Firebase Cloud Storage as shown below: getImages = () => { let firebase = loadFirebase() ...

Deno.Command uses backslashes instead of quotes for input containment

await new Deno.Command('cmd', { args: [ '/c', 'start', `https://accounts.spotify.com/authorize?${new URLSearchParams({ client_id, response_type: 'code', ...

Determine the presence or absence of data in an Angular Observable

Here is an example of how I am making an API call: public getAllLocations(): Observable<any> { location = https://v/locations.pipe(timeout(180000)); return location; } In my appl ...

Preventing over-purchasing products by managing Knex.js inventory levels

Currently, I am in the process of developing an online store for my school's guild organization. I must admit that I lack experience working with databases and Knex.js is still a bit challenging for me. An issue arises when multiple users simultaneo ...

Formulate a Generic Type using an Enum

I'm currently working on a project that involves creating a generic Type using enums. Enum export enum OverviewSections { ALL = 'all', SCORE = 'score_breakdown', PERFORMANCE = 'performance_over_time', ENGAGEMENT ...

Using vuexfire's firestoreAction to bind with a specific argument is a powerful

I'm attempting to connect my module's store to a document import Vue from 'vue' import { db } from '../my-firebase/db' import { firestoreAction } from 'vuexfire' export const user = { ... actions: { ...

A guide to efficiently removing an element in Angular using TypeScript by considering certain properties

I need help removing an element from an array based on any property such as its key, name, or email. HTML <tr *ngFor="let person of persons;" (click)="remove(person.key)"> <td>{{person.key}}</td> <td>{{person.name}}</td> ...

The 'RouterLink' JSX element type is missing any construct or call signatures

While researching this issue on the internet and Stack Overflow, I've noticed a common theme with problems related to React. An example can be found here. However, I am working with Vue and encountering errors in Vue's own components within a new ...

JSONPath encounters an issue when square brackets are embedded within a string

I am encountering issues with the JSONPath library found at https://github.com/JSONPath-Plus/JSONPath in its latest version. For example: { "firstName": "John", "lastName": "doe", "age": 26, ...

Angular's trio of services tied in a circle of dependency

I'm encountering an issue with my angular project. These warnings keep popping up: WARNING in Circular dependency detected: src\app\core\http\content.service.ts -> src\app\core\http\domain.service.ts -> ...

When trying to update the Firebase Realtime Database, an error occurs with the function db._checkNotDeleted

While attempting to update the tree using the @firebase/database library's set function, I encountered the following error: Reference_impl.ts:482 Uncaught (in promise) TypeError: db._checkNotDeleted is not a function at ref (Reference_impl.ts:482: ...

Error encountered while transforming object due to index type mismatch

I am attempting to change the values of an object, which consist of arrays with numbers as keys, to their respective array lengths. However, I received a type error that says 'Element implicity has any type because a string element cannot be used to ...

Tips for choosing the node_modules distribution flavor to include in your webpack bundle

Issue: Following the update of AJV.js to Version 6.4, my vendor bundle now includes the "uri-js" ESNEXT version instead of the ES5 version, causing compatibility issues with IE11. Analysis: Upon investigation, I discovered that AJV references uri-js usi ...

Is there a method to restrict the scope of identical components appearing multiple times on a single page in Angular 7?

I have a scenario where I need to place multiple instances of the same component on a page, but when one of them receives input and refreshes, all other components also refresh. Is there a way to prevent this from happening? <tr *ngFor="let map of imgs ...

Avoid using propTypes for props verification

Looking for a solution to handle multiple props on a button: interface buttonProps { secondary?: boolean; tertiary?: boolean; width?: number; children?: any; icon?: string; } If the button includes an icon without any children, how can ...

Slideshow through each item using Typescript and Angular8

I came across a solution in this carousel on by one link, but I'm struggling to work with the jQuery code even though I have JQuery installed in my project. For example: const next = jQuery(this).next(); I am looking to convert the JQuery code from ...

Managing Modules at Runtime in Electron and Typescript: Best Practices to Ensure Smooth Operation

Creating an Electron application using Typescript has led to a specific project structure upon compilation: dist html index.html scripts ApplicationView.js ApplicationViewModel.js The index.html file includes the following script tag: <script ...

Wildcard routes taking precedence over other defined routes

Currently, I'm developing a Node.js server utilizing Express.js and Typescript. Within my project structure, there is a folder named "routes" where I store .ts files containing route definitions. An example of a route file might appear like this: impo ...

Angular 4 - Seeking clarification on the usage of *ngComponentOutlet

When using *ngComponentOutlet, the following code snippets are employed to handle the displaying: Below is a snippet of functional code: this.displayComponent({ 'objects':[ {component: ToDisplayAComponent, expanded: fals ...