What is the right way to keep the information between my bot and Facebook consistent? - chatbot

From what I read in the Facebook Messenger documentation, there are a couple of callbacks that are triggered. The onReceivedAuthentication() as per documentation is called when a person taps on the "Send to Messenger" plugin. I want to save the person's firstName, lastName, picture and gender in my database. What if the person directly searches for our page and starts chatting with it? In that case, the above callback won't be triggered right? What if the user changes their name or picture on Facebook? How do I keep my database consistent with Facebook's data for each user?
Currently, I am updating the person's details in my database everytime the user greets my bot. I don't think that is a good strategy. Any suggestions are appreciated.

Just decide particular time limit like 1 hour or 24 hours or 1 week or as per your choice and when you store user's data from facebook by its graph API response,store one more field for that particular time of storing it either by timestamp or date and after that whenever you get message from user just compare that messages' timestamp with that field and if that difference is greater than that decided time limit then update users' data.
you can compare user's current message time as you are getting it in form of timestamp with every message
Hope this help you.

Related

Ban a User in a particular firebase firestore group chat for predefined time

I am very new to coding. but i managed to build a group chat app using a low code platform called flutterflow. i managed to spend significant amount of time on it and was able to build a public group chat app except few functionalities. I am hoping to find help from here. for the following questions.
I have chat mods appointed on a group level. like if you create a group, you are a founder and you can assign mods to that perticular group chat. now i want these mods to be able to ban a user in that particular group chat.
I have tried created a subcollection in groups called "banned user" and created two feilds. one is "banned users" document reference to users. and another is "banned_till" to record a time stamp until the user gets banned.
Problem with this is when i ban a user twice, it creates two documents in the user reference with the same user. and two documents has different "banned_till" times. which one it is supposed to pick?
i tried to do this and put a conditional visibility to the chat that "if current time is less than or equal to banned_till time" it wont let user type in the textfield to chat. but this is giving me gray screen.
I am very new to this. any help would be appreciated.
there is specific way to do so. you have to set custom logic. like save all banned users in a firebase database object with thier max time and procced next.

How to know the count of repeated entries in Firestore flutter?

I'm creating a appointment app in flutter using firebase in which I have keep the track of people that got appointment repeatedly based on their phone number . How do I get this count of repeated entries?
it would be better if you add some code and more information to your question so we can can answer correctly but based on my understanding you want to check if this user repeatedly booked appointments using your app considering that it is a logged in user not a guest,
in this case inside your Firestore collection that contains the users i assume that each document represent a user add to each document (user information) a counter (integer variable) called for example "appointementsNumber" and every time a user book an appointment this counter will be increased by one, in this case you are able to know how many times this user booked an appointment.
hopefully i did understand your question correctly.

How to send message to specific facebook user from website?

My goal is to make a website, in which user could customize a photo and then provide his friends indicators like name or id. My next task is to fetch that info from database and send messages on specific date to provided users. Ex birthday wishes, greetings, and so on.
I studied facebook send api for a few days now and couldn't find solution for myself. If I want to send message, I need to have Page-scoped id of user, which is acquired when the person text you first, which is not desired, because person wouldn't know what it is.
Also I was looking into Customer matching API, also seems to require the same PSID. The next thing I checked was Send Dialog API, which seems to send messages instantly, but not on the specific date. Also I checked unofficial facebook-chat-api, which asks for user ID, whereas I can find my id, I couldn't find ids of my friends.
So I just want to know is it even possible, if yes, I'd really appreciate your help.
User to User communication is not possible (and not allowed) in an automatic way, there is no API for it except for the Send Dialog. The Messenger platform is for page to user communication only.
Do not use inofficial tools, they are not allowed and might get you banned.

Facebook APIs using checkins as an entry to raffle

I've been exploring ways that it might be possible to promote the business of a friend of mine. One of these ways is by encouraging users to check in to his business, the incentive for this being that they go into the draw to win some kind of prize.
I've been trying to find if the code for this already exists but I might be looking in the wrong places. If it doesn't what would be the best way to do it using the graph APIs.
Thanks.
You can use Facebook app to check-in to your page/business.
All page check-ins can be fetched using following request by your code
https://graph.facebook.com/PAGE_ID/checkins?access_token=PAGE_ACCESS_TOKEN
If you want to get only specific time period check-ins use since and until params in query.
You have to parse the json response and store in an array and randomly select the winner.
you can contact the winner using their facebook id and send them a message.
You will have to write the code yourself, but it would essentially work like this:
Get the user to allow access to the "Raffle" application and get their email address and permissions to look at their check-ins. Email is required to contact the winner.
Use a scheduled script (cronjob) to periodically check if the user has checked-in anywhere (in particular, the business you want to promote).
Award a raffle ticket for each unique check-in within a 24 hour period.
Hold a draw between all the users who checked in on that day or week and award the prize to someone randomly.
Pretty simple flow, but complex code.

Which user data can be stored in my system apart from the Facebook ID?

I would like to know if I can store more data than a Facebook user id. In the old API it says no.
From ttp://developers.facebook.com/docs/ref … ndardinfo/:
The only storable values returned from this call are the user IDs.
But, could I store data if I do not relate it to the user? For instance: If the user is a woman, and rates something in my page, could I count a +1 women vote in my page without relating to the user?
That information is really old. Long ago Facebook changed the rules so you could "cache" any information 24 hours. Last year they then changed it so you could store it indefinitely. However, there are still rules on what that information can be used for. Look at the question "How long can I store data?" http://www.facebook.com/help/new/?page=1100
Now it's pretty much all based around permissions. Basic authorization gets you basic information about the user, based on their privacy settings. The user may not allow you to tell their gender. If you want more information, you need to prompt the user to grant you access to that additional information. Facebook has even setup a real time API for subscribing to user information changes. For example, you can get "alerted" if a user changes their gender (bad example).