Push notifications

From tinh2/skills-hub-registry · View interactive version

Push notifications is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Add push notifications to my app — set up FCM, APNs, or OneSignal for Flutter, React Native, Expo, or web with permission flows, foreground and background handlers, notification channels, topic subscriptions, deep link routing, and device token management

How to use this skill

Skill file

You are in AUTONOMOUS MODE. Do NOT ask questions. Execute the full pipeline below

without pausing for user input. Make reasonable decisions using sensible defaults.

PURPOSE:

Set up a complete push notification system for mobile and/or web platforms. This includes

provider SDK installation, credential configuration, a notification service layer,

foreground and background notification handling, topic/channel management, deep link

routing, and verification that notifications deliver correctly.

INPUT:

$ARGUMENTS

The user may specify:

  1. Provider: "fcm", "apns", "onesignal" (default: auto-detect based on platform)
  2. Platform: "flutter", "react-native", "web", "ios", "android" (default: auto-detect)
  3. Features: "topics", "deep-links", "rich" (rich media notifications)

If no arguments, auto-detect the platform and use FCM as the default provider.

=== PHASE 1: PLATFORM DETECTION ===

Step 1.1 — Detect Client Platform

Scan for project files to determine the platform:

| File / Pattern | Platform | Default Provider |

|---------------|----------|-----------------|

| pubspec.yaml | Flutter (iOS + Android + Web) | FCM via firebase_messaging |

| package.json with "react-native" | React Native (iOS + Android) | FCM via @react-native-firebase/messaging |

| package.json with "expo" | Expo (React Native) | Expo Notifications (wraps FCM/APNs) |

| package.json with "next" or "react" | Web | FCM via firebase/messaging or Web Push API |

| Podfile / *.xcodeproj | Native iOS | APNs directly or FCM |

| build.gradle with android | Native Android | FCM |

Record: PLATFORM, CLIENT_ROOT, PROVIDER

Step 1.2 — Detect Backend

Scan for a backend server (notifications need a server component):

Record: BACKEND_FRAMEWORK, BACKEND_ROOT

Step 1.3 — Check Existing Push Setup

Search for existing push notification code:

expo-notifications, firebase-admin

If complete push notification system exists, report it and exit.

If partial, identify gaps and extend.

=== PHASE 2: CLIENT SDK INSTALLATION ===

Step 2.1 — Install Client SDK

Based on platform and provider:

Flutter + FCM:

flutter pub add firebase_messaging firebase_core
flutter pub add flutter_local_notifications  # for foreground display

Ensure firebase_core is initialized in main.dart.

Run flutterfire configure if Firebase is not yet configured.

React Native + FCM:

npm install @react-native-firebase/app @react-native-firebase/messaging
cd ios && pod install

Expo + Expo Notifications:

npx expo install expo-notifications expo-device expo-constants

Web + FCM:

npm install firebase

Create public/firebase-messaging-sw.js service worker.

Native iOS + APNs:

OneSignal (any platform):

Step 2.2 — Install Server SDK

On the backend (for sending notifications):

FCM (via firebase-admin):

APNs (direct):

OneSignal:

=== PHASE 3: CREDENTIAL CONFIGURATION ===

Step 3.1 — Configure Provider Credentials

FCM:

```

FIREBASE_PROJECT_ID=

FIREBASE_PRIVATE_KEY=

FIREBASE_CLIENT_EMAIL=

```

```

NEXT_PUBLIC_FIREBASE_VAPID_KEY=

```

APNs:

```

APNS_KEY_ID=

APNS_TEAM_ID=

APNS_KEY_PATH=./certs/AuthKey.p8

APNS_BUNDLE_ID=com.yourapp.id

```

OneSignal:

```

ONESIGNAL_APP_ID=

ONESIGNAL_API_KEY=

```

Add all variables to .env.example with descriptions.

Step 3.2 — Platform-Specific Configuration

Flutter / Android:

```xml

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id"

android:value="default_channel"/>

```

Flutter / iOS:

React Native / Android:

React Native / iOS:

Web:

```js

importScripts('https://www.gstatic.com/firebasejs/10.x/firebase-app-compat.js');

importScripts('https://www.gstatic.com/firebasejs/10.x/firebase-messaging-compat.js');

firebase.initializeApp({ /* config */ });

const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {

self.registration.showNotification(payload.notification.title, {

body: payload.notification.body,

icon: '/icon-192x192.png',

});

});

```

=== PHASE 4: NOTIFICATION SERVICE (SERVER) ===

Step 4.1 — Create Notification Service

Create a server-side notification service:

class NotificationService {
  async sendToDevice(params: {
    token: string;
    title: string;
    body: string;
    data?: Record<string, string>;
    imageUrl?: string;
    badge?: number;
    sound?: string;
    channelId?: string;
  }): Promise<{ success: boolean; messageId?: string }>

  async sendToTopic(params: {
    topic: string;
    title: string;
    body: string;
    data?: Record<string, string>;
  }): Promise<{ success: boolean; messageId?: string }>

  async sendToMultiple(params: {
    tokens: string[];
    title: string;
    body: string;
    data?: Record<string, string>;
  }): Promise<{ successCount: number; failureCount: number; failedTokens: string[] }>

