Skip to content

Push

Your app keeps its own push service (Firebase). PurrCRM sends pushes through your Firebase project, once your team has added its key on Settings › Channels › Push (A push campaign). Your app does three things.

Ask Firebase for the device’s token and hand it to the facade, on every start and whenever it changes:

final token = await FirebaseMessaging.instance.getToken();
if (token != null) await crm.registerPushToken(token);
FirebaseMessaging.instance.onTokenRefresh.listen(crm.registerPushToken);

The facade registers the token for each user who signs in, so a phone that changes hands gets only the new user’s pushes. Before your own sign-out, while the user’s token still works:

await crm.forgetPushToken();
await mySignOut();
// A push arrived while the app was open.
FirebaseMessaging.onMessage.listen((message) {
final result = crm.handlePushArrival(message.data);
if (result.isCrm && !result.replyOnScreen) {
showMyNotice(message); // a reply on screen is already read there
}
});
// The user tapped a push, whether the app was open or not.
FirebaseMessaging.onMessageOpenedApp.listen((message) {
if (!crm.handlePushTap(message.data)) {
myRouter.follow(message.data); // not PurrCRM's: yours to follow
}
});

Arriving, a reply refreshes the unread count and a message makes the app check in. Tapped, every push records push_opened, and a PurrCRM push opens its page once the user is ready (setReady). replyOnScreen says the reply’s conversation is open on screen.

PurrCRM‘s pushes carry type (support_reply for a reply, crm_message for a message from your team), link (the page, such as /messages/<id>) and notice_id.

3. Create the Android notification channel

Section titled “3. Create the Android notification channel”

On Android 8 and later every notification belongs to a channel the app created, which the user can turn off on its own. PurrCRM names one in every push: the Android channel on Settings › Channels › Push › Advanced, messages unless your team changes it. Create a channel with exactly that id as your app starts, or Android shows your pushes in a “Miscellaneous” channel.

With flutter_local_notifications:

const channel = AndroidNotificationChannel(
'messages', // the Android channel in your app's push settings
'Messages', // what the user sees in the app's notification settings
description: 'Replies from our team, and messages about your account.',
importance: Importance.high,
);
await FlutterLocalNotificationsPlugin()
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);

Or natively, in MainActivity.onCreate:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"messages", "Messages", NotificationManager.IMPORTANCE_HIGH)
getSystemService(NotificationManager::class.java)
.createNotificationChannel(channel)
}

Creating a channel that exists already changes nothing, so do it on every start. If your team changes the channel’s id, ship a build that creates the new one first, and keep creating the old one while builds that know only it are installed. On iOS, the iOS thread groups your notifications and needs nothing from your app.

A marketing push goes only to people who agreed to offers by push. If your app asks them, tell PurrCRM:

await crm.setOffersByPush(true);
final agreed = await crm.offersByPush();

Topics refine this further: see Preferences.

Every push PurrCRM sends is also kept as a notice in the user’s inbox:

  • crm.notices is a listenable CrmNotices: the notices read so far, newest first, and unread, the whole inbox’s count for your bell.
  • CrmNoticesBuilder(builder: (context, notices) => ...) rebuilds with it.
  • CrmInboxList(empty: Text('Nothing yet')) draws the inbox, older notices a page at a time. A tap marks a notice read and follows its link, unless you pass onOpen.
  • crm.markNoticesRead(ids) (or all: true), crm.refreshNotices() and crm.moreNotices() for a screen of your own.

Under Testing › Preview on my phone, make your phone a test phone, then send a push from any message with Try it on my test phone. If nothing arrives, the push’s report and Settings › Channels › Push › Recent failures say why.