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]: Response returned from CreateNotificationAsync is always null with IncludeExternalUserIds #28

Open
1 task done
Hoang-Minh opened this issue Apr 13, 2023 · 17 comments
Labels
bug Something isn't working

Comments

@Hoang-Minh
Copy link

Hoang-Minh commented Apr 13, 2023

What happened?

Notification is sent to user. However, response returned is null. Triggering through postman with the same object returns response with an id.

var appConfig = new OneSignalApi.Client.Configuration
            {
                BasePath = _appSettings.OneSignalBasePath,
                AccessToken = _appSettings.OneSignalApiKey
            };
var oneSignalClient = new DefaultApi(appConfig);
var ids = new List<string> { "123" }
var options = new Notification(appId: _appSettings.OneSignalAppId)
            {                
                ChannelForExternalUserIds = "push",
                Url = notification.Url,
                Headings = new StringMap(en: "Heading"),
                Contents = new StringMap(en: "Contents"),
                IncludeExternalUserIds = ids,
                IsAnyWeb = true,
                WebButtons = new List<Button>
                {
                    new Button(id: "read-more-button")
                    {                        
                        Icon = "http://i.imgur.com/MIxJp1L.png",
                        Text = "View more"                        
                    }
                
            };
var response = await oneSignalClient.CreateNotificationAsync(options);

Steps to reproduce?

1. Install OneSignalApi v1.0.2
2. Call CreateNotificationAsync with notification object
3. Response is null

What did you expect to happen?

If the notification is sent successfully, the response should not be null and it should have an id like it does with postman

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Hoang-Minh Hoang-Minh added the bug Something isn't working label Apr 13, 2023
@den-bessal
Copy link

I have the same problem.

@emawby
Copy link

emawby commented Apr 13, 2023

Thank you for reporting we will investigate

@mic2zar
Copy link

mic2zar commented Apr 17, 2023

Same in here. We got bombarded with null pointers over weekend.

@emawby
Copy link

emawby commented Apr 17, 2023

We have identified the issue and are working on releasing the fix ASAP!

@oscarito9410
Copy link

oscarito9410 commented May 11, 2023

same here please also see my issue #32 @emawby

@Plastiquewind
Copy link

Any update here @emawby?
I see that v2.0.0 is available on NuGet and IncludeExternalUserIds is marked as obsolete there, but with this version instead of null I'm getting a response with an error saying that external user ids are invalid.
Thanks in advance.

@guilhermeyabu
Copy link

Hi guys!

Any news about this issue?

@licon4812
Copy link

You cannot use dotnet simplified type initiators with the Notification Modle class.

You have to use standard constructors, at this stage. I am tempted to work on a fix, but here is another way of declaring the
new Notification() type

#37 (comment)

@sangheraajit
Copy link

Hi @Hoang-Minh

Are you able to make it work?
Is there any fix?

@PatryxCShark
Copy link

Is there anybody who found solution?

@sangheraajit
Copy link

Hi @PatryxCShark

We did not find any solution but we implemented direct API.

@PatryxCShark
Copy link

@sangheraajit so how to do it correctly? Could you show sample?

@sangheraajit
Copy link

public async Task<CreateNotificationSuccessResponse?> SendNotification(List UserIds, string message)
{

        var _httpClient = new HttpClient
        {
            BaseAddress = new Uri("https://onesignal.com/api/v1/notifications")
        };
        _httpClient.DefaultRequestHeaders.Add("Authorization", "Basic xxxxxxxxxxx");


        var notificationData = new NotificationData
        {
            app_id = "xxxxxx",
            android_channel_id = "xxxxxxxx",
            include_external_user_ids = UserIds, // Add multiple user IDs using a List<string>
            contents = new NotificationContents
            {
                en = message,
            },
        };
        var jsonContent = JsonConvert.SerializeObject(notificationData);
        var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");

        var response = await _httpClient.PostAsync("", content);
      if (response.IsSuccessStatusCode)
        {
            var resultjson = await response.Content.ReadAsStringAsync();
            Console.WriteLine($"\n{resultjson}");
           



        }
        else
        {

            Console.WriteLine($"response.StatusCode={response.StatusCode} response.ReasonPhrase={response.ReasonPhrase} response.Content {await response.Content.ReadAsStringAsync()}");
            //return response.ReasonPhrase;
        }
        return null;

@PatryxCShark
Copy link

PatryxCShark commented Mar 12, 2024

@sangheraajit thanks, but what is the difference?
I have one question more.
I want to register some notifications (channel "push").
Some of them are supposed to be sent now, some of them are scheduled.
I use IncludeExternalUserIds (only one id per one message in my case). Everything is OK but I cannot register notifications when such external id is not subscribed at the moment of registration. For notifications to be sent now is not a problem but for notifications to be sent in future it is because I expect to check if such user is subscribed at the moment of sending to its device.
And now I cannot register notifications for future which is a big problem because meanwhile such an external id user can be subscribed.
Is there any possibility to register expecially scheduled messages even if such external id user is not subscribed at the moment of pushing notification (registration in OneSignal)??

@sangheraajit
Copy link

Hi @PatryxCShark,

I have responded to your previous question with the answer below:

Thanks for asking, but you may be wondering about the difference between the codes. The first code uses pure HTTP request, without using the SDK. Meanwhile, NotificationData is a custom class that we created. Here is the class structure:

public class NotificationData
{
    public string app_id { get; set; }
    public string android_channel_id { get; set; }
    public List<string> include_external_user_ids { get; set; }
    public NotificationContents contents { get; set; }
}

public class NotificationContents
{
    public string en { get; set; }
}

Regarding your question about sending scheduled messages to an external user who is not subscribed at the moment of pushing notification, you can use a workaround by creating your own scheduler and executing the notification send function at the scheduled time. I hope this clarifies everything for you.

Let me know if you have any further questions.

Best regards.

@PatryxCShark
Copy link

Unfortunately @sangheraajit it makes OneSignal a bit problematic and a bit useless for sending notifications as scheduled.
It would be much better to choose if external id of user must be checked at the moment of registration or just at the moment of sending. It is more logical way because at the moment of real sending to device, beside this, it is checked currently again (and user can be unsubscribed - this is OK but why during registration?).
Are you going to add such opportunity to register always messages and just check external id at the moment of the set sending time?

@natanaelfiorilla
Copy link

A year later, and no fix yet?

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