Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _HelpScreenState extends State<HelpScreen> {
// Replace with your country's emergency number, e.g., "112" or "911"
final status = await Permission.phone.request();
print(status);
final Uri launchUri = Uri(scheme: 'tel', path: '411');
final Uri launchUri = Uri(scheme: 'tel', path: '<PHONE_NUMBER>');
if (await canLaunchUrl(launchUri)) {
await launchUrl(launchUri);
} else {
Expand Down
53 changes: 53 additions & 0 deletions stml_functions/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Import function triggers from their respective submodules:
*
* const {onCall} = require("firebase-functions/v2/https");
* const {onDocumentWritten} = require("firebase-functions/v2/firestore");
*
* See a full list of supported triggers at https://firebase.google.com/docs/functions
*/

// const {onRequest} = require("firebase-functions/v2/https");
// const logger = require("firebase-functions/logger");

// Create and deploy your first functions
// https://firebase.google.com/docs/functions/get-started

// exports.helloWorld = onRequest((request, response) => {
// logger.info("Hello logs!", {structuredData: true});
// response.send("Hello from Firebase!");
// });


const functions = require("firebase-functions");
const admin = require("firebase-admin");

// Initialize Firebase Admin SDK
admin.initializeApp();

// Cloud Function to send notifications to a topic
exports.sendNotification = functions.https.onRequest((req, res) => {
// Extract topic and message from the request body
const topic = req.body.topic;
const message = req.body.message;

// Construct the notification payload
const payload = {
notification: {
title: req.body.title,
body: message,
},
topic: topic,
};

// Send the message to the topic using Firebase Admin SDK
admin.messaging().send(payload)
.then((response) => {
console.log("Notification sent successfully:", response);
res.status(200).send("Notification sent successfully!");
})
.catch((error) => {
console.error("Error sending notification:", error);
res.status(500).send("Error sending notification");
});
});