Get actionButton id selected in OneSignal push notification


#1

In my Ionic v3 app I would like to perform various type of actions if the user click on a defined action button on the OneSignal push notification.
I’m able to retrieve the payload when the notification it’s clicked but not to retrieve the id of the action button clicked. How can I do this?

app.component.ts

initializeApp() {...
      if (isCordovaAvailable()){
            this.oneSignal.startInit(oneSignalAppId, sender_id);
            this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
            this.oneSignal.handleNotificationReceived().subscribe(data => this.onPushReceived(data.payload));
            this.oneSignal.handleNotificationOpened().subscribe(data => this.onPushOpened(data.notification.payload));
            this.oneSignal.endInit();  
          } 
...
}

private onPushOpened(payload: OSNotificationPayload) {
    console.log(JSON.stringify(payload));  
  }

And this is my json output

  {
    "notificationID": "b2af8c73-a2c6-4335-a3da-8fb5f21269c6",
    "title": "Avviso:",
    "body": "C'è un nuovo evento in programma, dai un 'occhiata!🎉🎊",
    "additionalData ":{},
    "smallIcon ":"ic_stat_onesignal_default ",
    "smallIconAccentColor ":"FF9900FF ","
    ledColor ":"FF99000 ","
    lockScreenVisibility ":1,"
    groupMessage ":"","
    actionButtons ":[
        {"id ":"1 ","text ":"text1 ","icon ":""},
        {"id ":"2 ","text ":"text2 ","icon ":""}
        ],
    "fromProjectNumber ":"1086176974958 ",
    "priority ":5,
    "rawPayload ":" {\"google.sent_time\":1526398379468,\"google.ttl\":259200,\"custom\":\"{\\\"ti\\\":\\\"1b5ae85f-6597-4cef-8f43-60d19148a288\\\",\\\"i\\\":\\\"b2af8c73-a2c6-4335-a3da-8fb5f21269c6\\\",\\\"tn\\\":\\\"TemplApp advice\\\ ",\\\"a\\\":{\\\"actionButtons\\\":[{\\\"id\\\":\\\"1\\\",\\\"text\\\":\\\"text1\\\",\\\"icon\\\":\\\"\\\"},{\\\"id\\\":\\\"2\\\",\\\"text\\\":\\\"text2\\\",\\\"icon\\\":\\\"\\\"}],\\\"actionSelected\\\":\\\"__DEFAULT__\\\"}}\",\"oth_chnl\":\"\",\"pri\":\"5\",\"vis\":\"1\",\"bgac\":\"FF9900FF\",\"from\":\"1086176974958\",\"ledc\":\"FF99000\",\"alert\":\"C'è un nuovo evento in programma, dai un 'occhiata!🎉🎊\",\"sicon\":\"ic_stat_onesignal_default\",\"title\":\"Avviso:\",\"grp_msg\":\"\",\"google.message_id\":\"0:1526398379474892%b9b0241cf9fd7ecd\",\"actionSelected\":\"2\",\"notificationId\":-1227815476}"
    }

I would like to make that if the user click on action button 1, the navigation push to an X page of my app, if the user click on action button 2, push to another page.
I think that is needed the actionButton id for achieve this but I don’t know how to obtain it.

Thank you in advance
Erica


#2

Still have the problem :frowning:


#3

no one? still have the problem :frowning: