Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question]: Action Buttons - actionId or actionID? #1738

Open
1 task done
DarkNightZ152 opened this issue Sep 6, 2024 · 0 comments
Open
1 task done

[question]: Action Buttons - actionId or actionID? #1738

DarkNightZ152 opened this issue Sep 6, 2024 · 0 comments

Comments

@DarkNightZ152
Copy link

DarkNightZ152 commented Sep 6, 2024

How can we help?

I don't know if anyone has the same problem as me. I send a push notification from BE (NestJS + OneSignal NodeJS API) to Mobile (React Native with Expo integration). On BE I send it like this:

createNotifications({
      heading: 'Item is activated',
      message: `Your item is activated: ${item.name}`,
      externalUserIds: [item.userId],
      data: {
        type: 'item.activated',
        item: {
          id: item.id,
          name: item.name,
        },
      },
      buttons: [
        {
          id: 'view-item',
          text: 'View Item',
        },
      ],
    });

On Mobile (React Native), I tried the following:

useEffect(() => {
    const handleNotificationClick = (event: NotificationClickEvent) => {
      console.log('event: ', JSON.stringify(event, null, 2));
      console.log(`actionId: ${event.result.actionId}`);
      console.log(
        event.result.actionId
          ? `actionId: ${event.result.actionId}`
          : 'No actionId',
      );
      }
    };

    OneSignal.Notifications.addEventListener('click', handleNotificationClick);

    return () => {
      OneSignal.Notifications.removeEventListener(
        'click',
        handleNotificationClick,
      );
    };
  }, []);

If I click on the body of the push notification, the event.result will be an empty object (no actionId), but if I click on the view-item button, it will print out as follows:

event:  {
  "result": {
    "actionID": "view-item"
  },
  "notification": {
    "mutableContent": true,
    "body": "Your item is activated: Ergonomic Frozen Car 090235 4343152",
    "sound": "default",
    "notificationId": "...",
    "actionButtons": [
      {
        "id": "view-item",
        "text": "View Item"
      }
    ],
    "title": "Item is activated",
    "collapseId": "...",
    "additionalData": {
      "type": "item.activated",
      "actionSelected": "view-item",
      "item": {
        "name": "Ergonomic Frozen Car 090235 4343152",
        "id": "..."
      }
    },
    "rawPayload": {
      ......
    }
  }
}
 LOG  actionId: undefined
 LOG  No actionId

But if I change it to: console.log(actionId: ${event.result.actionID}); it will still log the output but will give an error/warning in the IDE: no property 'actionID' in event.result:

 LOG  actionID: view-item
 LOG  actionID: view-item

Please tell me how to fix it. Sorry if my English is bad. Btw i'm using "react-native-onesignal": "^5.2.3".

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant