checking whether user is registered with onesignal

Hi,

I am using OneSignal to push notifications to specific userid, but i got a 400 bad request error. I realised to solve it, i will have to ensure that i am only pushing to users who are registered with onesignal. However, as not all of my users have logged into the app, some of the users are not registered, thus causing the bad request error. 

So i was wondering if there is a way to check whether the userid is registered with onesignal. There is a client action of "CheckOneSignalPlugin". Does this client action check whether the userid is registered or is it just checking whether that device has the plugin? 

I tried using this client action in a if condition (as shown in the screenshot below), and will only push notifications when this client action returns true. The issue of 400 bad request is solved, but the notifications is not sent. So i am also wondering whether this client action is checking the correct thing (whether users are registered). 

If not, are there other ways in order for me to only push notifications to users that are registered? 


The CheckOneSignalPlugin action, only valid if you have the plugin available.

You have a table called Device in the OneSignal API, which gives you the information on which devices have a given user registered.

You can see this Demo that will help you set up OneSignal correctly.

Cheers,

Nuno

Do not forget that to use One Signal, you need to create a project in Firebase, so that you can then have the Key to correctly configure OneSignal.

Nuno Miguel Verdasca wrote:

Do not forget that to use One Signal, you need to create a project in Firebase, so that you can then have the Key to correctly configure OneSignal.

Hi Nuno,

My setting up is done correctly, as the the notifications are working perfectly when i used the "PushNotificationToAll" server action. 

And by device are you referring to the server action GetDeviceId_PushToken_PlayerId?

Is there other reason which might cause the notification to be not sent correctly, given my logic in the screenshot of my post? 

Yes. You can make a join between the users table and the device, and knowing the user you can know which device you should send the push notification to. Let me know if you need help?!

Nuno Miguel Verdasca wrote:

Yes. You can make a join between the users table and the device, and knowing the user you can know which device you should send the push notification to. Let me know if you need help?!

Sorry i dont really get your meaning. Isn't GetDeviceId a server action? How do i join it with users entity?


First of all, you came to look at the Demo that I told you up there, it shows you how to do it ... If you can't understand it around, please tell me.

