Agent Wranglers

Push notifications Recommended

Give every push a lifetime and a topic

Set how long each push may wait for an offline device. Give updates a topic, so a newer push replaces the older one.

How to do it

Set TTL in seconds for web push (RFC 8030 makes it required), apns-expiration for APNs and ttl for FCM. Use minutes for a "driver is outside", and a day for an order update. Set Topic for web push, apns-collapse-id for APNs and collapse_key for FCM, such as order-1042. Use Urgency: high only for messages the person must see now, because it wakes the device and drains the battery.

Example

await webpush.sendNotification(subscription, JSON.stringify(update), {
  TTL: 24 * 3600, urgency: 'normal', topic: `order-${order.id}`,
});
webpush(subscription_info=subscription, data=json.dumps(update), vapid_private_key=VAPID_KEY,
        vapid_claims={"sub": "mailto:push@example.com"}, ttl=24 * 3600,
        headers={"Urgency": "normal", "Topic": f"order-{order.id}"})

How to check

Turn a test device offline, send three updates with one topic and a TTL of an hour, and turn it on. One notification shows, with the last text. A push with a TTL of 60 seconds sent to a device that stays offline for 2 minutes never shows.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers notifications playbook: https://agentwranglers.se/playbook/notifications/push-notifications/push-ttl-and-collapse.