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

feat: push permission prompt #101

Merged
merged 38 commits into from
Mar 3, 2023
Merged

feat: push permission prompt #101

merged 38 commits into from
Mar 3, 2023

Conversation

ami-aman
Copy link
Collaborator

@ami-aman ami-aman commented Feb 24, 2023

closes: https://github.com/customerio/issues/issues/8746
closes: https://github.com/customerio/issues/issues/9493

This PR adds the ability to display a push notification permission prompt in the app. This gives the user the freedom to display a prompt at a later time in the app, which was previously only possible at app launch or by requiring the customer to utilise additional libraries.

Use case:
Show push permission prompt by calling CustomerIO.showPromptForPushNotifications from the javascript with configurable options such as badge and sound.

var options = {"ios" : {"sound" : true}}
    CustomerIO.showPromptForPushNotifications(options).then(response => {
      alert("Permission Status -> " + response)
      console.log("Permission status is - ", response)
    }).catch(error => {
      alert("Failed to show push permission prompt.")
      console.log(error)
})

This PR also includes support for obtaining push permission authorisation status with a callback to perform action based on the response received. Call CustomerIO.getPushPermissionStatus to get the status.

Use case:

const getPushPermissionStatus = () => {
	CustomerIO.getPushPermissionStatus((response) => {
        performActionOnPushStatus(response)
})
}
        
const performActionOnPushStatus = (status) => {
 	alert("Push permission status is - " + status)
	console.log("Push permission status is - " + status)
} 

@github-actions
Copy link

github-actions bot commented Feb 24, 2023

Pull request title looks good 👍!

If this pull request gets merged, it will cause a new release of the software. Example: If this project's latest release version is 1.0.0. If this pull request gets merged in, the next release of this project will be 1.1.0. This pull request is not a breaking change.

All merged pull requests will eventually get deployed. But some types of pull requests will trigger a deployment (such as features and bug fixes) while some pull requests will wait to get deployed until a later time.

This project uses a special format for pull requests titles. Expand this section to learn more (expand by clicking the ᐅ symbol on the left side of this sentence)...

This project uses a special format for pull requests titles. Don't worry, it's easy!

This pull request title should be in this format:

<type>: short description of change being made

If your pull request introduces breaking changes to the code, use this format:

<type>!: short description of breaking change

where <type> is one of the following:

  • feat: - A feature is being added or modified by this pull request. Use this if you made any changes to any of the features of the project.

  • fix: - A bug is being fixed by this pull request. Use this if you made any fixes to bugs in the project.

  • docs: - This pull request is making documentation changes, only.

  • refactor: - A change was made that doesn't fix a bug or add a feature.

  • test: - Adds missing tests or fixes broken tests.

  • style: - Changes that do not effect the code (whitespace, linting, formatting, semi-colons, etc)

  • perf: - Changes improve performance of the code.

  • build: - Changes to the build system (maven, npm, gulp, etc)

  • ci: - Changes to the CI build system (Travis, GitHub Actions, Circle, etc)

  • chore: - Other changes to project that don't modify source code or test files.

  • revert: - Reverts a previous commit that was made.

Examples:

feat: edit profile photo
refactor!: remove deprecated v1 endpoints
build: update npm dependencies
style: run formatter 

Need more examples? Want to learn more about this format? Check out the official docs.

Note: If your pull request does multiple things such as adding a feature and makes changes to the CI server and fixes some bugs then you might want to consider splitting this pull request up into multiple smaller pull requests.

@ami-aman ami-aman changed the title Aman/push notifications feat: push permission prompt Feb 24, 2023
@github-actions
Copy link

github-actions bot commented Feb 24, 2023

Hey, there @ami-aman 👋🤖. I'm a bot here to help you.

⚠️ Pull requests into the branch main typically only allows changes with the types: fix. From the pull request title, the type of change this pull request is trying to complete is: feat. ⚠️

This pull request might still be allowed to be merged. However, you might want to consider make this pull request merge into a different branch other then main.

This project uses a special format for pull requests titles. Expand this section to learn more (expand by clicking the ᐅ symbol on the left side of this sentence)...

This project uses a special format for pull requests titles. Don't worry, it's easy!

This pull request title should be in this format:

<type>: short description of change being made

If your pull request introduces breaking changes to the code, use this format:

<type>!: short description of breaking change

where <type> is one of the following:

  • feat: - A feature is being added or modified by this pull request. Use this if you made any changes to any of the features of the project.

  • fix: - A bug is being fixed by this pull request. Use this if you made any fixes to bugs in the project.

  • docs: - This pull request is making documentation changes, only.

  • refactor: - A change was made that doesn't fix a bug or add a feature.

  • test: - Adds missing tests or fixes broken tests.

  • style: - Changes that do not effect the code (whitespace, linting, formatting, semi-colons, etc)

  • perf: - Changes improve performance of the code.

  • build: - Changes to the build system (maven, npm, gulp, etc)

  • ci: - Changes to the CI build system (Travis, GitHub Actions, Circle, etc)

  • chore: - Other changes to project that don't modify source code or test files.

  • revert: - Reverts a previous commit that was made.

