OneSignal / onesignal-dotnet-api

Other
13 stars 12 forks source link

[question]: Aliases, IncludeExternalUserIds as deprecated. #34

Open pmikoda opened 1 year ago

pmikoda commented 1 year ago

How can we help?

Previously I was using IncludeExternalUserIds to send notification to the certain external user/s, but from the newest version, this Datamember is marked as deprecated.

When I'm trying to use aliases I have some problems with it. I'm not sure how to create them (is it available on the FE side like it was for setting up of externalUserIds?) image

Also in documentation there is a mention about visibility of aliases in OneSignal Dashboard but I can't find these.

My actual code looks like this: image and I don't know what should I pass to aliasLabel <- and where to create this if I want the same label for all users but send notifications by their externalId.

Code of Conduct

emawby commented 1 year ago

@pmikoda Good questions the aliases function similarly to external user id, expect they are a key value pair where you supply both the key and value instead of just the value. This allows you to have multiple external ids if you for example you integrated with facebook and google, and wanted to represent those different ids separately.

To get the same behavior as external_user_id use the "external_id" alias label. To add an alias you can use IdentifyUserByAlias.

mjasikowski commented 1 year ago

@emawby The type of parameter that PlayerNotificationTargetIncludeAliases accepts is incorrect. It requires a List<string>, while it should really require Dictionary<string, List<string>, where the key for that dictionary should be the alias label (i.e. external_id), the value being a list of actual IDs.

Currently it generates the following JSON payload:

{ 
   "include_aliases": {
      "alias_label": ["values"]
   }
}

The alias_label property here cannot be renamed. This is actually the case for the SDK in other languages as well. At the moment the IncludeAliases property is unusable due that problem.

ante-maric commented 1 year ago

I just bumped into this too :(

emawby commented 1 year ago

@yasikovsky Thank you for pointing this out we will address!

temcewen commented 1 year ago

@emawby This is a severe issue. I suppose we should just continue using "IncludeExternalUserIds" until it's fixed, correct?

temcewen commented 1 year ago

Any updates on this?

nan-li commented 1 year ago

This is a bug we are fixing. In the meantime, it is safe to continue using IncludeExternalUserIds @temcewen

grantvine-sc commented 7 months ago

Has this since been resolved ?

nan-li commented 7 months ago

This fix has not yet been released. We are working on an overhaul of this library's API and Interfaces. In the meantime, you can use IncludePlayerIds to target by subscription ID or player ID, and use IncludeExternalUserIds to target by external ID.

Thank you for your continued patience.

matheuscschenfeld commented 6 months ago

Any news about this issue?

DaveBrask commented 6 months ago

I find that IncludeExternalUserIds works for me, and I plan on using it in production. Soon. Is that a bad idea?

matheuscschenfeld commented 5 months ago

@nan-li Any news from OneSignal on this? I'm constantly having problems creating a notification. It looks like the response = await appInstance.CreateNotificationAsync(notification); fails and I don't know why.

DaveBrask commented 5 months ago

@nan-li: i'm away from the office. When I get back I'll post working code. I'm suspect your create notification works but doesn't know anyone to send it to.
I'm working on requesting push notification permissions for Android 13 and iOS in Maui.

DaveBrask commented 5 months ago

@nan-li This code works for me to send via user id or by tag. In my App.xml.cs: OneSignal.Initialize(Common.Constants.OneSignalID);

In my loading page I use M plus the identity column value of the user to create the userID OneSignal.Login(Common.Constants.OneSignalExternalIdPrefix + lvm.MyInfo.MyMemberData.MyMember.MemId.ToString()); Then I add a tag for the unit they are a member of, U plus unit identity column OneSignal.User.AddTag(Common.Constants.OneSignalUnitTag, lvm.MyInfo.MyMemberData.MyUnit.UniId.ToString());

Then on the cloud server: Configuration config = new Configuration(); config.BasePath = "https://onesignal.com/api/v1"; // Configure Bearer token for authorization: app_key config.AccessToken = "REST API Key from OneSignal account"; var apiInstance = new DefaultApi(config); var notification = new Notification(appId: ScoutChat.Common.Constants.OneSignalID); // OneSignal app ID try { List exUserIds = new List(); exUserIds.Add(ScoutChat.Common.Constants.OneSignalExternalIdPrefix + "60"); // 60 is my member number notification.Headings = new StringMap("Title"); notification.Contents = new StringMap("Contents"); notification.ChannelForExternalUserIds = "\"push\""; Dictionary<string, object> dataDict = new Dictionary<string, object>(); notification.Data = dataDict; List filters = new List(); // field, key, value int unitId = 1; // 1 is my unit number Filter filter = new Filter("tag", ScoutChat.Common.Constants.OneSignalUnitTag, unitId.ToString()); filters.Add(filter);

            bool useFilter = true;     // I toggle this to test sending by member ID or by Unit Tag; both ways work
            if (useFilter)
                notification.Filters = filters;
            else
            {

pragma warning disable CS0612 // Type or member is obsolete

                notification.IncludeExternalUserIds = exUserIds;

pragma warning restore CS0612 // Type or member is obsolete

            }
            // Create notification
            CreateNotificationSuccessResponse result = apiInstance.CreateNotification(notification);
            if (result.Recipients == 0)
                Debug.WriteLine("No recipients");  // I find this happens even when the notifications are sent
            Debug.WriteLine(result);
        }
        catch (ApiException ex)
        {
            Debug.Print("Exception when calling DefaultApi.CreateNotification: " + ex.Message);
            Debug.Print("Status Code: " + ex.ErrorCode);
            Debug.Print(ex.StackTrace);
        }
JakubHolovsky commented 2 months ago

Hello, we are having this issue as well, are you open to merging a PR? So we just change it to a dictionary and resolve this issue?

DaveBrask commented 2 months ago

What issue are you having? The OneSignal folks agreed that the deprecation warning is a mistake and will be corrected so I'm not worried about that. I find everything else works except: When the app is closed clicking on the notification opens the app but the Clicked event is not called. I have opened an issue for that and submitted example code.