title: Send notifications conditionally using Firebase cloud functions?
body: <p>I am writing an android application where I need to send a notification based on some condition.</p>
  
  <p><a href="https://i.stack.imgur.com/SqWhH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SqWhH.png" alt="enter image description here"></a></p>
  
  <p>For example, when <code>notiType = home</code> then send other message in notification. If <code>notiType = inBetween</code> then send another message</p>
  
  <p>I have written the cloud function for this but getting an error while deploying.</p>
  
  <p>Here is the cloud function :</p>
  
  <pre class="lang-js prettyprint-override"><code>'use strict';
  
  const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  
  admin.initializeApp(functions.config().firebase);
  
  /* Listens for new messages added to /messages/:pushId and sends a notification to users */
  exports.pushNotification = functions.database.ref('/Notifications/{user_id}/{notification_id}').onWrite(event =&gt; {
    console.log('Push notification event triggered');
    /* Grab the current value of what was written to the Realtime Database 
     */
    const userId = event.params.user_id;
    const notificationId = event.params.notification_id;
  
  
    const deviceToken = admin.database().ref(`Notifications/${userId}/${notificationId}/deviceToken`).once('value');
    const childName = admin.database().ref(`Notifications/${userId}/${notificationId}/childName`).once('value');
    const notificationType = admin.database().ref(`Notifications/${userId}/${notificationId}/type`).once('value');
  
    return Promise.all([deviceToken, childName, notificationType]).then(result =&gt; {
  
      const token = result[0].val();
      const name = result[1].val();
      const type = result[2].val();
  
      /* Create a notification and data payload. They contain the notification information, and message to be sent respectively */
  
      const payload;
  
      switch (type) {
        case "home":
          payload = {
            notification: {
              title: 'App Name',
              body: `${name} is reached at home`,
              sound: "default"
            }
          };
          break;
        case "between":
          payload = {
            notification: {
              title: 'App Name',
              body: `${name} stuck on the way for some reason`,
              sound: "default"
            }
          };
          break;
        case "school":
          payload = {
            notification: {
              title: 'App Name',
              body: `${name} reached at school`,
              sound: "default"
            }
          };
          break;
      };
  
      return admin.messaging().sendToDevice(token, payload).then(response =&gt; {
        return null;
      });
    });
  });
  </code></pre>
  
  
  
  <p>Getting this error :</p>
  
  <p><a href="https://i.stack.imgur.com/dRwvx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dRwvx.png" alt="Getting this error"></a></p>
  
  <p>Please correct me where I am going wrong. Using Firebase -tools version 5.0.1</p>