0.2.3 • Published 1 year ago

mysignal v0.2.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Firebase and Huawei Cloud Messaging SDK for Nodejs

This the wrapper on firebase-admin and hcm-admin

Contents

Install

This package depends on firebase-admin. Make sure to install it.

npm install firebase-admin mysignal

Usage

const { MysignalAdmin } = require('mysignal')
const firebaseAdmin = require('firebase-admin')
const serviceAccount = require('./firebase-service-account.json')
const huaweiConfig = require('./huawei-config.json')

const admin = new MysignalAdmin()
// initialize FCM and HCM
admin.initializeApp({
  firebase: {
    credential: firebaseAdmin.credential.cert(serviceAccount),
  },
  huawei: {
    appId: huaweiConfig.appId,
    appSecret: huaweiConfig.appSecret,
  }
})
// or just initialize one service
// firebase
admin.initializeFirebase({
  credential: firebaseAdmin.credential.cert(serviceAccount),
})
// or huawei
admin.initializeHuawei(huaweiConfig)

// send notification
await admin.messaging().send({
  token: '<some push token>',
  notification: {
    title: '<title>',
    body: '<message>',
  },
  data: { hello: 'world' },
})

Subscribe/unsubscribe

await admin.messaging().subscribeToTopic([token1, token2], topicName)
await admin.messaging().unsubscribeFromTopic([token1, token2], topicName)

Sending messages

// to topic
await admin.messaging().sendToTopic(topicName, {
  notification: {
    title: '<title>',
    body: '<body>',
  },
  data: { hello: 'world' },
})

// conditional
await admin.messaging().send({
  condition: "'topicA' in topics || 'topicB' in topics",
  notification: {
    title: '<title>',
    body: '<body>',
  },
  data: { hello: 'world' },
})

// individual
await admin.messaging().send({
  token: '<token>',
  notification: {
    title: '<title>',
    body: '<body>',
  },
  data: { hello: 'world' },
})

// multicast
await admin.messaging().sendEach({
  tokens: ['<token1>', '<token2>'],
  notification: {
    title: '<title>',
    body: '<body>',
  },
  data: { hello: 'world' },
})
0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago