(English) Possible Implementations

Updated for SDK Flutter version 3.7.1

Push Notification Handlers

Below are the required methods to properly integrate push notifications and In-App Messages using Inngage, alongside Firebase Messaging.


InngageSDK.registerSubscriber(String fcmToken)

This method must be called right after InngageSDK.subscribe(). It sends the user’s fcmToken to the Inngage API, enabling the delivery of push notifications and In-App Messages.

InngageHandlersNotification.handleForegroundNotification(...)

This method handles notifications received while the app is in the foreground. It should be called inside the FirebaseMessaging.onMessage.listen listener, as shown below:

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  final messageData = message.data;
  final hasInngageData =
      messageData.containsKey("inngageData") || messageData["provider"] == "inngage";

  if (hasInngageData) {
    InngageNotificationMessage.handleForegroundNotification(
      remoteMessageData: messageData,
      backgroundIcon: Colors.blue, // optional
    );
  } else {
    _handlerCustomNotificationForeground(message);
  }
});

📘

💡 Notifications sent via Inngage include the provider: "inngage" field in the payload. This allows you to conditionally route the handling logic to our SDK only when the message originates from Inngage.

InngageHandlersNotification.handleClickNotification(...)

This method must be called inside FirebaseMessaging.onMessageOpenedApp.listen, which is triggered when a user taps a notification while the app is in the background:

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
  final messageData = message.data;
  final hasInngageData =
      messageData.containsKey("inngageData") || messageData["provider"] == "inngage";

  if (hasInngageData) {
    InngageNotificationMessage.handlerNotificationClick(remoteMessage: message);
  } else {
    _handlerCustomNotificationClick(message);
  }
});

InngageHandlersNotification.handleTerminatedNotification(...)

This method handles notifications received when the app is completely terminated and should be placed inside FirebaseMessaging.getInitialMessage():

FirebaseMessaging.instance.getInitialMessage().then((remoteMessage) {
  if (remoteMessage == null) return;

  final messageData = remoteMessage.data;
  final hasInngageData =
      messageData.containsKey("inngageData") || messageData["provider"] == "inngage";

  if (hasInngageData) {
    InngageHandlersNotification.handleTerminatedNotification(remoteMessage: remoteMessage);
  } else {
    _handlerCustomNotificationClick(remoteMessage);
  }
}).catchError((error) {
  debugPrint("Error on getInitialMessage: $error");
});

InngageHandlersNotification.handleBackgroundNotification(...)

To ensure that In-App Messages work while the app is in the background, implement the following inside FirebaseMessaging.onBackgroundMessage():

Future<void> _firebaseBackgroundHandler(RemoteMessage message) async {
  // Your background handling logic
  await InngageHandlersNotification.handleBackgroundNotification(
    remoteMessageData: message.data,
  );
}

And register it:

FirebaseMessaging.onBackgroundMessage(_firebaseBackgroundHandler);

Notification Click Tracking

To ensure that the status of push messages sent through the platform is properly updated — identifying when the user clicks on a notification and opens the app — you need to implement the InngageSDK.updateStatusMessage(...) method.

This method should receive the response.payload value, which comes from the onDidReceiveNotificationResponse function during the initialization of the FlutterLocalNotificationsPlugin.

With this implementation, the system will automatically register notification clicks and update their status on the platform.

const iOS = DarwinInitializationSettings(
  requestAlertPermission: false,
  requestBadgePermission: false,
  requestSoundPermission: false,
);

const android = AndroidInitializationSettings('@mipmap/ic_launcher');

const settings = InitializationSettings(
  android: android,
  iOS: iOS,
);

await flutterLocalNotificationsPlugin.initialize(
  settings,
  onDidReceiveNotificationResponse: (response) {
    if (response.notificationResponseType ==
            NotificationResponseType.selectedNotification &&
        response.payload != null) {
      InngageSDK.updateStatusMessage(response.payload);
    }
  },
  onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
);

✅ Summary

With all these handlers correctly implemented, your app will be able to use Inngage services integrated with Firebase Messaging, even if you are using custom push notification services. This setup ensures full control over the message flow and allows seamless integration of In-App Messages from the Inngage platform.