utils

helper/notification.js

const { messaging } = require("../config/firebase");

const notification = {
  async run(topic, title, description) {
    this.postNotificationTokens(title, description);
    this.postNotificationTopic(topic, title, description);
  },
  async postNotificationTopic(topic, title, description) {
    const message = {
      data: {
        title: title,
        description: description,
      },
      topic: topic,
    };

    messaging
      .send(message)
      .then((response) => {
        // Response is a message ID string.
        console.log("Successfully sent topic:", topic, response);
      })
      .catch((error) => {
        console.log("Error sending message, postNotificationTopic");
      });
  },
  async postNotificationTokens(title, description) {
    const registrationToken = [
      "c17vD0QGPhhjNE1TfnuAp5:APA91bEpV2gNrhAzLCYaD4WVzfKTBSrmbq0Ip1IcsC3GMpNhRzfTwfeWx_nc84XURRxZK9yxWjTNrcZQ6OrbAsQkaXKS4efWkX0JZI997HMLGrrCGOZrCT7JZK09qflPW3JBuIq4m30M",
      "fAuz2s3uUIopLY6Fw4MBwf:APA91bE6sNspy4Pus33RvUI2SnIsxMdG3IETcmlhvOnvHTFOB-ELI3biPJ5auwlLli-IW2f46lOMcAncvknpMO8gpZQ3zl2NgXffctlOMMb0N3SVwipZa5G_qbTKr_BgnEeQzsx8fqiY",
      "fnlFBS4fiwsQZOgC6fW32j:APA91bGwFSKuSKpyvrpRHTcSWgdQ25ddvbl1tQOFzRrMKUoPSWFUVsoSfEgoZhx-guk2SJtZjoa5nOhF-9ywwkIal0hBt3GpjebI3yEq_CXe9xPsdgqSYEMpi5Av320eJuXJzVgQBFL5",
    ];
    const message = {
      data: {
        title: title,
        description: description,
      },
      tokens: registrationToken,
    };

    messaging
      .sendMulticast(message)
      .then((response) => {
        // Response is a message ID string.
        console.log("Successfully sent notification STRATEGIES TO ADMIN");
      })
      .catch((error) => {
        //   console.log("Error sending message:", error);
        console.log("error postNotificationAdmin");
      });
  },
};
module.exports = notification;

Last updated

Was this helpful?