Skip to content

Instantly share code, notes, and snippets.

@sandipndev
Created August 28, 2020 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandipndev/8e1a01f9d05e5d941e01a9ce1f7eaaa0 to your computer and use it in GitHub Desktop.
Save sandipndev/8e1a01f9d05e5d941e01a9ce1f7eaaa0 to your computer and use it in GitHub Desktop.
Hally Cloud Functions
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import * as express from "express";
const app = express();
app.use(express.json());
const topic = "hally";
admin.initializeApp(functions.config().firebase);
app.post("/subscribe", (req, res) => {
const token: string = req.body.token;
admin
.messaging()
.subscribeToTopic(token, topic)
.then(res.send)
.catch(res.send);
});
app.post("/notifyOthers", (req, res) => {
admin
.messaging()
.send({
data: req.body,
topic,
})
.then(res.send)
.catch(res.send);
});
export const widgets = functions.https.onRequest(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment