· Frontend developer

Send push notifications via Cloud Functions - can't redirect to specific page

Custom Code

I am trying to send a notification via a Cloud Function (using the built-in Firebase Messenger notifications). This is how to send the notification:

    // Prepare and send a notification to each token
    const responses = await Promise.all(tokens.map(token => {
      const message = {
        notification: {
          title: title,
          body: body,
        },
        apns: {
          payload: {
            aps: {
              sound: "default",
            },
          },
        },
        token: token,
      };
      return admin.messaging().send(message);
    }));

The code above will send a notification to all the given tokens. 

However, the issue occurs when you want to lead the user to a specific page. Notifications aren't so useful when they don't lead to the right page so this is quite important.

What have you tried so far?

I tried various ways of doing this. Let's say I want to navigate to the page "profile" that has no parameters.

  1. I tried adding the "data" parameter and the "route" field inside it:

    // Prepare and send a notification to each token
    const responses = await Promise.all(tokens.map(token => {
      const message = {
        notification: {
          title: title,
          body: body,
        },
        data: {
          route: "profile"
         },
        apns: {
          payload: {
            aps: {
              sound: "default",
            },
          },
        },
        token: token,
      };
  1. I tried the same thing but I put the deep link inside the "route" instead of the "profile", didn't work

  2. I tried adding a new way using initialPageName with params:

    // Prepare and send a notification to each token
    const responses = await Promise.all(tokens.map(token => {
      const message = {
        notification: {
          title: title,
          body: body,
        },
        data: {
          initialPageName: "profile",
          parameterData: JSON.stringify({})
         },
        apns: {
          payload: {
            aps: {
              sound: "default",
            },
          },
        },
        token: token,
      };
  1. I also tried multiple variations with "/" before the "profile", etc. - nothing helped

  2. I also tried catching the variables on the home page and then routing based on what variable I got.

Did you check FlutterFlow's Documentation for this topic?
Yes
8