Code Monkey home page Code Monkey logo

firebase-push-notifications--device-to-device-notification's People

Contributors

akshayejh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

firebase-push-notifications--device-to-device-notification's Issues

Index.js

Please Provide index.js file.

'use-strict'

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.firestore.document("Users/{user_id}/Notifications/{notification_id}").onWrite((change, context) => {

const user_id = context.params.user_id;
const notification_id = context.params.notification_id;

console.log("User ID: " + user_id + " | Notification ID " + notification_id);

return admin.firestore().collection("Users").doc(user_id).collection("Notifications").doc(notification_id).get().then(queryResult => {

	const from_user_id = queryResult.data().from;
	const from_message = queryResult.data().message;

	const from_data = admin.firestore().collection("Users").doc(from_user_id).get();

	const to_data = admin.firestore().collection("Users").doc(user_id).get();

	return Promise.all([from_data, to_data]).then(result => {
		const from_name = result[0].data().name;
		const to_name = result[1].data().name;
		const token_id = result[1].data().token_id;

		const payload = {
			notification : {
				title : "Notification From" + from_name,
				body : from_message,
				icon : "default"
			}, 
			data : {
				message : from_message,
				from_user_id : from_user_id
			}
		};

		return admin.messaging().sendToDevice(token_id, payload).then(result => {
			console.log("Notification sent");
			return 0;
		});

	});


});

});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.