aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.41k stars 2.12k forks source link

Q: How to manage enabledness of Push Notifications? #11110

Closed tyndria closed 1 year ago

tyndria commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication, Analytics, GraphQL API, Push Notifications

Amplify Categories

auth, api, notifications

Environment information

``` System: OS: macOS 12.6.2 CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz Memory: 363.06 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 17.6.0 - ~/.nvm/versions/node/v17.6.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v17.6.0/bin/yarn npm: 8.5.1 - ~/.nvm/versions/node/v17.6.0/bin/npm Watchman: 2023.02.13.00 - /usr/local/bin/watchman Browsers: Chrome: 111.0.5563.64 Safari: 15.6.1 Safari Technology Preview: 14.2 npmPackages: @apollo/client: ^3.7.7 => 3.7.7 @apollo/client/cache: undefined () @apollo/client/core: undefined () @apollo/client/errors: undefined () @apollo/client/link/batch: undefined () @apollo/client/link/batch-http: undefined () @apollo/client/link/context: undefined () @apollo/client/link/core: undefined () @apollo/client/link/error: undefined () @apollo/client/link/http: undefined () @apollo/client/link/persisted-queries: undefined () @apollo/client/link/retry: undefined () @apollo/client/link/schema: undefined () @apollo/client/link/subscriptions: undefined () @apollo/client/link/utils: undefined () @apollo/client/link/ws: undefined () @apollo/client/react: undefined () @apollo/client/react/components: undefined () @apollo/client/react/context: undefined () @apollo/client/react/hoc: undefined () @apollo/client/react/hooks: undefined () @apollo/client/react/parser: undefined () @apollo/client/react/ssr: undefined () @apollo/client/testing: undefined () @apollo/client/testing/core: undefined () @apollo/client/utilities: undefined () @apollo/client/utilities/globals: undefined () @aws-amplify/pushnotification: ^5.0.20 => 5.0.20 @aws-amplify/ui-react-native: ^1.2.10 => 1.2.10 @aws-sdk/client-lex-models-v2: ^3.262.0 => 3.279.0 @aws-sdk/client-lex-runtime-v2: ^3.262.0 => 3.279.0 (3.186.0) @babel/core: ^7.12.9 => 7.21.0 @babel/runtime: ^7.12.5 => 7.21.0 @notifee/react-native: ^7.4.0 => 7.5.0 @react-native-async-storage/async-storage: ^1.17.12 => 1.17.12 @react-native-community/eslint-config: ^2.0.0 => 2.0.0 @react-native-community/netinfo: ^9.3.7 => 9.3.7 @react-native-community/push-notification-ios: ^1.10.1 => 1.10.1 (1.0.3) @react-native-firebase/app: ^17.3.2 => 17.3.2 @react-native-masked-view/masked-view: ^0.2.8 => 0.2.8 @react-native-picker/picker: ^2.4.8 => 2.4.8 @react-navigation/bottom-tabs: ^6.5.5 => 6.5.7 @react-navigation/native: ^6.0.14 => 6.1.6 @react-navigation/native-stack: ^6.9.2 => 6.9.12 @react-navigation/stack: ^6.3.13 => 6.3.16 @reduxjs/toolkit: ^1.9.3 => 1.9.3 @reduxjs/toolkit-query: 1.0.0 @reduxjs/toolkit-query-react: 1.0.0 @rneui/base: ^4.0.0-rc.7 => 4.0.0-rc.7 @rneui/themed: ^4.0.0-rc.7 => 4.0.0-rc.7 @tsconfig/react-native: ^2.0.2 => 2.0.3 @types/jest: ^26.0.23 => 26.0.24 @types/lodash: ^4.14.191 => 4.14.191 @types/react: ^18.0.21 => 18.0.28 @types/react-native: ^0.70.6 => 0.70.11 @types/react-native-vector-icons: ^6.4.13 => 6.4.13 @types/react-test-renderer: ^18.0.0 => 18.0.0 @types/uuid: ^9.0.0 => 9.0.1 @typescript-eslint/eslint-plugin: ^5.37.0 => 5.53.0 (3.10.1) @typescript-eslint/parser: ^5.37.0 => 5.53.0 (3.10.1) HelloWorld: 0.0.1 amazon-cognito-identity-js: ^6.1.2 => 6.1.2 apollo3-cache-persist: ^0.14.1 => 0.14.1 aws-amplify: ^5.0.20 => 5.0.20 babel-jest: ^26.6.3 => 26.6.3 babel-plugin-module-resolver: ^5.0.0 => 5.0.0 date-fns: ^2.29.3 => 2.29.3 eslint: ^7.32.0 => 7.32.0 eslint-config-prettier: ^8.6.0 => 8.6.0 (6.15.0) eslint-plugin-import: ^2.27.5 => 2.27.5 eslint-plugin-prettier: ^4.2.1 => 4.2.1 (3.1.2) eslint-plugin-react-hooks: ^4.6.0 => 4.6.0 example: 0.0.1 graphql: ^16.6.0 => 16.6.0 (15.8.0) hermes-inspector-msggen: 1.0.0 husky: ^8.0.0 => 8.0.3 jest: ^26.6.3 => 26.6.3 lint-staged: ^13.1.0 => 13.1.2 lodash: ^4.17.21 => 4.17.21 metro-react-native-babel-preset: 0.72.3 => 0.72.3 prettier: ^2.8.3 => 2.8.4 react: ^18.2.0 => 18.2.0 react-intl: ^6.2.8 => 6.2.10 react-native: 0.70.6 => 0.70.6 react-native-autoheight-webview: ^1.6.5 => 1.6.5 react-native-config: ^1.5.0 => 1.5.0 react-native-device-info: ^10.4.0 => 10.4.0 react-native-gesture-handler: ^2.9.0 => 2.9.0 react-native-get-random-values: ^1.8.0 => 1.8.0 react-native-gifted-chat: ^1.1.1 => 1.1.1 react-native-linear-gradient: ^2.6.2 => 2.6.2 react-native-safe-area-context: ^4.5.0 => 4.5.0 react-native-screens: ^3.18.2 => 3.20.0 react-native-secure-key-store: ^2.0.10 => 2.0.10 react-native-svg: ^13.8.0 => 13.8.0 react-native-svg-transformer: ^1.0.0 => 1.0.0 react-native-url-polyfill: ^1.3.0 => 1.3.0 react-native-vector-icons: ^9.2.0 => 9.2.0 react-native-webview: ^11.26.1 => 11.26.1 react-redux: ^8.0.5 => 8.0.5 react-test-renderer: 18.1.0 => 18.1.0 reactotron-react-native: ^5.0.3 => 5.0.3 typescript: ^4.8.3 => 4.9.5 uuid: ^9.0.0 => 9.0.0 (3.4.0, 8.3.2, 7.0.3) npmGlobalPackages: @aws-amplify/cli: 10.6.2 corepack: 0.10.0 npm: 8.5.1 typescript: 4.6.4 yarn: 1.22.19 ```

