mugib_sdk_push 1.2.0
mugib_sdk_push: ^1.2.0 copied to clipboard
Turnkey FCM push add-on for mugib_sdk — one call wires Firebase Cloud Messaging to a Mugib client for proactive notifications.
mugib_sdk_push #
Turnkey Firebase Cloud Messaging
push for mugib_sdk. One call wires
proactive notifications to a Mugib client — so Mujib can reach your users
(follow-ups, surveys, campaigns) even when the app is backgrounded or closed.
Firebase is managed centrally by Mujib. Your app bundles no
google-services.json / GoogleService-Info.plist, and the Firebase service
account never reaches the device — only the non-secret client config is fetched
at runtime from Mujib.
Zero config for the developer: you don't paste a Firebase App ID
anywhere. enablePush() reads your app's own bundle/package id and Mujib
resolves (or auto-registers) the matching App ID in its central Firebase project
for you.
Install #
dependencies:
mugib_sdk: ^1.0.39
mugib_sdk_push: ^1.2.0
Usage #
import 'package:mugib_sdk/mugib_sdk.dart';
import 'package:mugib_sdk_push/mugib_sdk_push.dart';
final mugib = MugibClient(apiKey: 'YOUR_KEY');
final push = await mugib.enablePush(
onForegroundMessage: (m) => showBanner(m.title, m.text),
onMessageOpenedApp: (m) => openConversation(),
);
// push.token — the FCM token (already reported to Mujib)
// push.usingMujibProject / push.warning — see "Already using Firebase?" below
// await push.dispose(); — stop listeners
Already using Firebase in your app? #
FCM binds to your app's default Firebase project, and only one project can
receive push. enablePush() never breaks your Firebase — if a default app
already exists, it's reused. But then tokens belong to your project, so check:
if (!push.usingMujibProject) {
debugPrint(push.warning!); // switch to per-app mode
}
In that case, use per-app mode: paste your Firebase project's service account on the Mujib SDK channel. Mujib then sends through your project — no conflict, no central config needed.
That's it. enablePush():
- reads your app's bundle/package id and fetches Mujib's central Firebase config with the App ID resolved automatically for this app,
- initializes a dedicated Firebase app,
- requests notification permission,
- reports the FCM token to Mujib and keeps it fresh,
- surfaces incoming messages.
Background / terminated notifications are shown automatically by the OS from the notification payload — no extra code.
Proactive conversations (server-initiated chat) #
Mujib can start a conversation with a user — not just send a notification.
When a marketing outreach campaign (or staff) reaches an app installation, the
push carries the conversation's session_id. Open that same thread on tap so
the user can read Mujib's opener and reply — the reply flows straight back into
the campaign's AI:
final push = await mugib.enablePush(
onMessageOpenedApp: (m) async {
final convo = mugib.openProactiveConversation(m); // null for plain pushes
if (convo != null) {
final history = await convo.getHistory(); // includes Mujib's opening message
// render `history.messages`, then:
final reply = await convo.send(userText); // continues the same thread
}
},
);
MugibPushMessage.isConversation / .sessionId let you branch between a plain
notification and a proactive conversation.
Platform setup #
- Android: no Firebase files needed. Ensure your
minSdkVersionmeetsfirebase_messagingrequirements. - iOS: add the Push Notifications capability. Apple requires an APNs Auth Key tied to your app's bundle id, uploaded once to Mujib's Firebase project (done by the Mujib admin).
Chat/voice only? #
If you don't need push, just use mugib_sdk — it stays lightweight with no
Firebase dependency.