Created
August 28, 2020 05:45
-
-
Save sandipndev/8e1a01f9d05e5d941e01a9ce1f7eaaa0 to your computer and use it in GitHub Desktop.
Hally Cloud Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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