title: How can scheduled Firebase Cloud Messaging notifications be made outside of the Firebase Console?
body: <p>Inside the Firebase Console, under the Cloud Messaging view, users are able to create test notifications. This functionality also allows you to schedule the time at which the notification will send to a device or set of devices.</p>
  <p>Is it possible to create and send <strong>scheduled</strong> FCM notifications to specific devices by using firebase cloud functions and the Firebase Admin SDK? Is there an alternative way to solving this?</p>
  <p>The current way that I send scheduled messages to users is like so:</p>
  <pre class="lang-js prettyprint-override"><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  const schedule = require('node-schedule');
  admin.initializeApp();
  
  exports.setScheduledNotification = functions.https.onRequest(async (req, res) =&gt; {
      const key = req.query.notification_key;
  
      const message = {
          notification: {
              title: 'Test Notification',
              body: 'Test Notification body.'
          }
      };
  
      var currentDate = new Date();
      var laterDate = new Date(currentDate.getTime() + (1 * 60000));
  
      var job = schedule.scheduleJob(key, laterDate, () =&gt; {
          const snapshot = admin.messaging().sendToDevice(key, message);
      });
  
      return res.status(200).send(`Message has been scheduled.`);
  });
  </code></pre>
  <p>First of all, I am unsure how <code>node-schedule</code> interacts with firebase cloud functions. The logs appear that the function terminates very quickly which I would think would be correct. The longer the operation runs the more costly it is in our firebase bills. The notification does still run on a scheduled time though. I'm confused on how that all is working behind the scenes.</p>
  <p>Secondly, I am having issues canceling these scheduled notifications. The notifications will most likely be on a 2hr timed schedule from the point it gets created. Before the 2hrs is up, I'd like the have the ability to cancel/overwrite the notification with an updated scheduled time.</p>
  <p>I tried this to cancel the notification and it failed to find the previously created notification. Here is the code for that:</p>
  <pre class="lang-js prettyprint-override"><code>exports.cancelScheduledNotification = functions.https.onRequest(async (req, res) =&gt; {
      const key = req.query.notification_key;
  
      var job = schedule.scheduledJobs[key];
      job.cancel();
  
      return res.status(200).send(`Message has been canceled.`);
  });
  </code></pre>
  <p>Is it possible to tap into the scheduling functionality of firebase cloud messaging outside of the firebase console? Or am I stuck with hacking my way around this issue?</p>