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

[Bug]: CreateNotificationSuccessResponse.Recipients = 0 after sending push. #42

Open
1 task done
magnetica opened this issue Nov 21, 2023 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@magnetica
Copy link

What happened?

we are sending notifications and the response.Recipients is always = 0, but we have few active devices that receive them.

Steps to reproduce?

this is my code (using asp.net mvc)

if (ModelState.IsValid)
			{
				// prepara record
				PushNotification push = new PushNotification
				{
					Note = pushvm.Note,
					Title = pushvm.Title,
					Language = (int)pushvm.Language,
					UCode = StringUtils.CleanString(MAGNETICA.Utils.Funzioni.GenerateHashMD5(MAGNETICA.Utils.Funzioni.CreateUnixTime())),
					InsDate = DateTime.Now,
					InsUser = User.Identity.Name,
					Sent = false
				};

				//invio push
				OneSignalApi.Client.Configuration config = new OneSignalApi.Client.Configuration();
				config.BasePath = "https://onesignal.com/api/v1";
				config.AccessToken = ConfigurationManager.AppSettings["OneSignalRestAPIKey"];

				var apiInstance = new DefaultApi(config);

				StringMap headings;
				StringMap content;
				string segment;
				if (pushvm.Language == PushLanguage.Italian)
				{
					headings = new StringMap(it: pushvm.Title, en: pushvm.Title);
					content = new StringMap(it: pushvm.Note, en: pushvm.Note);
					segment = "Lang-it";
				}
				else
				{
					headings = new StringMap(en: pushvm.Title);
					content = new StringMap(en: pushvm.Note);
					segment = "Lang-end";
				}
				var notification = new Notification(appId: ConfigurationManager.AppSettings["OneSignalAppID"])
				{
					SmallIcon = ConfigurationManager.AppSettings["BaseUrl"] + "/Content/Media/logos/AppIcon.png",
					IncludedSegments = new List<string> { segment },
					Headings = headings,
					Contents = content,
				}; // Notification | 

				try
				{
					// Create notification
					CreateNotificationSuccessResponse result = await apiInstance.CreateNotificationAsync(notification);

					push.Sent = true;
					push.SendDate = DateTime.Now;
					push.Recipients = result.Recipients;
				}
				catch (ApiException e)
				{
					//Debug.Print("Exception when calling DefaultApi.CreateNotification: " + e.Message);
					//Debug.Print("Status Code: " + e.ErrorCode);
					//Debug.Print(e.StackTrace);
				}

				_moDb.PushNotifications.Add(push);
				_moDb.SaveChanges();

				return RedirectToAction("Index");
			}

			return View(pushvm);

What did you expect to happen?

receive the number of recipients

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@magnetica magnetica added the bug Something isn't working label Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant