Перейти к содержимому

Push notifications

A Web Push registration gets each notification as an RFC 8291 encrypted record. Your client generates a P-256 key pair and an auth secret, registers the public key and decrypts each record with the private key. These routes need a user session token.

A registration is Web Push when token is an endpoint URL sent with both keys, and raw when token is a vendor device token sent with no keys.

FormtokenKeys
Web PushA publicly routable endpoint URLencryption_key and auth_secret
RawA vendor device tokenNeither

platform is one of these values.

PlatformTransport
android_fcmFirebase Cloud Messaging
ios_apnsApple Push Notification service
ios_apns_voipApple PushKit, for incoming calls on iOS
android_unified_pushUnifiedPush

android_unified_push and ios_apns_voip only accept Web Push. An iOS device that receives calls registers both ios_apns and ios_apns_voip, each with its own key pair.

FieldTypeDescription
device_idstringThe registration ID, 32 lowercase hexadecimal characters

Registering again with the same platform, app_id, provider_environment and token replaces the registration but keeps its device_id unchanged.

POST /v1/users/@me/mobile-devices

Stores a push registration and returns its device registration object. Web Push endpoints must be https URLs on public hosts.

FieldTypeDescription
platformstringThe platform of the device
tokenstringThe endpoint URL, or the vendor token on a raw registration (1-4096 characters)
encryption_key?stringThe base64url P-256 public key, Web Push only (1-1024 characters)
auth_secret?stringThe base64url auth secret, Web Push only (1-1024 characters)
app_id?stringThe client build, such as stable, beta or canary (default stable)
provider_environment?stringproduction or development, used by APNs only
user_agent?stringA user agent string describing the device (1-1024 characters)

When provider_environment is omitted, it defaults to production on ios_apns and ios_apns_voip and stays empty on other platforms. To get thread and forum new post notifications on this device, send the request with the channel_threads client capability.

StatusBodyCondition
200device registration objectThe registration was stored
400error responseINVALID_FORM_BODY when the body matches neither form
400error responseURL_NOT_PUBLICLY_ROUTABLE on token when the endpoint is a private or reserved address

The rate limit is 20 requests per minute, on the user:push:subscribe bucket.

POST /v1/users/@me/mobile-devices/unregister

Removes the registration that matches platform, token, app_id and provider_environment, and returns 200 even when none matches.

FieldTypeDescription
platformstringThe platform sent at registration
tokenstringThe token sent at registration (1-4096 characters)
app_id?stringThe client build sent at registration (default stable)
provider_environment?stringThe environment sent at registration
FieldTypeDescription
successbooleanAlways true
StatusBodyCondition
200response bodyThe registration was removed, or there was none

The rate limit is 40 requests per minute, on the user:push:unsubscribe bucket.

FieldTypeDescription
device_idstringThe registration ID
platformstringThe platform
app_id?stringThe client build sent at registration
provider_environment?stringThe APNs environment, null on other platforms
user_agent?stringThe user agent sent at registration
GET /v1/users/@me/mobile-devices

Returns every mobile registration on the account. Browser subscriptions are left out.

FieldTypeDescription
devicesarray[mobile device object]The registrations
StatusBodyCondition
200response bodyAlways

The rate limit is 40 requests per 10 seconds, on the user:push:list bucket.

DELETE /v1/users/@me/mobile-devices/{device_id}

Removes the registration with this device_id, and returns 200 even when none matches.

FieldTypeDescription
successbooleanAlways true
StatusBodyCondition
200response bodyThe registration was removed, or there was none

The rate limit is 40 requests per minute, on the user:push:unsubscribe bucket.

A browser registers the PushSubscription it gets from the Push API. The subscription ID comes from the endpoint, so subscribing again with the same endpoint replaces the subscription. An account keeps at most 100 push registrations across browsers and devices. Past that, a new one removes earlier registrations, starting with the ones from the same session.

FieldTypeDescription
subscription_idstringThe subscription ID
user_agent?stringThe user agent sent when subscribing
FieldTypeDescription
p256dhstringThe base64url P-256 public key (1-256 characters)
authstringThe base64url auth secret (1-256 characters)
POST /v1/users/@me/push/subscribe

