Agent Wranglers

NTF-12Recommended

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. Merge duplicate events before sending, as Send one message per event says.

Examples

JavaScript example

await webpush.sendNotification(subscription, JSON.stringify(update), {
  TTL: 24 * 3600, urgency: 'normal', topic: `order-${order.id}`,
});

Python example

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.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/notifications/push-notifications/push-ttl-and-collapse">Agent Wranglers notifications playbook</a>. In code you write, add a comment next to it with the same link.