title: How to send notification for each incoming message in firebase (React js)?
body: <p>I have a simple chat webapp where two people can talk to each other. I want them to get notifications when they get a new message. So far I managed to get the permission from the user and also got the token:</p>
  <pre><code>const messaging = firebase.messaging();
  function InitializeFirebaseMessaging(){
    messaging.requestPermission().then(function(){
      console.log(&quot;Notification permission&quot;);
      return messaging.getToken();
    }).then(function(token){
      console.log(&quot;Token: &quot;+token);
    }).catch(function (reason){
      console.log(reason);
    });
  }
  messaging.onMessage(function (payload){
    console.log(payload);
  });
  messaging.onTokenRefresh(function () {
    messaging.getToken()
        .then(function (newtoken) {
            console.log(&quot;New Token : &quot;+ newtoken);
        })
        .catch(function (reason) {
            console.log(reason);
        })
  });
  </code></pre>
  <p>In the Firestore I have a &quot;pairings&quot; collection where I have paired up users (so only pairs can send messages to each other) and there is a collection for each user with their sent and received messages.</p>
  <p>When I log into Firebase, go to Engage/Cloud Messaging, I can send a message to that user from Firebase using the token. How can I achieve sending notifications automatically to the other person for each incoming message?</p>