(English) Possible Implementations
Push Notification Handlers
Below are the required methods to properly integrate push notifications and In-App Messages using Inngage, alongside Firebase Messaging.
InngageNotificationMessage.registerSubscriber(String fcmToken)
This method must be called right after InngageNotificationMessage.subscribe(). It sends the user’s fcmToken to the Inngage API, enabling the delivery of push notifications and In-App Messages.
InngageNotificationMessage.handlerNotificationForeground(...)
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.handlerNotificationForeground(
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.
InngageNotificationMessage.handlerNotificationClick(...)
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);
}
});
InngageNotificationMessage.handlerNotificationClosed(...)
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) {
InngageNotificationMessage.handlerNotificationClosed(remoteMessage);
} else {
_handlerCustomNotificationClick(remoteMessage);
}
}).catchError((error) {
debugPrint("Error on getInitialMessage: $error");
});
InngageNotificationMessage.handlerNotificationBackground(...)
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 InngageNotificationMessage.handlerNotificationBackground(
remoteMessageData: message.data,
);
}
And register it:
FirebaseMessaging.onBackgroundMessage(_firebaseBackgroundHandler);
✅ 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.
Updated about 1 month ago