Skip to main content

Test a Push Notification

Setup

To start, you need to make sure that you have the Handshake app downloaded on your phone, can run it against the environment you’re testing in, and have push notification tokens saved for your user in the db.

Testing on mobile apps

The following mobile resources will walk you through how to download both the iOS and Android apps and point them to different environments:

Push Notification Tokens

A registered push notification token must exist for a user to be sent a push notification. This token is provided by Firebase Cloud Messaging (FCM), sent by the mobile apps to our backend, and stored in two locations: a Handshake postgres table & a Notifications Data Service (NDS) spanner table (both are named push_notification_tokens).

A push notification token is created for a user when they sign in to our Handshake mobile app. If that isn't happening automatically, you can force it by doing the following:

  1. Delete all push notification tokens for your user from the Handshake postgres table
  2. Uninstall the app on your device
  3. Reinstall the app on your device
  4. Sign in on your device
  5. Enable push notifications on your device

Development (RDE)

Setup

Environment Variables

Fetch the FCM_PRIVATE_KEY environment variable from staging and add it to .env.development.local in Handshake.

seira staging handshake secrets get FCM_PRIVATE_KEY

OR Check "Staging FCM Key" in HS General Engineers vault in 1Password

Note: Wrap the returned JSON in single quotes when adding it to .env.development.local, It should look something like this FCM_PRIVATE_KEY='{...}'

Services

  • Start Handshake
  • Start Elasticsearch: foreman start -f Procfile.all_indexing
  • Run Notifications Service: foreman start -f Procfile.notifications

Login

This is important for creating a push notification token for your device

  • Log in to the mobile app as Student User (User #125)
    • School: Amaranta University
    • Email: student@amaranta.edu
    • Look for the verification code in server logs: Next::Access::TemporaryPasscode::Credential Create
    • Once logged in remember to turn on notifications

Testing

Note: Requires a valid job alert id

curl -s \
-H "Authorization: Bearer apitoken" \
-H "Content-Type: application/json" \
-X POST \
-d '{"notification_name":"digest_job_alert", "notification_version":"2", "user_id":125, "user_email_address":"mailgun-dev@gmail.com", "attributes": {"monolith_activity_id":12345, "activity_action":"digest", "activity_user_id":125, "job_alert_id":<Grab the id of the push enabled job alert>, "activity_details":"123,456"}}' \
http://localhost:5550/v1/notifications | jq

Staging

Testing

Job Alert Digest (Saved Search)

Note: Requires a valid job alert id and staging user

job_ids = Posting.where(status: 'approved', school_id: user.institution.id).last(2).map(&:job_id)
activity = Activity.create!(
user: user,
primary_object: job_alert,
action: 'digest',
details: job_ids.join(','),
count: 1
)
Notifications::NotificationSendingWorker.perform_async(
'digest_job_alert',
'2',
{
'monolith_activity_id' => activity.id,
'activity_action' => activity.action,
'activity_user_id' => activity.user_id,
'job_alert_id' => activity.primary_object_id,
'activity_details' => activity.details,
},
activity.user_id,
activity.user.primary_email,
Digest::UUID.uuid_v5(activity.id.to_s, 'digest_job_alert_notification')
)