Test Push

Sending a Push Notification for Testing

With a real project, the Firebase 1 console's Messaging page has Send test message: paste the token from the registration event. A server uses the FCM HTTP v1 API (from the Firebase documentation; not run here):

Sending one message with the FCM HTTP v1 API (not run here)Shell
curl -X POST https://fcm.googleapis.com/v1/projects/PROJECT_ID/messages:send \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json" \
  -d '{"message": {"token": "DEVICE_TOKEN",
       "notification": {"title": "Back in stock", "body": "Salt and Saffron is here"},
       "data": {"bookId": "3"}}}'

$ACCESS_TOKEN is a short-lived OAuth 2.0 token for the firebase.messaging scope, minted from a service account key. BookNest reads the data fields on a tap:

Opening the book from a tapped push notification, in watchPlugins()
  PushNotifications.addListener('pushNotificationActionPerformed', ({ notification }) => {
    show('pushAction', notification); // the user tapped a push notification (Section 4.15.6)
    const { bookId } = notification.data;
    if (bookId) f7.views.current.router.navigate(`/books/${bookId}/`);
  });

A tapped FCM notification starts the activity with the data fields as extras plus google.message_id, and the plugin's handleOnNewIntent() reports any such intent as a tap, so adb can fake one without Firebase:

Simulating the tap on a push notificationShell
adb -s emulator-5558 shell am start -n com.example.booknest/.MainActivity \
  --es google.message_id 0:demo-1 --es bookId 2
Output
LAB pushAction {"id":"0:demo-1","data":{"bookId":"2"}}
routeChange  /books/5/ -> /books/2/ [book]