MobiariDocs

Push notifications

What the Mobiari mobile apps receive by push. The kinds of notification, what each push carries, where a tap leads, and how operators turn APNs and FCM on.

Not part of the public API yet

Push notifications are not part of the public API yet: registering a device, notification preferences and the notification list will be documented here when they are. This page describes how push behaves in the Mobiari apps.

The merchant apps (iOS and Android, application id com.mobiari.merchant) receive the same team alerts the platform sends by e-mail and WhatsApp: new and paid orders, cancellations, low stock, and conversations that are assigned to you or to nobody. The server sends iOS pushes through APNs, Android pushes through Firebase Cloud Messaging (FCM), and browser pushes through Web Push (see Browsers).

Push is for team members signed in to the app.

Incoming calls

A customer's WhatsApp call rings every live device of every team member who may answer conversations (conversations.reply), even with the app closed. These pushes skip the notification center: no bell entry, no e-mail, and no per-kind preference. They carry data only, all strings:

Field
kindcall.incoming when it starts ringing, call.ended when it was answered elsewhere, declined, missed or hung up.
call_id, store_idThe call and its store.
contact_name, contact_phoneWho is calling (empty on call.ended).
  • iOS: a VoIP push (apns-push-type: voip, topic <bundle id>.voip) to the device's PushKit (VoIP) token. The app must report a call to CallKit for every one it receives. Devices without a VoIP token are not rung.
  • Android: a high-priority FCM data message, dropped after 60 seconds.

A ring is worthless after about a minute: a push still queued by then is dropped. To answer, the app fetches the call's offer and follows the same steps as the web admin.

Preferences

A push is one channel of the member's notifications: the same notification also lands in their bell and, if they choose, in their e-mail or WhatsApp. Each member picks, per store and per kind, where it reaches them.

Members choose in the Mobiari admin, under Notifications → Preferences. Preferences apply to every device of the user.

KindWhenWho gets itNeedsPush by default
orders.createdA new order (online or a manual sale)Every member, except whoever placed itorders.readyes
orders.paidPayment confirmed (once per order, however many times the provider confirms)Every member, except whoever took the paymentorders.readyes
orders.cancelledSomeone cancelled an orderEvery member, except whoever cancelledorders.readyes
customers.address_changedA customer changed the delivery address with orders not shippedThe customer's owner, else every memberorders.readyes
inventory.low_stockA variant reached its reorder point (or 5 units) at a location, at most once a dayEvery memberinventory.readno
inventory.out_of_stockA variant ran out at a location, at most once a dayEvery memberinventory.readyes
conversations.startedA customer started a conversation and the chat bot is offThe assignee, or every member when unassignedconversations.readyes
conversations.message_receivedA customer wrote and the chat bot is offSameconversations.readyes
conversations.handed_overThe chat bot handed the conversation to the teamSameconversations.readyes
conversations.assignedSomeone else assigned a conversation to youThe new assigneeconversations.readyes
tasks.assignedSomeone assigned you a taskThe assigneeyes
tasks.dueA task of yours is dueThe assigneeyes
customers.note_mentionSomeone mentioned you in a customer noteThe members mentionedcustomers.readyes
customers.privacy_requestA customer asked from their account for their data to be deleted or corrected (LGPD, answer within 15 days)Every membercustomers.writeyes
fiscal.document_rejectedSEFAZ rejected or denied an NF-eEvery memberorders.writeyes
purchasing.documents_receivedPurchase NF-e issued to the store arrived from SEFAZEvery memberpurchasing.readno
purchasing.invoice_cancelled_after_receiptA supplier cancelled an invoice already received: the reversal waits for a decisionEvery memberpurchasing.readyes
documents.expiringA store document is about to expireEvery memberdocuments.writeno
signatures.updatedA signature request you sent was signed by everyone or declinedThe senderdocuments.readno
workflows.run_failedAn automation failed, at most once an hour per automationEvery memberworkflows.writeno

New kinds will be added. Ignore a kind you do not know, or open its link (below).

What a push carries

Every push has a localized title and body, and deep-link data:

KeyPresent
kindAlways. One of the kinds above, or test for a test push.
store_idAlways, except test.
order_idorders.*, and customers.address_changed about one order
conversation_idconversations.*
product_id, variant_idinventory.*
customer_idcustomers.* about a customer
linkThe admin path the notification opens (/orders/<id>, /tasks, ...), when it has one

All values are strings.

iOS (APNs). The data keys sit at the top level of the payload, next to aps:

{
  "aps": {
    "alert": { "title": "Pedido #1042 pago", "subtitle": "Loja Azul", "body": "R$ 1.234,56 · Ana Souza" },
    "sound": "default",
    "badge": 3,
    "thread-id": "store-0199a0c4-..."
  },
  "kind": "orders.paid",
  "store_id": "0199a0c4-...",
  "order_id": "0199b7e2-...",
  "link": "/orders/0199b7e2-..."
}

subtitle is the store name. thread-id groups a conversation's pushes (conv-<conversation id>) and a store's other alerts (store-<store id>). Pushes use apns-push-type: alert, priority 10, and expire after an hour.

