I already did an app in Android studio but I'm building a WebPage to send a notification to Firebase Messaging to push notifications on the app.
This is the module to get Firebase properties
//class name: network.js
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-app.js";
import {
getMessaging,
getToken,
} from "https://www.gstatic.com/firebasejs/9.22.1/firebase-messaging.js";
const firebaseConfig = {
i have all information about my firebase project and keys
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const getData = getDatabase(app);
const messaging = getMessaging(app);
export { messaging, getToken };
here is my script file to use they: // classname: script.js
import { messaging , getToken } from "./network.js"
const topic = "cozinha";
const message = {
notification: {
title: "Test Title",
body: "Test Body example text",
},
topic: topic,
};
getMessaging()
.send(message)
.then((response) =\> {
// Response is a message ID string.
console.log("Successfully sent message:", response);
})
.catch((error) =\> {
console.log("Error sending message:", error);
});
When I try to use it I receive an error called:
Uncaught ReferenceError: getMessaging is not defined
I tried to use other ways like:
messaging.send() ....
Uncaught TypeError: messaging.send is not a function
messaging.getMessaging().send ...
Uncaught TypeError: messaging.getMessaging is not a function
I hope you guys can help me. Thank you and have a nice day.