Describe the bug

Sorry, "question type" leads to dead page, so I've decided to ask question here

Is there a way to manage enabledness of Push notifications? We want to give user a possibility to stop receiving notifications.

Currently I'm using push notifications module which is working on ios & android (tested using aws pinpoint). I thought that the good option could be to use endpoint optOut field, but I don't think there is a way to check the value of this field using amplify package (only REST).

So is there a way to allow user to disable & enable push notifications any time if there are integrated thought AWS Pinpoint?

Expected behavior

-

Reproduction steps

-

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

tannerabread commented 1 year ago

Hi @tyndria we have feature-request #3280 open that I believe is asking for the same thing you are asking for in the Push Notification updateEndpoint method.

However, our PN category relies on Analytics to work and the updateEndpoint method in Push Notification calls the underlying updateEndpoint method in the Analytics category. They also share an endpoint when PN is enabled.

To do what you are trying to do, you should be able to call Analytics.updateEndpoint({ optOut: 'ALL' }) to disable PN/other messages for a user

Edit: The above was assuming you are using endpoints to send messages/campaigns to your users rather than the device token. It should have worked in theory, however, after testing this out myself it doesn't seem to be working as expected. Let me discuss this internally and see if we need to fix something and I will respond again to this issue

tyndria commented 1 year ago

@tannerabread Thanks for the answer! I was also asking is there a way to to get the value of optOut field without an update. So if the idea is to use optOut field to manage PN, I should be able to check what is the actual value of this field at any moment of the time. For now I only know about update function, but I didn't find any get method in sdk (except REST endpoint)

tannerabread commented 1 year ago

Hi @tyndria sorry for the delay, I was trying to verify but it looks like we currently do not have a way to get that value in the library. And we have marked this as a bug because the solution I gave you to enable/disable the notifications does not seem to be working as it should.

We will try to post here with any updates on the issue

tyndria commented 1 year ago

@tannerabread thank you, I will wait for the fix 👍

tannerabread commented 1 year ago

Hi @tyndria we have recently released a rewritten Push Notification category with new features, can you try it out and let me know if it works for you?

You can follow the migration steps here or if you are starting again from scratch follow the getting-started guide here

For your previous question, you would change the options by the identifyUser method and more specifically as follows:

import type { AWSPinpointUserInfo } from '@aws-amplify/notifications'

const userProfile: AWSPinpointUserInfo = {
  optOut: 'ALL'
}

Notifications.Push.identifyUser('userid', userProfile)
tannerabread commented 1 year ago

Hi 👋 Closing this as resolved. This should be handled with the recent release of the rewritten Push Notification category mentioned above.

If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with additional information so we can re-open this issue and be better able to assist you.

Thank you!

tyndria commented 1 year ago

@tannerabread thank you, I hope I will be able to check soon!