OneSignal / onesignal-go-api

The official OneSignal API client for Go
MIT License
13 stars 7 forks source link

[question]: Send notification with tag filter #27

Open icobani opened 1 year ago

icobani commented 1 year ago

How can we help?

Hi all, i m new user for this package and i cannot found send notification with tag filter. I share my send message service function is bellow. If can be help me, I would be very pleased.


func (s *OneSignalService) SendMessage(userIDs []uint64, Heading string, Content string, priority int32, notificationData map[string]interface{}) {

    ids := make([]string, len(userIDs))
    for i, v := range userIDs {
        ids[i] = fmt.Sprintf("%d", v)
    }

    notification := *onesignal.NewNotification(s.AppID)
    notification.SetIncludeExternalUserIds(ids)

    var heading = onesignal.StringMap{}
    heading.SetEn(Heading)
    notification.Headings.Set(&heading)
    notification.SetIosSound("RingBellTriple.wav")
    notification.SetAndroidSound("RingBellTriple.wav")
    notification.SetIsAndroid(true)
    notification.SetIsIos(true)
    notification.SetIsChromeWeb(true)
    notification.SetIsChrome(true)
    notification.SetIsSafari(true)
    notification.SetIsFirefox(true)
    notification.SetIsAnyWeb(true)
    notification.SetIsAdm(true)
    notification.SetIsHuawei(true)
    if notificationData != nil {
        notification.SetData(notificationData)
    }
    var content = onesignal.StringMap{}
    content.SetEn(Content)
    notification.Contents.Set(&content)
    notification.SetPriority(priority)

    notification.SetTag("") // I think i will use this methot but i m not understand clearly, how can i set this properties

    if resp, _, err := s.ApiClient.DefaultApi.CreateNotification(s.AppAuth).Notification(notification).Execute(); err != nil {
        fmt.Println("Error", err)
    } else {
        if resp.GetErrors().ArrayOfString != nil {
            fmt.Println("Error", resp.GetErrors().ArrayOfString)
        } else {
            fmt.Printf("   - Response: %+v\n", "Success")
        }
    }
}

thanks a lot.

ici.

Code of Conduct

Vitor-Bukovitz commented 1 year ago

@icobani My workaround:

    notification.AdditionalProperties = map[string]interface{}{
        "filters": []map[string]interface{}{
            {
                "field":    "tag",
                "key":      "key_of_your_tag",
                "relation": "=",
                "value":    "value_of_your_tag",
            },
        },
    }
kaspers1778 commented 1 year ago

Same question here, cannot understand how to deal with SetTag("") method if we cannot set key-value pair.

emawby commented 1 year ago

@icobani I recommend setting up segments using the tag and targeting in that way