OneSignal / OneSignal-DotNet-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your .NET app with OneSignal. https://onesignal.com
MIT License
14 stars 4 forks source link

[Bug]: Do not receive notification using externalId #87

Open Duddde opened 5 months ago

Duddde commented 5 months ago

What happened?

I'm trying to send notification with ExternalId. I do not receive anything. But when the external Id is null, i receive the notification on my device.

 public async Task SendNewMatchNotification(string userId)
  {
      //SendOneSignalNotification
      Configuration config = new Configuration();
      config.BasePath = _options.BasePath;
      // Configure Bearer token for authorization: app_key
      config.AccessToken = _options.AccessToken;

      var apiInstance = new DefaultApi(config);

      var notification = new Notification(appId: _options.AppId)
      {
          TemplateId = _options.NewMatchTemplateId,
          IncludedSegments = new List<string> { "Total Subscriptions" },
          ExternalId = userId
      };

      try
      {
          // Create notification
          CreateNotificationSuccessResponse result = await apiInstance.CreateNotificationAsync(notification);
          Debug.WriteLine(result);
      }
      catch (ApiException e)
      {
          Debug.Print("Exception when calling DefaultApi.CreateNotification: " + e.Message);
          Debug.Print("Status Code: " + e.ErrorCode);
          Debug.Print(e.StackTrace);
      }
  }

On my .Net MAUI APP i'm using OneSignal.Login(userId.ToString()); to register the connected user.

But in my subscriptions i have two with the same Id's (it's maybe the problem)

image

Any idea of what's the problem ?

Steps to reproduce?

Back end API .Net 7
pckg OneSignalAPI v2.0.2

Client : MAUI .Net 7.0
pckg OneSignal.SDK.Net 5.0.2

What did you expect to happen?

I expect to receive notification when using externalId

Relevant log output

Output of the one signal api : 
class CreateNotificationSuccessResponse {
  Id: 4cead680-2811-4134-b570-4f4d1bd95acc
  Recipients: 0
  ExternalId: 91b0045a-ed5c-49df-b499-88d382721db4
  Errors: 
}

Code of Conduct

Duddde commented 5 months ago

According to OneSignal Support, I need to use the IncludeExternalUserIds property instead of ExternalId. Indeed it seems to work. However, the IncludeExternalUserIds property is marked as deprecated by the SDK. Do you think this is the right solution?

The API return does not looks good...

class CreateNotificationSuccessResponse {
Id: 9481f102-ae46-4bfa-907e-fa8949a00aed
Recipients: 0
ExternalId:
Errors:
}
tulio-mcsantos commented 5 months ago

Accordingly with their documentation it is supposed to use the include_aliases property but I could not make it work with it. My Notification:

Notification notification = new(appId: "<MY_APP_ID>")
{
    IncludeAliases = new PlayerNotificationTargetIncludeAliases(["<EXTERNAL_ID>"]),
    TargetChannel = Notification.TargetChannelEnum.Push,
    Contents = new StringMap(en: "Hello world from .NET"),
    Subtitle = new StringMap(en: "Testing"),
};

Response:

class CreateNotificationSuccessResponse {
  Id: 
  Recipients: 0
  ExternalId: 
  Errors: class Notification200Errors {
  ActualInstance: System.Collections.Generic.List`1[System.String]
}

But using the deprecated IncludeExternalUserIds it did work:

Notification notification = new(appId: "<MY_APP_ID>")
{
    IncludeExternalUserIds = ["<EXTERNAL_ID>"],
    TargetChannel = Notification.TargetChannelEnum.Push,
    Contents = new StringMap(en: "Hello world from .NET"),
    Subtitle = new StringMap(en: "Testing"),
};

But it does have a kind of weird response:

class CreateNotificationSuccessResponse {
  Id: f1266639-78e0-477e-9977-48a223b410e2
  Recipients: 0
  ExternalId: 
  Errors: 
}
emawby commented 5 months ago

@Duddde Thank you for reporting. I am going to move this issue to the .net api Github repository since I believe this is an issue with the backend SDK and not this repo. To confirm are you able to receive the notification when you create the push notification using the web dashboard or using the REST API directly?

Duddde commented 5 months ago

Thanks for your feedback. Yes i'm able to receive notifications from the dashboard or my API.