Skip to content

messaging HowTo

GitHub Action edited this page Apr 21, 2026 · 1 revision

How To: Using @quatrain/messaging

This guide covers the core operations for sending notifications.

Table of Contents

  1. Registering Messaging Adapters
  2. Sending Messages

1. Registering Messaging Adapters

You can register different adapters for different communication channels.

import { Messaging } from '@quatrain/messaging'
import { FirebaseMessagingAdapter } from '@quatrain/messaging-firebase'

const fcmAdapter = new FirebaseMessagingAdapter({
    config: { /* Firebase credentials */ }
})

// Register the push notification adapter
Messaging.addAdapter('push', fcmAdapter)

2. Sending Messages

To send a message, retrieve the appropriate adapter and construct your payload. The payload structure depends on the underlying provider, but standard fields (title, body, recipient) are generally normalized.

import { Messaging } from '@quatrain/messaging'

async function notifyUser(deviceToken: string) {
    const pushAdapter = Messaging.getAdapter('push')
    
    await pushAdapter.send({
        to: deviceToken,
        notification: {
            title: 'Your order has shipped!',
            body: 'Track your package in the app.'
        },
        data: {
            orderId: '12345'
        }
    })
    
    console.log('Push notification sent.')
}

Clone this wiki locally