How to modify firebase database so that i can set a read or unread status - reactjs

I need to show the count of unread messages from firebase in the notification bell.
I am done with displaying all contents in my collection in my web application.But when a new message arrives i need to give a feedback to user by showing the unread message count in notification bell .From my understanding,for that i need to set a read/unread status in firebase collection.Is there any alternative way for showing the count of unread messages in my React Web Application?
i am using firebase package of npm for displaying messages.
Below is the sample data in my firebase collection.
name:"John Doe",
message:"you got a new appointment"
i am new to firebase.Please help me with some logic to sort out this problem.

If I understand correctly, you would want to use a status flag (read: boolean), unless you would not mind writing all new messages to a particular path and moving them to another path after it is read.
Something like below
/user/unread-msg => all new messages come here
/user/read-msg => messages are moved here after being read.
This I believe would be less efficient than using a simple flag.
You could use a firebase cloud function to maintain the count of child elements in a particular path like /user/unread-msg or /user/read-msg so that you don't have to download the entire data to get the count.
Refer the sample code at https://github.com/firebase/functions-samples/tree/master/child-count

Related

Variable value for Amount for Salesforce opportunity API

I'm working on a Magento website. In that, after the customer is done with adding products to the cart he fills a form and once the form is submitted, form data along with product details like SKU, price is sent to Salesforce to create a new opportunity.
The API is working and the Data is going to salesforce, but the issue is that the same product can have different prices based on certain conditions.
the new amount going to salesforce but on the salesforce side, the new amount is not reflecting but the amount when the product is created for the first time is coming.
is there any way to make the amount a variable field so the new amount reflects?
below is an image of the opportunity and the JSON data I'm sending.
{"StageName":"New Opportunity","Name":"test","CloseDate":"2021-06-04","What_are_you_interested_in__c":"Purchase New Trailer","Product_JSON__c":"[{\"Name\":\"Large Trailers\",\"Sku\":\"large-trailers-rent\",\"Quantity\":1,\"Price\":\"1301.0400\"}]","Purchase_Delivery_Contact_Phone__c":"123","On_Site_Contact_Email__c":"test-12#test-12.com","Mailing_Street__c":"test-12","Delivery_Street__c":"","Qty__c":"1","X66969__c":0,"First_Name__c":"test-12","Last_Name__c":"test-12"}
This request looks weird. Vanilla Salesforce doesn't need hacks like a text field to hold serialised JSON in it (Product_JSON__c).
Where do you send it? Normal POST to something like services/data/v51.0/sobjects/Opportunity or some custom endpoint (it'd have "/apexrest" in the URL). Even if it goes to normal endpoint - I guess there's trigger that deserialises this Product_JSON__c and creates OpportunityLineItems out of it. You'll have to chat with developer responsible for that trigger, we can't tell what's going on in there.
In general yes, it's possible to have variable prices. You (or that developer) have to read up about OpportunityLineItem. There's ListPrice,UnitPrice,TotalPrice,Discount, lots of choices to do this right and report properly on the discounts! And there are tips like
Creating an OpportunityLineItem increments the Opportunity Amount
value by the TotalPrice of the OpportunityLineItem
There are ways to do it properly, insert header (Opportunity) and line items in one go, without such hacks. See
https://salesforce.stackexchange.com/questions/155422/using-the-rest-api-to-create-parent-and-child-records-in-a-single-http-request
https://salesforce.stackexchange.com/questions/274694/can-you-upsert-using-composite-sobject-tree
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobject_tree.htm

When is new Gmail API History ID generated

I am trying to design an algorithm to maintain a list of new INBOX messages using a combination the watch()/push notification, with the user.history and user.messages gmail apis. HistoryID documentation is unclear.
https://developers.google.com/gmail/api/guides/sync#partial
indicates
"You can also use push notifications to trigger partial synchronization in real-time and only when necessary, thereby avoiding needless polling." -- My question is HOW?
Which event on the email account triggers an incremented HistoryID?
If I guess HistoryID I get in the push notification the latest historyId of the label specified, then I should be able to use that HistoryID as the starting HistoryId in the User.History.List call, but when I do I just get an json response which is another higher HistoryID. So, if I'm specifying messagesadded and watching INBOX, why is the call to History API with the most current HistoryID returning no HistoryList objects?
I have read Gmail API users.watch - no details for historyId and Gmail History list is not giving complete data
and I'm unclear as to how to design the algorithm to use push notifications in conjunction with the other apis to do a partial sync to maintain a running inventory on new INBOX messages, as per the documentation.
this issue really sad, google just send historyId with empty history list. But why cant add emailId or property that this history binds with new message arrived?
To solve this problem u need remember time when u last time fetch email messages with total counter messages in Inbox, next, when u get google pub/sub message and it has empty history object - u need get new total counter of messages in Inbox label - if there is differences - next what u need is fetch email messages using:
or
max count value = differences between of total counter messages,
means add query to get messages by max result
or
using date time from your last update - means add query to get messages by date time.
Really bad that google make such bad implementation for pub sub for new messages.

Why does gmail API when using history.list method send message ids without the field what action has been preformed on them?

When using gmail API, history.list method we get "bare" message ids with no additional field from the fields in 'labelAdded', 'labelRemoved', 'messageAdded', 'messageRemoved'. Why is that? And is it possible that a new message has been added but when we use this method, the field messageAdded hasn't been used, so we receive it "bare" ?
According to the GMail history API, the list only contains the id and threadId fields.
It works this way because the objective of the history API is to provide you with the changes that happened in the mailbox, not its contents.
After you obtain the list from Users.history: list you need to call Users.messages: get or Users.messages: list to get the full messages.
If the messageAdded field is empty, it means that no new messages were added after the last historyId you examined. You might have skipped some. Make sure that every time you query the API you internally store the last historyId you processed so you can resume from that point in the future and not lose any changes.

Is there any way to limit a Gmail watch to only messages added?

When setting up a watch for a user is there a way to limit the watch to only messages added to the inbox?
Based on the documentation (https://developers.google.com/gmail/api/v1/reference/users/watch) I see that there is the option for INBOX labelId, but I want to limit it to only messages added as well. We're currently having to handle this by passing 'history/messagesAdded' in the fields string in the subsequent history.list call.
Unfortunately you cannot. what you have to do is
Get the history when notification arrived. History returns a json and it contains a 'messagesAdded' if new message is added.
You can keep a predefined array of labels like below
predefinedLabels = ['UNREAD', 'CATEGORY_PERSONAL', 'INBOX']
Now you can check, (each is the history json)
if 'messagesAdded' in each:
labels = each["messagesAdded"][0]["message"]["labelIds"]
intersectionOfTwoArrays = list(set(predefinedLabels) & set(labels))
Here you get the intersection of labels. Now you have to check that with predefined labels
if set(predefinedLabels) == set(intersectionOfTwoArrays):
#get the messageId and do what you want
finally you can filter the notification as you want!.
It is better to store histroyId and update it with every
notification and use it when you get the history. It will help you
to get updated history only.
Please note I used python when I was building my sever. So above demo code written using python
It looks like history.list added a new parameter "historyTypes". If you set that to "messageAdded", the api will only return history records of that type.

Watson Dialog does not recognize continuation of conversation

When trying to use the Dialog tool to get a feel for how the APIs work, I ran into a problem where a POST to /conversation creates a new conversation, instead of continuing an existing one. I am using the docs found at : http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/dialog/api/v1/
An initial POST returns a conversation and client id, but subsequent requests with those values added, along with an input value, just return information for a new conversation. Are these docs inaccurate?
Here is a screenshot from one of my many attempts at getting this to work. The client and connection IDs are from a previous POST to /conversation
http://imgur.com/4035dWe
Thanks for your help!
Your first call to Converse you should not specify the conversation ID. Dialog will return a conversation ID with the first response.
You then use that ID going forward to maintain the conversation. It is unclear if you are doing this in the example above.
It turns out I was using the incorrect encoding for the conversation / client ID's and input. Watson expects the form values to be URL encoded. Once I made that change, the problem was resolved.
Thanks to everyone who offered their time and help!

Resources