How to use the firebase-admin.messaging function in firebase-admin

To help you get started, we’ve selected a few firebase-admin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github androidthings / photobooth / firebase / functions / assistant-app / request-handlers.js View on Github external
function sendFirebaseCommand (command) {
  // figure out how to delay the set about of time
  // i.e. wait(delay);

  // Define capture command playload for FCM message
  var payload = {
    data: {
      cmd: command
    }
  };
  // Send a message to devices subscribed to the provided topic.
  admin.messaging().sendToTopic(TOPIC, payload)
    .then(function (response) {
      // See the MessagingTopicResponse reference documentation for the
      // contents of response.
      console.log('Successfully sent message:', response);
      console.log('"' + KEY_FOR_COMMAND + ': ' + command + '"' + ' to topic ' + TOPIC);
    })
    .catch(function (error) {
      console.log('Error sending message:', error);
      console.log('"' + KEY_FOR_COMMAND + ': ' + command + '"' + ' to topic ' + TOPIC);
    });
}
github smartnav / fcm-notification / lib / fcm.js View on Github external
this.unsubscribeFromTopic = function(registrationTokens, topic, callback) {
          admin.messaging().unsubscribeFromTopic(registrationTokens, topic)
              .then(function(response) {
                // See the MessagingTopicManagementResponse reference documentation
                // for the contents of response.
                callback(null,response)
                console.log('Successfully unsubscribed to topic:', response);
              })
              .catch(function(error) {
                callback(error)
                console.log('Error unsubscribing to topic:', error);
              });
        }
github chat-sdk / chat-sdk-android / FirebasePushNotifications / index.js View on Github external
if(threadId === "undefined" || !threadId || threadId === null) {
        throw new functions.https.HttpsError("invalid-argument", "Sender ID not valid");
    }

    if(body === "undefined" || !body || body === null) {
        throw new functions.https.HttpsError("invalid-argument", "Sender ID not valid");
    }

    var status = {};
    for(let uid in userIds) {
        if(userIds.hasOwnProperty(uid)) {
            let userName = userIds[uid];
            let message = buildMessage(userName, body, action, sound, type, senderId, threadId, uid);
            status[uid] = message;
            admin.messaging().send(message);
        }
    }
    // return Promise.all(promises);
    // return res.send(status);
    return status;

});
github Temzasse / yak-chat / server / notifications.js View on Github external
export const notifyChannel = (channelId, { title, body }) => {
  if (!title || !body) return; // bail out

  const msg = { notification: { title, body } };
  admin.messaging().sendToTopic(channelId, msg)
    .then(response => {
      logger.info('Successfully sent message:', response);
    })
    .catch(error => {
      logger.info('Error sending message:', error);
    });
};
github shalvah / RemindMeOfThisTweet / src / notifications.js View on Github external
async sendNotification(token, username, tweetUrl) {
        const message = {
            data: {
                title: `Here's your reminder, @${username}.👋`,
                body: `You set this reminder with @RemindMe_OfThis. Tap to view the tweet.`,
                url: tweetUrl,
            },
            token
        };

        return firebase.messaging().send(message)
            .then((response) => {
                console.log('notification.send.success:' + JSON.stringify(response));
            })
            .catch((error) => {
                console.log('notification.send.error:' + JSON.stringify(error));
            });
    }
};
github TarikHuber / react-most-wanted / packages / cra-template-rmw / template / functions / utils / notifications.js View on Github external
.then(snapshot => {
        let registrationTokens = []

        snapshot.forEach(token => {
          if (token.val()) {
            registrationTokens.push(token.key)
          }
        })

        if (registrationTokens.length) {
          return admin.messaging().sendToDevice(registrationTokens, payload)
        } else {
          console.log('Not tokens registered')
          return null
        }
      })
  },
github stmoreau / chat-ara / functions / index.js View on Github external
Promise.all([getTokens, getAuthor]).then(([tokens, author]) => {
      const payload = {
        notification: {
          title: `Awesome message from ${author.displayName}`,
          body: message.content,
          icon: author.photoURL
        }
      };

      admin.messaging().sendToDevice(tokens, payload).catch(console.error);
    });
  });
github codediodeio / ionic4-master-course / functions / lib / fcm.js View on Github external
icon: 'https://angularfirebase.com/images/logo.png',
                actions: [
                    {
                        action: 'like',
                        title: '👍 Yaaay!'
                    },
                    {
                        action: 'dislike',
                        title: '☹ Boooo!'
                    }
                ]
            }
        },
        topic: 'discounts'
    };
    return admin.messaging().send(payload);
}));
//# sourceMappingURL=fcm.js.map
github karnikram / the-ssn-app / firebase-cloud-functions / functions / index.js View on Github external
sound: "default"
    },
    data: {
        title: expanded,
        content: snapshot.val().title,
        color: '#2196F3'
    }
  };

  const options = {
        priority: "high",
        timeToLive: 60 * 60 * 24 * 7 * 4
   };


  return admin.messaging().sendToTopic(category, payload, options);
});
github codediodeio / ionic4-master-course / functions / src / fcm.ts View on Github external
actions: [
            {
              action: 'like',
              title: '👍 Yaaay!'
            },
            {
              action: 'dislike',
              title: '☹ Boooo!'
            }
          ]
        }
      },
      topic: 'discounts'
    };

    return admin.messaging().send(payload);
  });