You have a table in OneSignalAPI, called Device. This table among other things has the HardwareDevice and the UserID (this UserID is a reference to your USERS 'table.


Imagine that you want to send a push notification to yourself, go to the Device table, and search for your user (GetUserId ()), and push to the respective device.


Imagine that you want to send to any other USER, knowing his user, you can go to the devices table, and know the HardwareDevice and send it there.


But it is only possible to send to the users who are present in this table, that is, they are registered, that is, who registered the device in the application (two actions you have from OneSignal (Register and RegisterWithUser)), if you already have users and only after you have placed OneSignal, you will have to make a logic of their registration, ensuring that the next time users log in to your application, they go through a given flow that registers them. But again, in the Demo I shared with you, there is a great example there. It even shows you how to build deeplinks with parameters in the link.

Nuno Miguel Verdasca wrote:

You have a table in OneSignalAPI, called Device. This table among other things has the HardwareDevice and the UserID (this UserID is a reference to your USERS 'table.


Imagine that you want to send a push notification to yourself, go to the Device table, and search for your user (GetUserId ()), and push to the respective device.


Imagine that you want to send to any other USER, knowing his user, you can go to the devices table, and know the HardwareDevice and send it there.


But it is only possible to send to the users who are present in this table, that is, they are registered, that is, who registered the device in the application (two actions you have from OneSignal (Register and RegisterWithUser)), if you already have users and only after you have placed OneSignal, you will have to make a logic of their registration, ensuring that the next time users log in to your application, they go through a given flow that registers them. But again, in the Demo I shared with you, there is a great example there. It even shows you how to build deeplinks with parameters in the link.

Hi Nuno,

Thank you very much for your help and for the demo! I will get back to you if i have any more questions. 


Nuno Miguel Verdasca wrote:

You have a table in OneSignalAPI, called Device. This table among other things has the HardwareDevice and the UserID (this UserID is a reference to your USERS 'table.


Imagine that you want to send a push notification to yourself, go to the Device table, and search for your user (GetUserId ()), and push to the respective device.


Imagine that you want to send to any other USER, knowing his user, you can go to the devices table, and know the HardwareDevice and send it there.


But it is only possible to send to the users who are present in this table, that is, they are registered, that is, who registered the device in the application (two actions you have from OneSignal (Register and RegisterWithUser)), if you already have users and only after you have placed OneSignal, you will have to make a logic of their registration, ensuring that the next time users log in to your application, they go through a given flow that registers them. But again, in the Demo I shared with you, there is a great example there. It even shows you how to build deeplinks with parameters in the link.

Hi Nuno,

I have some questions regarding your demo. 

When you use GetDeviceID, it means that it will get the deviceID of myself right? So in the server action of Notify_Delivery2User, your if condition of "Was a device added?" is 

SyntaxEditor Code Snippet

DeviceId<>""

Does this condition mean that when I do not have a deviceId (means not did not log in with a device), it will send the notifications to device? But i thought when your deviceid is " ", there is no existing device to send notifications to? 

In my own app, when i use the "PushNotificationToUserId", the UserId i use in the input parameter may not have a deviceId, thus result in the 400 bad request error. But according to your logic, when you use GetDeviceId, isn't it only getting my own deviceId and not the deviceId of other users? So that would mean that notifications will still be sent to users without a deviceId. 

Sorry if i understand your logic wrongly and please correct my understanding!! Thank you!

Edit: I think that in your demo, you are only sending to notifications to yourself (as you used GetUserId() in your Notify_Delivery2User) and all users. However, for me i am sending notifications to selected users (which i have filtered using aggregate editor) and these selected users might not have registered with OneSignal. So i need to be able to check whether every user that i am going to send notification to has registered with OneSignal. This is the part which i cannot figure out and need help with! 

Yes, GetDeviceId, is a function that will get you the Device ID (Hardware Device Id). So that when you call the action of OneSignal, he inside can go cross the Devices with the Users.






Snippet de código do editor de sintaxe

DeviceId <> ""



This condition means that if you have a Device registered in the OneSignal Devices table.

Yes, OneSignal sends notifications to the device, not to a user or a mobile phone number, but to a device.

Of course, he is not obtaining the Device ID from other users, this is a function that reads the information from your device, which is then saved in that table. That is why all phones must be registered, if not at the time of sending the Push he does not know who to send to. Another thing, you must have logic to validate if the plugin exists or not (CheckOneSignalPlugin), another point, do not forget to add the client action "OnApplicationReady", and here in this action you must also place the validation of the plug-in.

Tell me, can you install the Demo that I sent you on your phone and run the App on your phone? That is the first thing you should try to do. Another point, I deduce that you have already configured Firebase, OneSignal (links that I left you up there), as well as you already placed the Keys in the site properties in the Demo (and consequently in your application)?



let me know if you understand? =)

Nuno

Nuno Miguel Verdasca wrote:

Yes, GetDeviceId, is a function that will get you the Device ID (Hardware Device Id). So that when you call the action of OneSignal, he inside can go cross the Devices with the Users.






Snippet de código do editor de sintaxe

DeviceId <> ""



This condition means that if you have a Device registered in the OneSignal Devices table.

Yes, OneSignal sends notifications to the device, not to a user or a mobile phone number, but to a device.

Of course, he is not obtaining the Device ID from other users, this is a function that reads the information from your device, which is then saved in that table. That is why all phones must be registered, if not at the time of sending the Push he does not know who to send to. Another thing, you must have logic to validate if the plugin exists or not (CheckOneSignalPlugin), another point, do not forget to add the client action "OnApplicationReady", and here in this action you must also place the validation of the plug-in.

Tell me, can you install the Demo that I sent you on your phone and run the App on your phone? That is the first thing you should try to do. Another point, I deduce that you have already configured Firebase, OneSignal (links that I left you up there), as well as you already placed the Keys in the site properties in the Demo (and consequently in your application)?



let me know if you understand? =)

Nuno

Hi Nuno,

Thanks for the quick reply. 

May i know what are the sources of the "GetDeviceByUserId" in your screenshot above? You kept referring to a OneSignal device table, but i dont seem to be able to find this table anywhere. Am i missing anything? 

And yes, i have configured Firebase and got the keys from OneSignal correctly. 


Solution

I didn't understand what you mean by the sources in my screenshot, can you explain it better? However, that is a screenshot of the OneSignal action itself.


About the table, you can find here:

Solution

Attention, that OneSignal is a Cordova plugin, what I mean is that it does not work in OutSystems Now. You will have to generate the app and install it on your phone. If you have an Android it's easier to generate, because in non-productive environments you don't need certificates to generate the App.

Miguel Verdasca wrote:

I didn't understand what you mean by the sources in my screenshot, can you explain it better? However, that is a screenshot of the OneSignal action itself.


About the table, you can find here:

Hi Nuno,

I tried to join the users entity with the device entity, however the device Id for every user is 0. Is it because i have to do something to the device entity? I did log into the user account using an android phone, so shouldnt there be a deviceId?


Hi Jolene Kwek,

let's step by step...

In the Demo application you placed this in the Extensibility Configurations:

{
    "preferences": {
        "android": [
            {
                "name": "AndroidLaunchMode",
                "value": "singleTask"
            }
        ]
    }  
}

On the site properties you will find the OneSignal keys:

  • OneSignalAppId
  • OneSignalRestAPIKey

You must also place the default values in the LocalSetting table

You generated the Demo application, and installed it on your Android phone, right?

After that, when you send to All or Me, do you receive push notification?

Miguel Verdasca wrote:

Hi Jolene Kwek,

let's step by step...

In the Demo application you placed this in the Extensibility Configurations:

{
    "preferences": {
        "android": [
            {
                "name": "AndroidLaunchMode",
                "value": "singleTask"
            }
        ]
    }  
}

On the site properties you will find the OneSignal keys:

  • OneSignalAppId
  • OneSignalRestAPIKey

You must also place the default values in the LocalSetting table

You generated the Demo application, and installed it on your Android phone, right?

After that, when you send to All or Me, do you receive push notification?

Hi Nuno,

there is some issues with opening the application, the screen freezes at the splash screen. I check the login page in my service studio, the roles are anonymous and registered. So im not sure why i cant move on from the splash screen.  


Have you already placed all screens as anonymous? But it's supposed to work without being anonymous on every page. Install this app please on your phone:

let me know if you can do it.

Miguel Verdasca wrote:

Have you already placed all screens as anonymous? But it's supposed to work without being anonymous on every page. Install this app please on your phone:

let me know if you can do it.

Hi sorry, i could get to the login page, but i suppose since this app is yours, i do not have the relevant login details?


Try now please

Miguel Verdasca wrote:

Hi Jolene Kwek,

let's step by step...

In the Demo application you placed this in the Extensibility Configurations:

{
    "preferences": {
        "android": [
            {
                "name": "AndroidLaunchMode",
                "value": "singleTask"
            }
        ]
    }  
}

On the site properties you will find the OneSignal keys:

  • OneSignalAppId
  • OneSignalRestAPIKey

You must also place the default values in the LocalSetting table

You generated the Demo application, and installed it on your Android phone, right?

After that, when you send to All or Me, do you receive push notification?

Hi, okay i tried it and i got the notifications. Also as you were saying above, for my app, i didnt use the local setting, i just inputted my onesignal app id directly into the input parameter of the "PushNotificationToAll"/"PushNotifitionToUserId". 


And now, do you think you can configure it?

Miguel Verdasca wrote:

And now, do you think you can configure it?

Let me try it and get back to you. Really thank you so much for helping!!


Miguel Verdasca wrote:

And now, do you think you can configure it?

Hi Miguel,

Thanks for your help. I found the correct device table.