Examples:

feat: edit profile photo
refactor!: remove deprecated v1 endpoints
build: update npm dependencies
style: run formatter 

Need more examples? Want to learn more about this format? Check out the official docs.

Note: If your pull request does multiple things such as adding a feature and makes changes to the CI server and fixes some bugs then you might want to consider splitting this pull request up into multiple smaller pull requests.

ios/CustomerioReactnative.swift Show resolved Hide resolved
* @param options
* @returns Success & Failure promises
*/
static async showPromptForPushNotifications(options?: any) : Promise<any>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why any is used for options parameter?

What about using a typescript interface instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I used any to prevent customer from importing another interface or config class. But this can be changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can see how not needing to include another import could be nice. However, I believe that if a customer is using typescript in their project, they are OK with adding more imports for types in their code. Also, they probably prefer a strongly typed API when interacting with our SDK. With this in mind, I do believe it's preferred that we replace any with a strongly typed interface.

If we were to organize all of the interfaces in the project, I think the import statements for our SDK could look nice in a customer's app.

Here is an example of the imports could look like in a customer's app:

import type { PushPermissionOptions, Foo, Bar } from "customerio-reactnative/types" 
import { CustomerIOTracking } from "customerio-reactnative" 
...

I do not see this as a blocker for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small idea to share, I think changing the function name to something such as:

Suggested change
static async showPromptForPushNotifications(options?: any) : Promise<any>{
static async askForPushPermission(options?: any) : Promise<any>{

would match the function naming of getPushPermissionStatus.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This is a great suggestion. I will add this in a separate PR. I appreciate the suggestion.

  2. I used "prompt" to make it specific that calling this method would show a prompt on the screen and not do something in the background.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I am OK with that while I am also OK with adding the changes to this PR.
  2. I am OK with either name. I hope using the word "prompt" doesn't confuse anyone where there are some cases where a prompt will not show up when this function is called. That's one reason why I suggested the name change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I tried implementing customerio-reactnative/types and found that it has to be a completely new library inside our customerio-reactnative with it's own package.json, index.ts and other important files. Since we are waiting to release this feature on priority, I do not want to take more time learning & implementing it at the moment. But I really loved the suggestion and will make sure to add it in the future updates. I would also like to add other configs like CioConfigOptions to /types so that the importing customerio-reactive could get reclustered as we release new features in future.

  2. I still lean towards having promt in the function name as it makes things clear to me as a user. I discussed with Rehan and we both had same POV.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. My code sample might have been bad as the solution I am thinking shouldn't be that complex. Here is a start to this work that I am testing now to see if we can sneak it into this release. I think our typescript customers will appreciate the strong types.
  2. Good idea to ask others. If other people are behind it, I am for it 👍

src/CustomerioTracking.tsx Outdated Show resolved Hide resolved
src/CustomerioTracking.tsx Outdated Show resolved Hide resolved
* @param options
* @returns Success & Failure promises
*/
static async showPromptForPushNotifications(options?: any) : Promise<any>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small idea to share, I think changing the function name to something such as:

Suggested change
static async showPromptForPushNotifications(options?: any) : Promise<any>{
static async askForPushPermission(options?: any) : Promise<any>{

would match the function naming of getPushPermissionStatus.

ios/CustomerioReactnative.swift Show resolved Hide resolved
@ami-aman ami-aman marked this pull request as ready for review March 1, 2023 16:50
* Get status of push permission for the app
* @returns Promise with status of push permission as a string
*/
static getPushPermissionStatus() : Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static getPushPermissionStatus() : Promise<any> {
static getPushPermissionStatus() : Promise<PushPermissionStatus> {

Going along with the comment about a strongly typed parameter for showPromptForPushNotifications, we know the data type that is being returned from the Promise.

We should be providing customers with a data type return value that they can easily parse in their code.

Copy link
Contributor

@mrehan27 mrehan27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

@mrehan27 mrehan27 merged commit 1abe9b3 into main Mar 3, 2023
@mrehan27 mrehan27 deleted the aman/push-notifications branch March 3, 2023 12:28
github-actions bot pushed a commit that referenced this pull request Mar 3, 2023
## [2.2.0](2.1.0...2.2.0) (2023-03-03)

### Features

* push permission prompt ([#101](#101)) ([1abe9b3](1abe9b3))
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

Successfully merging this pull request may close these issues.

3 participants