title: Why might this Cloud Function not be triggering a notification?
body: <p>I am writing a Cloud Function in Firebase that sends a notification to devices with tokens that are stored as documents in a collection:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  
  admin.initializeApp();
  
  exports.sendDMNotification = functions.firestore.document('/dm_threads/{thread_id}/messages/{message_id}')
      .onCreate((snapshot, context) =&gt; {
  
  
          const newMessage = snapshot.data();
  
          const senderName = newMessage.authorName;
          const senderID = newMessage.authorUID;
          const messageText = newMessage.message;
          const recipientName = newMessage.recipientName;
          const recipientID = newMessage.recipientUID;
          const timestamp = newMessage.timestamp;
  
          console.log(senderName + " " + senderID + " " + messageText + " " + recipientName + " " + recipientID + " " + timestamp.toString());
  
          let deviceTokenQuery = admin.firestore().collection(`/Users/${recipientID}/device_tokens/`);
  
          return deviceTokenQuery.get().then(querySnapshot =&gt; {
              console.log('deviceTokenQuery returned');
  
              let tokens = querySnapshot.docs;
  
              console.log('1');
  
  
              const notificationPromises = tokens.map(token =&gt; {
                  console.log('2');
  
                  let token_id = token.tokenID.toString();
  
                  console.log('3');
  
                  const payload = {
                      notification: {
                          title: senderName,
                          body: messageText,
                          icon: "default"
                      }
                  };
  
  
                  return admin.messaging().sendToDevice(token_id, payload)
  
              });
              console.log('4');
              return Promise.all(notificationPromises);
  
          });
  
      });
  </code></pre>
  
  <p>Only "deviceTokenQuery returned", "1", and "4" log statements appear. Do I have a syntax problem or am I not using these these methods properly?</p>