  async subscribeToTopic(params: {
    tokens: string[];
    topic: string;
  }): Promise<{ success: boolean }>

  async unsubscribeFromTopic(params: {
    tokens: string[];
    topic: string;
  }): Promise<{ success: boolean }>
}

The service MUST:

Step 4.2 — Create Device Token Management

Create an API endpoint and storage for device tokens:

Route: POST /api/notifications/register-device

Route: DELETE /api/notifications/unregister-device

Create a device token model/table:

DeviceToken {
  id: string
  userId: string
  token: string (unique)
  platform: "ios" | "android" | "web"
  createdAt: DateTime
  lastUsedAt: DateTime
}

Step 4.3 — Create Notification API Endpoints

Route: POST /api/notifications/send

Route: POST /api/notifications/send-topic

=== PHASE 5: CLIENT-SIDE HANDLING ===

Step 5.1 — Permission Request

Create a permission request flow:

Flutter:

final messaging = FirebaseMessaging.instance;
final settings = await messaging.requestPermission(
  alert: true, badge: true, sound: true,
  provisional: false,  // set true for quiet notifications on iOS
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
  final token = await messaging.getToken();
  // Send token to backend
}

React Native:

const authStatus = await messaging().requestPermission();
if (authStatus === messaging.AuthorizationStatus.AUTHORIZED) {
  const token = await messaging().getToken();
  // Send token to backend
}

Web:

const permission = await Notification.requestPermission();
if (permission === 'granted') {
  const token = await getToken(messaging, { vapidKey: VAPID_KEY });
  // Send token to backend
}

The permission flow MUST:

Step 5.2 — Foreground Notification Handling

When the app is in the foreground, notifications are NOT displayed by default on most platforms.

Create a foreground handler:

Flutter:

React Native:

Web:

Step 5.3 — Background Notification Handling

Configure background message handling:

Flutter:

React Native:

Web:

Step 5.4 — Notification Tap / Open Handling

Handle what happens when a user taps a notification:

Flutter:

React Native:

Web:

=== PHASE 6: TOPICS AND CHANNELS ===

Step 6.1 — Create Topic Management

Define standard topics for the application:

TOPICS = {
  GENERAL: 'general',           // All users
  ANNOUNCEMENTS: 'announcements', // Product announcements
  MARKETING: 'marketing',        // Promotional content (opt-in)
}

Create a notification preferences screen/page:

Step 6.2 — Create Android Notification Channels

For Android (required for Android 8.0+):

Channels:
  - default: General notifications (importance: high)
  - messages: Chat messages (importance: high, vibration: true)
  - updates: App updates (importance: default)
  - marketing: Promotional (importance: low)

Create channels during app initialization, before any notification is received.

Step 6.3 — Deep Link Configuration

Set up deep linking so notification taps navigate to the correct screen:

Flutter:

```

data: { route: '/orders/123', type: 'order_update' }

→ Navigate to OrderDetailScreen(orderId: '123')

```

React Native:

Web:

The deep link handler MUST:

=== PHASE 7: VERIFICATION ===

Step 7.1 — Static Verification

Run the project's linter and type checker:

Fix all errors introduced by the push notification integration.

Step 7.2 — Integration Checklist

Verify and report:

=== OUTPUT ===

Print the following summary:


Push Notification Integration Complete

Platform: [detected platform]

Provider: [selected provider]

Backend: [detected backend framework]

Files Created/Modified

| File | Purpose |

|------|---------|

| [path] | [description] |

Environment Variables Required

| Variable | Purpose | Where to get it |

|----------|---------|-----------------|

| [KEY] | [purpose] | [provider console URL] |

Notification Endpoints

| Method | Path | Purpose |

|--------|------|---------|

| POST | /api/notifications/register-device | Register device token |

| DELETE | /api/notifications/unregister-device | Remove device token |

| POST | /api/notifications/send | Send to specific user |

| POST | /api/notifications/send-topic | Send to topic subscribers |

Topics Configured

| Topic | Description | Default |

|-------|-------------|---------|

| general | All users | Subscribed |

| announcements | Product updates | Subscribed |

| marketing | Promotional | Opt-in |

Testing

  1. FCM: Use Firebase Console > Cloud Messaging > Send test message
  2. FCM CLI: firebase messaging:send --json '{"token":"...","notification":{"title":"Test"}}'
  3. Backend: Call POST /api/notifications/send with a valid user ID
  4. Verify foreground: Send while app is open — should show in-app notification
  5. Verify background: Send while app is backgrounded — should show system notification
  6. Verify tap: Tap the notification — should navigate to correct screen

=== NEXT STEPS ===

After push notification integration:

=== DO NOT ===

============================================================

SELF-HEALING VALIDATION (max 3 iterations)

============================================================

After completing the integration, validate:

  1. Run the project's test suite to verify the integration works end-to-end.
  2. Run build/compile to confirm no breakage.
  3. Verify the integration responds correctly (health checks, test calls, smoke tests).
  4. If failures occur, diagnose from error output and apply minimal fixes.
  5. Repeat up to 3 iterations.

IF STILL FAILING after 3 iterations:

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /push-notifications — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.