okay in this video we're going to be talking about notification settings and we are going to be sending notifications to our device via the on Signal dashboard and via the one signal API um this is the second video I did one where we set up our user via API calls to receive notifications so if you want to go back and watch that you can it will be on the screen somewhere right now if you don't watch that don't worry about it because in this video I've actually set up the user a different way using the flutter one signal SDK so I'm going to go over that also do that at the end but first we'll do the notifications and send in them in the two methods so our people that have already set themselves up can do so but if you want to actually use the flutter SDK to do it you can stick around and go through that at the end for the second half of the video it's a much simpler way of doing it within the API so pros and cons are both options so we'll go through when we get to it and so let's get started so we've got our user enabled notifications via these buttons so and we set up the one signal system so on your one signal dashboard basically you just go to new message and we want a new push in app we can also do uh it's one of the reasons why the SDK makes a bit more sense than the using the apis like I say pros and cons but it makes easier handing inapp messages via the SDK so again so we going to come on to but although inapp is not going to be part of this video but it's when we get to the pros and cons we'll talk about them so we want a new push notification so you need to give your campaign a name so we'll call it call it great deals obviously we want to be selling our users something I suppose ultimately that's kind of the the um I guess the point to much of this sort of stuff so basically you can send to all your subscribers which is here or you can send to particular segments now particular segments will be different groups of users so we'll go that and if we include segments you can create new segments and add users to them so we could create a segment but we're going to send to test subscriptions we've got a test subscriber down here and then we come down so obviously you can do it in different languages we're going to just use English and you need to give your message title and as you'll see see on the screen on the right here you'll see what it's going to look like when it's uh when it's done so oh L don't know where that is London is what we're looking for and then we can send the US of the message so 20% discount five star stays the launch URL that will be what the what L what launch is when your user clicks on it so I'll tell you what we'll do okay so in there we'll just add obviously that' probably be your own website or it'd be an affiliate link or something or whatever you're going to do it so but we're going to send our users to booking. com for there festar discount stays and in our here okay so our next bunch of settings are specific to Android so what we're going to be doing because this was an Android demonstration originally I was going to go through this quickly the small icon default is a bell obviously you can set something else so for categories you can create some categories and you can set some parameters on how you want your notifications to look and sound uh but if you set it for none it will just use the device defaults you can play that obviously to your heart's content and then the priority doesn't get it delivered any quicker it's to do with how Android basically deals with the the message in terms of displaying it and waking the phone up Etc and then you can add some action buttons so you can play around with those and then you can schedule your your delivery so we can send it to everybody at the same time now think to remember about these These are push notifications so these are the ones that if we open up so we're in Android Studio so these are push notifications these are the ones that sit in your in your notification tray now what happens is if your your app is in Focus I it's on the one that's in being used your notifications won't show up in the app that's what the app notifications are for um these will be delivered when the app is out of focus in the background and your user logged in that's in the documentation so if we head back to there and we just send send that notification and then message started sending so it's been delivered now that doesn't necessarily mean delivered to the device when you again when you documentation all that's telling you the notification has been delivered to the Google Firebase Cloud messaging servers and they're then dealing with it basically although Google say they are delivered at the same time but let's see so let's have a look if we just Dr down and then we go look great deals on London hotels get 20 October five star stays and it's going to launch booking. com it's going to launch something there we go so don't need cies right so that's how you send them from the dashboard okay so that is obviously uh pretty straightforward sending messages from the one signal dashboard so what I'm going to move on to now is to super base and we'll look at how setup doing it via the one signal API so if we head over over there now I have got a table here uh called products and the idea is that obviously you could do this for any table that you wish but for this instance what I'm doing every time there's an update in this table it gets a new row we have a trigger which operates a function that connects to the one signal API and sends a push message to our users basically so new row in here trigger a function get a notification basically and as always any Snippets of code that you see on screen here you'll be able to copy and paste from a link down below so so essentially there are three functions you could do it in two OB justd do it in three um and I'll explain to why when I get to it so essentially first thing we're doing is creating a trigger after an insert on the public.
products table and for each new row we're going to execute function call Push which is the one that calls the push notification function this is the call push function and all that does in turn is calls the send push one signal function now the reason I did it this because this has to return a trigger for this function this particular the one that you call from the trigger has to return a trigger um but our sending push notification returns a Json which we're not really doing anything with but uh it's the one that tells us the success or not of our API course therefore if we have any issues we can debug and that kind of stuff which is why I've done it that way so we're still getting the response from the API for us to be able to deal with it if we need to so this is the function that actually sends the notification so if we just quickly go into database and we go into triggers and we're here in the public schema we've got that trigger set up and that then as I said through a separate function actually calls this one which sends the message to the one signal API so this is very much the same as I said in the previous video if you've watched any of my videos you'll recognize this it's I don't change it very much I just change the bits that are necessary so we have the main content of the Json the body of the Json for the request which setting up there I will come back to that in a second when we Lo documentation we have got our headers we got the typ is post we got our API m point and then we've got your with the API key now like I've said previously I've hardcoded in this particular one um normally you'll see me have done it through the to base vault which is very easy to do and there is a video on that which will come on the screen now and then again we've got the content type in headers and whatnot and then we are sending the content there and we respond getting the response which is the success code or not as the case may be and any data associated with that so the request itself on the documentation if you remember this from the previous video there is a handy section at the bottom where you can actually construct your request here so you know what you're doing so you'll have your you need to put your app ID that's required what segments you targetting if remember previously we used test subscriptions again there's some more options which obviously you can play with the content is usual your content is obviously required um English is a requirement all the other one all the other languages are not we can give it a head up if we wish again not a requirement and then if you remember there in the uh original message we sent a few minutes ago we used booking. com as the URL and then say loads and loads of different options not really any of which are are required um but say you can read this and play them I'll put a link to this documentation down below even uh if you've got a one signal account obviously you'll have it anyway but I'll put the link Down Below in case you want to read up on it before you start so and then your API key that is um obviously required so this tool is really good it gives you so you can set up your set up your request here in the examples so you know how to format it in your API requ that you're making and that's what we've done here using the build object and then our message is you know get some discount on some attractions we send it to test subscriptions we have to send the app ID obviously and then our heading is 20% cheap Halloween that's just you know just a testing I've set up and that's it really and then what will happen is on the update of the table with a new row it will just trigger this so I have hardcoded these even again as a test these values here and that one specifically those two you'd probably want to put them in if you're doing this on depending on what table you're using and how you using your notifications you may want to put these as variables passed into the um function because it's just a more efficient way of doing it obviously rather than keep changing this function to hard code them in that's just not efficient at all obviously so again for this purpose of the test I've done that but you want to do it with variables you can and there those videos well I've done this on many occasions uh so I'm sure you've seen those as well so that's how you set up it based on a trigger and this is how you create the API call to the one signal API so if I head over to the actual device now I did this earlier so I won't trigger it again so so if I look at the notification history on the device you can see there we've got the 20% Halloween discount not in our tray as long as well as the other ones where I've been playing around with this um previously so as I said at the beginning I've done this via the one singal SDK previous video we did it via all by API calls and I thought I'd try something different for this one and see how that functions and if it was easier and it definitely is easier rather than if you remember it got a bit convoluted in the end so if we go to Pub dodev this is the package we're using basically the one signal flutter package and we are bringing it into our cod as a dependency so start one signal on the bottom right side there you see we've got the dependency for the flutter and then we've got the couple of Snippets of code we need in the actions to make it work so if we head to enable notification so the enable notifications and notification settings rows are both conditionally visible so if our device is showing that we are authorized to have notifications then we get the notification settings so then we can switch them off if they're not authorized we get enabled notifications which allows us to switch them on and we're doing that via a custom action on page load which check notification permissions and what that does it goes and checks our device see if we've got notifications enabled and for that we need Firebase messaging package to use that and again on the pevious video I mentioned this as all well but if you haven't watching that or you're not watching that you can't use any package related to than 14. 9 point2 with flutter flow that's because the Firebase C or package that flutter flow uses is not compatible with anything later than that so what we're doing and we split this really between authorized or not so if it's authorized you get the notification settings if it's anything other than authorized you'll get the enable notification settings so that hasn't changed so to enable notifications you can already see it's um a lot simpler so I'm still requesting permission via the flutter flow system so on our settings and permissions we got it switched on there yeah would like to send you push notifications there is an option to do this with the SDK in actual fact and that is in the documentation again I'll put a link for the documentation here for the SDK section as well and then we can ask permission via one signal I haven't actually tried that version if I'm being honest I just stuck with one I already had and then we're saying if it's true or false with request permission then we'll get the standard Android box at request permission to send notifications and if our user says no thank you very much it doesn't do anything it just sort of terminates there's nothing else to do because we're not having notifications if they say yes what we had doing is starting one signal so again that's much more simple and that just calls that custom action we had up a few minutes ago start one signal so we have to initialize one signal with our app ID and then simply opt in our user to subscriptions and then that will allow us to receive notifications and that's how this is functioning on the version that we've been using for this demonstration in this video what will happen is then our notification settings will be visible and then on the notification settings when you tap that still brings up an alert di an alert dialogue called notification which is a custom component and again I've styled this to look a little bit like the standard Android one and if we want to keep them active basically just dismisses the dialogue because there's nothing to do if we want to turn off notifications we got custom action stop one signal navigating back to the user page and we're opening the app settings so custom action stop one signal essentially same as what we've just had for starting War signal except we're opting out of notifications and then the other action at the end there opens the app settings within our device and that is another custom action which simply opens settings for our app so we can disable notifications and that relies on package app settings 5.
1.