Stores a browser subscription and returns its ID. To get thread and forum new post notifications, send the request with the channel_threads client capability.

FieldTypeDescription
endpointstringThe subscription endpoint URL, an https URL on a public host
keyspush subscription keys objectThe subscription keys
user_agent?stringA user agent string describing the browser (1-1024 characters)
installed_app?booleanWhether the client runs as an installed web app
FieldTypeDescription
subscription_idstringThe subscription ID
StatusBodyCondition
200response bodyThe subscription was stored
400error responseURL_NOT_PUBLICLY_ROUTABLE on endpoint when the endpoint is a private or reserved address

The rate limit is 20 requests per minute, on the user:push:subscribe bucket.

POST /v1/users/@me/push/rotate

Replaces the subscription for old_endpoint with one for endpoint. Call it from the service worker’s pushsubscriptionchange event.

FieldTypeDescription
old_endpointstringThe endpoint the browser replaced
endpointstringThe new endpoint URL, an https URL on a public host
keyspush subscription keys objectThe keys of the new subscription
user_agent?stringA user agent string describing the browser (1-1024 characters)
installed_app?booleanWhether the client runs as an installed web app

The response and rate limit are the same as Subscribe to push notifications.

GET /v1/users/@me/push/subscriptions

Returns the account’s browser subscriptions. Mobile registrations are left out.

FieldTypeDescription
subscriptionsarray[push subscription object]The subscriptions
StatusBodyCondition
200response bodyAlways

The rate limit is 40 requests per 10 seconds, on the user:push:list bucket.

DELETE /v1/users/@me/push/subscriptions/{subscription_id}

Removes the subscription, and returns 200 even when none matches.

FieldTypeDescription
successbooleanAlways true
StatusBodyCondition
200response bodyThe subscription was removed, or there was none

The rate limit is 40 requests per minute, on the user:push:unsubscribe bucket.

Squad posts one aes128gcm record to a Web Push endpoint for each notification. A raw registration gets an unencrypted APNs or FCM message instead. A record has at most 2713 bytes of JSON. When a notification is too large, Squad leaves out media and icons and shortens the body text, and your client has to handle those fields being missing.

Squad sets these Web Push headers on each record.

HeaderValue
TTL86400 on a notification and a clear, and 0 on a call ring
Urgencyhigh on a notification and a call ring, and low on a clear

Each payload is one of these kinds.

KindHow to recognise itWhat to do
NotificationAny other payloadShow it, using title, body, icon and image_url, and open data.url when tapped
ClearTop-level type is notification_clear and action is clear_channelDismiss what you showed for data.channel_id
Call ringTop-level type is call_ringRing, using the call ring fields under data

When an endpoint returns 404 or 410, Squad removes the registration. It retries a 429 or 5xx response and keeps the registration.

Only ios_apns_voip registrations and Web Push android_fcm registrations get call rings, and an ios_apns_voip registration gets nothing else. A call ring payload has these fields under data.

FieldTypeDescription
typestringAlways call_ring
channel_idstringThe private channel the call is in
message_idstringThe call message, which identifies the call
target_user_idstringThe account being rung
started_at_msintegerWhen the ring started, in milliseconds since the Unix epoch
expires_at_msintegerWhen the ring ends, in milliseconds since the Unix epoch
caller_id?stringThe account placing the call
caller_name?stringThe name to show for the caller
caller_avatar_url?stringAn image URL for the caller

caller_id and caller_name are sent together or not at all, and caller_avatar_url can be missing even when they are present. Ring until expires_at_ms even when they are missing. Squad sends no push when a call ends, and your client learns that from the Gateway connection.

iOS ends an app that gets a PushKit push without reporting a call to CallKit. Report a call for every PushKit push before you decrypt it, then end it right away in any of these cases.

CaseCause
The record does not decryptThe registered keys no longer match your key pair
type is not call_ringThe push is not a call ring
The Gateway reports no live call for channel_idThe call ended before the ring arrived

Use message_id to build the CallKit call UUID, so every push for the same call maps to one CallKit call.

Discard the record and show nothing. Squad can’t tell that decryption failed, and your client has to unregister and register again with its current keys.