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

[question]: Send notification with tag filter #27

Open
1 task done
icobani opened this issue Mar 25, 2023 · 3 comments
Open
1 task done

[question]: Send notification with tag filter #27

icobani opened this issue Mar 25, 2023 · 3 comments

Comments

@icobani
Copy link

icobani commented Mar 25, 2023

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

  • I agree to follow this project's Code of Conduct
@Vitor-Bukovitz
Copy link

@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
Copy link

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

@emawby
Copy link
Contributor

emawby commented May 2, 2023

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

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

4 participants