send notification by cloud function with firebase flutter | FCM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys uh now I'm going to show you that how we can send notification if there is any kind of update in your database first of all let me open my application okay this is the app uh so I have logged in this app in this app like my name is for sure and this is my phone number you can see this is my document in the cloud files too this is the fcm token which I have saved from the Firebase button sorry from the flood app why uh initializing the fcm so if you want to just first of all let's see the example uh what will happen if I just change the email I'm going to put this app into the background okay so this is my email if I change this email the notification will be sent to the user if your email has been changed machine [Music] foreign gmail.com please do then MD version gmail.com to achieve this uh we are going to you need to be uh completely uh done the setup with fcm and firestore okay and the flutter local notification also it is present if this package is present in the cup tab so first of all just set up that all come uh setups with those two packages after that you can come to my video before that you can't continue this process uh so you have to so let's start the coding first of all I'm going to delete the function uh which I have uploaded before then after that we are going to start coding so just let it update the loading the function name was email chain notify notification so I'm gonna delete this function now function as deleted if I go to customers then my phone number is equal to plus one okay this was my document right uh if I change anything in the email there is an email saying if I change here sending any kind of notification to the user because no notification said yeah it was like 60 minutes ago so now we are going to start the coding let me just when my videos oh I was deployed the function here before so I'm gonna start recording right now you need to initialize your fireplace first of all like Firebase in it type this command first of all yes what you want to or do right now you we want to write the short function so I'm going to choose the functions here next JavaScript no already exist I have already initialized my Firebase in it so you can also do this the same process and just put mode no again you should say do you want to install the dependencies yes I should type yes here okay so let's start the coding uh let me go to my functions after initialization of Firebase this folder will be already created uh you should go into the index.js ALS so you need to import your sum of some files like Firebase functions so my import functions functions required Firebase and transport then next we are going to import Firebase had been here and domain and equal to require Firebase at midnight okay done so next slide this admin.initialize app reciate the initialization has been completed then we are going to use now we are going to write the function that if any kind of changes happen in your database so it will going to send the notification to the user export toward the function name you should provide the function name first so we'll use a different function name right now like email send notification on email chain this is very big let's do this okay the functioning will be this so notification on email change so I'm going to write function here so take the functions first then after DOT first Port after uh go on the collection inside the document foreign field that is the email whenever the email has changed the function will be triggered so it will then after we need to choose when you want to send the notification on create on delete or an update on right okay let's we are going to see on update third we need a call we have to write a callback function which will be async it will take two parameters snap and phone text then after that all right whatever you want to do whenever you can get that document updated after updation so we'll got the snap of that snapshot of that document here so we are going to use that snap right now so uh store the data uh it will provide you the two kind of data like before uh which means you will get the data which is before the update okay that is all data so to use it here inside the operator after now before we leave the data before response we are showing it will data so we got the whole data that will get the new data which is after update snap after told data okay this has completed okay now we are going to write the page we are going to create a payload which we will want to send to the user in the future so if all data dot email should not be equal to the new data email okay which means the whole data in the new data should not be saved which means you are not doing any kind of update so it will not going to send any uh notification to the user it will be triggered but not do not send any kind of notifications so user or something like that so next oh really are going to create a payload here so payload payload or payload equal to inside an object we are going to use notification parameter notification equals to add another object inside this object we need to use the title let's say the title I am going to like something or email changed no okay let me just two batteries yeah sorry for that device um now that it will be your email change no no okay then your body is going to be or something like proper place and placed okay then we are going to use here the New Order mail then press your data Dot for me okay the next song will be something you have to use in your in your flutter project the next China Channel ID will get from the uh see if while you are setting up this all you will get to know what is channel ID and all that Channel ID B the hungry it should be same uh in the app you have given the channel ID for again Android Channel ID also the same angry itself I'm going to put this in similar quotations then next priority will be high okay we have successfully created our payload signed the drive block I'm going to write I'm going to call a function here like the response will be stored foreign messaging started messaging you have function called set two device so divide needs an array of whatever you want an array of like a token you need to provide the fcm token this token will get while initializing your fcm and flutter shutter local notifications with your flutter for Firebase project so I have already tooken here which I have initialized when when the user has signed in into my app so I'm going to use this field here so we'll get the new data inside the new data we also have the fcm token the next payload that's it any kind of error we are going to use this console.log set this logo I'm going to put the error so this is a function I guess it should work let me just deploy this function here the function name was send notifications on email change so I am going to call Firebase deploy here to deploy these functions would you like to proceed with deletion select one will continue the result I already have the previous functions uh deployed the Firebase so I don't want to delete those functions okay so it is just deploying let me open our new tab and we are going to watch the functions so email asset notification on email change it is creating the function is created could not deployed completely after deploying completely you are going to test this function try using uh all always try testing the testing in a physical device so that you will get to know is it working or not these are all the previous functions which I have created but this is the new system creating right now okay deploy has completed so let's take our project here sorry our device mobile device if I change any inside this notification will show different ly okay so I guess it is no yeah it is working uh your email changed now did you push it replace to empty push here okay if I change it to something else changed again there is no notification website okay so thank you guys the video has come to
Info
Channel: Code with Backbench
Views: 4,631
Rating: undefined out of 5
Keywords:
Id: RAfcpVSB4uY
Channel Id: undefined
Length: 17min 26sec (1046 seconds)
Published: Fri Jan 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.