Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as functions from 'firebase-functions';
- import * as admin from 'firebase-admin';
- admin.initializeApp();
- exports.salvandoBanco = functions.https.onRequest((request, response) => {
- return admin.database().ref('id_salvo').set(request.query.id).then(() => {
- response.send("ID salvo: " + request.query.id);
- })
- });
- exports.notificacao = functions.https.onRequest((request, response) => {
- let not = {
- notification: {
- title: 'Sua mensagem!',
- body: 'Conteúdo da notificação',
- }
- };
- //let token = 'crH8dfHlGRM:APA91bEWoeBwUauSQWFszcCuwAoeVwBD1wsvIMaQomyjsiLFLr2hDRqMddq_dGMUjYIakd-ECsFFy0qdXeInc2ZYK-5ErNm7VTF5HwXjYgBZC3WYjxICXT1w6V-wYuJ1Y8Fi9dVMTeiw';
- //return admin.messaging().sendToDevice(token, not);
- return admin.messaging().sendToTopic('topico', not);
- })
- //Caminho referência que será observado caso surge novo valor
- exports.bancoExemplo = functions.database.ref('/usuarios/{usuarioID}')
- .onCreate((snapshot, context) => {
- //Recupera o ultimo conteúdo criado neste caminho, onde o ultimo trecho pode variar
- let dados = {
- usuarioID: context.params.usuarioID,
- valor: snapshot.val()
- }
- return admin.database().ref('ultimo_usuario').set(dados);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement