title: How to trigger a cloud function when sending a firebase cloud message?
body: <p>I'm trying to trigger a firebase cloud functions once a user creates a new firebase cloud message(FCM).</p>
  
  <p>This <a href="https://firebase.google.com/docs/cloud-messaging/manage-topics" rel="nofollow noreferrer">documentation page</a> describes exactly what to do.</p>
  
  <p>Here's my code on the server side :</p>
  
  <p>Side Note: <em>subscribeToTopic</em> can take one token or an array of tokens.</p>
  
  <pre><code>admin.messaging().subscribeToTopic(fcmToken, "/topics/news")
  .then(res =&gt; {
      console.log('res: ', res);
  })
  .catch(error =&gt;{
      console.log('error: ', error);
  });
  </code></pre>
  
  <p>Assume fcmToken is a valid token, created from my device(client-side), i double checked it.</p>
  
  <p>Now, to test if it works: I create a new notification using the notification web console provided by firebase, and after choosing title and body, i get to choose the topic like in the image.
  <a href="https://i.stack.imgur.com/bobAb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bobAb.png" alt="choosing a topic for the message"></a></p>
  
  <p><strong>The problem is that the cloud function is not getting triggered at all.</strong></p>