Android (FCM). A notification message with the data under data:

{
  "notification": { "title": "Order #1042 paid", "body": "R$1,234.56 · Ana Souza" },
  "data": { "kind": "orders.paid", "store_id": "0199a0c4-...", "order_id": "0199b7e2-...", "link": "/orders/0199b7e2-..." },
  "android": {
    "priority": "high",
    "ttl": "3600s",
    "collapse_key": "order-0199b7e2-...",
    "notification": { "channel_id": "orders", "tag": "order-0199b7e2-...", "notification_count": 3, "sound": "default" }
  }
}

Create four notification channels in the app so users can mute them separately: orders, conversations, inventory and general (tasks, fiscal, purchasing, documents, automations). Until a channel exists, Android shows the push in the app's default channel.

Collapsing. Pushes about the same subject share a collapse key (apns-collapse-id / collapse_key and tag): order-<order id>, so an order's "paid" replaces its "new"; conversation-<conversation id>, so a burst of messages leaves one notification with the latest text; variant-<variant id> for stock. Kinds that each say something of their own (a task, a mention) never collapse.

Badge. The badge is the member's unread notifications in the store the push is about: the same number as the bell.

Handling a tap

Read kind and store_id from the push data. If store_id is not the store currently selected in the app, switch to it first (the user may belong to several stores), then:

kindOpen
orders.created, orders.paid, orders.cancelledThe order (order_id)
conversations.*The conversation thread (conversation_id)
inventory.*The variant's stock (variant_id), or the product (product_id)
testNothing in particular (the home screen)
anything elseThe screen for link if the app has one, else the home screen

If the user lost access to the store or the record is gone, show the store's home instead.

Browsers

The admin (app.mobiari.com) gets the same pushes in the browser, also with every Mobiari tab closed (the browser itself has to be running). Turning on desktop notifications in Conversations (the bell in the inbox toolbar) subscribes the browser and registers it as a web device of the session; turning them off, or signing out, removes it. Which alerts arrive follows the same notification preferences as the apps (the "Phone and browser" column).

The service worker (/sw.js) shows a push only when no Mobiari tab is in front: an open tab shows its own toast and plays its own sound, and a notification about a conversation is silent while a tab is open in the background. Clicking one opens its page, switching to its store. Browsers that cannot reach their push service (Chromium builds without Google's services, such as Helium or ungoogled-chromium) fall back to notifications from an open tab.

For operators

Push is off until credentials are configured. With none, the backend logs push notifications disabled once at startup and everything else works as before. Each provider is enabled on its own: configure only APNs and Android devices simply get nothing (and vice versa). A key that does not parse disables that provider with an error in the startup log; the backend still starts.

Variable
APNS_KEY_P8Contents of the APNs auth key (AuthKey_XXXXXXXXXX.p8, PKCS#8 PEM). In an env file, put it on one line with \n for the newlines.
APNS_KEY_PATHAlternative to APNS_KEY_P8: path to the .p8 file inside the container.
APNS_KEY_IDThe key's 10-character id.
APNS_TEAM_IDThe Apple Developer team id.
APNS_TOPICThe app's bundle id. Default com.mobiari.merchant.
FCM_SERVICE_ACCOUNT_JSONA Firebase service-account key JSON (Project settings, Service accounts, "Generate new private key"), minified to one line.
FCM_SERVICE_ACCOUNT_PATHAlternative: path to the JSON file inside the container.
FCM_PROJECT_IDThe Firebase project id. Defaults to the service account's project_id.
WEB_PUSH_VAPID_KEYWeb Push: the VAPID P-256 private key, PKCS#8 PEM (openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256). In an env file, one line with \n for the newlines.
WEB_PUSH_VAPID_KEY_PATHAlternative: path to the PEM file inside the container.
WEB_PUSH_SUBJECTThe contact push services see in the VAPID token, mailto: or https:. Default https://mobiari.com.

APNs uses token-based auth: the backend signs an ES256 JWT with the key and talks HTTP/2 to api.push.apple.com (or api.sandbox.push.apple.com for debug builds run from Xcode). One key works for both gateways and every app of the team. FCM uses the HTTP v1 API; the backend exchanges a JWT signed with the service account for an OAuth2 access token and reuses it until it expires.

Web Push signs an ES256 VAPID token with that key and encrypts each payload to the browser's key (RFC 8291, aes128gcm); browsers subscribe with the public half, served at GET /me/devices/web-push-config. Changing the key invalidates every browser subscription: browsers subscribe again on their next visit. Only the push services of Chrome, Firefox, Safari and Edge are accepted as endpoints.

Deliveries go through the job queue (jobs table, kind push.deliver): one job per device, retried with exponential backoff on provider 5xx, 429 and network errors, and dead-lettered after 5 attempts or on errors a retry cannot fix (bad credentials, rejected payload). A dead-lettered push job with InvalidProviderToken or THIRD_PARTY_AUTH_ERROR means the credentials are wrong.

On this page