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

Is it possible to add action buttons to notifications? #262

Closed
mostafiz93 opened this issue May 25, 2017 · 11 comments
Closed

Is it possible to add action buttons to notifications? #262

mostafiz93 opened this issue May 25, 2017 · 11 comments

Comments

@mostafiz93
Copy link

mostafiz93 commented May 25, 2017

Is it possible to add action buttons (say, Accept and Deny) to the notification that will perform specific operations when pressed. I'm talking about this Action Buttons. Are those possible in React Native?

I'm attaching some sample what I'm actually looking for.

@bbrcan
Copy link

bbrcan commented Jul 1, 2017

Yep, definitely need this functionality! Any advice would be greatly appreciated

@jkasten2
Copy link
Member

jkasten2 commented Jul 6, 2017

@mostafiz93 @bbrcan Yes, these are supported by this SDK. For Android you must swipe down with 2 fingers to see the buttons. For iOS 10 you must 3d touch on the notification to see them.

Then normal notification opened event will fired when a button is pressed. The id of the button will be sent to the event as well.

@bbrcan
Copy link

bbrcan commented Jul 7, 2017

What about when posting a notification though?

I noticed postNotification() only supports contents, data, and player_ids, whereas there's a lot more options supported by the OneSignal API, buttons being one of them.

I know this isn't an official SDK and you guys are kind enough to maintain & share this so a big thank you for that! :)

@jkasten2
Copy link
Member

jkasten2 commented Jul 7, 2017

@bbrcan Correct, the postNotification() function included with this SDK is limited to those 3 parameters so adding action buttons isn't possible with it. However you can use the OneSignal Create notification REST API endpoint directly to send the notification from either your app's code or through your own server. However if you do so through your app make sure to omit the Authorization header as this isn't secure in your app. include_player_ids does not require this key.

@leoskyrocker
Copy link

@jkasten2 are you aware of anyone working on adding options to this? It seems like a missing piece to reach full-parity.

@leoskyrocker
Copy link

seems like an overlook. someone added this feature here: #266.
Currently I cannot get it working yet though but it looks like what I was expecting.

@leoskyrocker
Copy link

Confirmed that this is working for me! (My use case was to set small_icon & large_icon)
The way I passed the params is as follow:
OneSignal.postNotification(contents, {}, onesignalPlayerId, {small_icon: 'ic_stat_name', large_icon: 'ic_launcher'})

I'll try to see if I have time to update the docs in the next few days. yay!

@jumaediahsan
Copy link

so how to make button on pushnotification ,, any tutorials ?

@leoskyrocker
Copy link

leoskyrocker commented Jan 26, 2018

By no means a complete example nor tested.. but something along the line:

Define Handler on action taken:

onOpened (openResult) {
  if (openResult.action.actionID === 'userSaidYes') {
    // do your logic
  }
}

Setup to listen to open event (which is also triggered when action taken) wherever you start your app:

OneSignal.addEventListener('opened', this.onOpened)

Then if you're sending a P2P notification with postNotification, you would do:

OneSignal.postNotification(contents, {}, onesignalPlayerId, {buttons: [{"id": "userSaidYes", "text": "Yes", "icon": "ic_xxxx_android_only"}, {"id": "userSaidNo", "text": "No", "icon": "ic_xxxx_android_only"}]})

@neo125874
Copy link

@leoskyrocker hello, did the action button support icon next to the button in ios/android?

@wahyu-handayani
Copy link

wahyu-handayani commented Apr 26, 2024

@mostafiz93 @bbrcan Yes, these are supported by this SDK. For Android you must swipe down with 2 fingers to see the buttons. For iOS 10 you must 3d touch on the notification to see them.

Then normal notification opened event will fired when a button is pressed. The id of the button will be sent to the event as well.

Hi I am currently using onesignal and flutter to build notification, as for android the action button shows up like what you said (by swiping down the notification). but in ios simulator, I cant do that, even with swipe left or right or double click. can you give a detail info about what 3d touch mean, I think I need to try it

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

8 participants