tbalthazar / onesignal-go

Go client for the OneSignal API
GNU General Public License v3.0
30 stars 39 forks source link

NotificationRequest.Tags not used? #5

Open gfl-chris opened 6 years ago

gfl-chris commented 6 years ago

I can't find a reference to NotificationRequest's Tags field (JSON: tags) in the Onesignal documentation and support tells me that tag values can't be set when creating a notification (when sending a templated notification). What was/is the intended behaviour? Has this been working for anyone else?

UpToEleven1102 commented 5 years ago

Did you manage to make it work yet?

Here is my code notificationReq := &onesignal.NotificationRequest{ AppID: appID, Contents: map[string]string{"en": "English message"}, IsAndroid: true, Tags: map[string]string{ "role": "merchant", }, }

And the error

2018/12/18 00:18:31 OneSignal returned those error messages:

  • Tags must be an array. For example, [{"key":"gender","relation":"=","value":"male"}] exit status 1
sergolius commented 5 years ago

@gfl-chris notification by template works fine for me. @UpToEleven1102 you need to format tags properly (map inside slice of interfaces), here is sample of tags formatting:

onesignal.NotificationRequest{
    TemplateID: "TemplateID",
    Tags: []interface{}{
        map[string]interface{}{
            "key": "gender", "relation": "=", "value": "male",
        },
    },
    AppID:            appID,
    IncludePlayerIDs: IncludePlayerIDs,
    //Contents:         map[string]string{"en": "hello"},
}