Microsoft Graph Webhook/Subscription, getting multiple post to my notificationUrl - node.js

Im trying to receive push notification on calendar events through microsoft graph
the notificationURL points to webservice which is running on NodeJS
subscription I have made has these options.
{
"changeType": "created,updated,deleted",
"notificationUrl": "myurl",
"resource": "users/userid/events?$filter=sensitivity%20eq%20%27Normal%27",
"expirationDateTime":"2016-11-05T18:23:45.9356913Z",
"clientState": "customclientstate"
}
however im getting multiple POST calls(2~4) coming from subscription(all of them having identical body) whenever a single event is changed.
there is only one subscription active, a single calendar, and i am responding to the request with status code 204 without any content(tested with postman).
its a huge problem since im updating DB whenever the request comes in.
has anyone run into this problem? ive been looking all over without any results.
any input would be greatly appreciated!! =).

I have this same issue. When creating new event in office calendar I'll get everytime one notification with ChangeType: Created and at the same time three notifications with ChangeType: Updated. When I'm cancelling event in office I get always 3 x Updated notifications and finally 1 x ChangeType: Deleted.
What you can do here is to use ChangeKey validation. Everytime you get new notification from office you have to request that event from API, right?
Once you fetched that event you can check if event.ChangeKey property has changed.
It's same thing as etag in websites. If content changes, etag hash changes.
So when you get Created notification, take that event's ChangeKey and store it to array or db and whenever you get notification remember to validate if you have that event's ID already in array or db and also if ChangeKey has changed. If ChangeKey is same as last time, you won't need to update that event in db.
This also works with recurring events, if even one occurrence has changed SeriesMaster event's ChangeKey also changes.

Related

Shopify Webhook Real Time changing

is there an api on shopify where I can see real time when data changes ? Maybe I have a node server and I use sockets to see when anyone has bought anything from my shop that I get a notification via nodejs on my backend. is it possible ? a few websites has this, they offers you to sell on their site and you can see real time changes data when anything was bought
Yes, you can subscribe to multiple Webhooks to get notified when a change occurs on your shop. Using the REST Admin API, available webhook event topics include:
orders/create: occurs whenever an order is created / someone buys from your shop.
orders/paid: occurs whenever an order is paid.
orders/fulfilled: occurs whenever an order is fulfilled.
orders/cancelled: occurs whenever an order is cancelled.
Use the /admin/api/2023-01/webhooks.json endpoint to subscribe to a webhook:
// Node.js - Session is built by the OAuth process
const webhook = new shopify.rest.Webhook({session: session});
webhook.topic = "orders/create";
webhook.address = "https://example.hostname.com/";
// format you want to receive the event data in
webhook.format = "json"; // or XML
// fields you want to receive
webhook.fields = [
"id",
"note"
];
await webhook.save({
update: true,
});
You can also use the GraphQL Admin API for the same purpose.

How do I send only one notification to a user in a Database listener in Firebase Functions

The app concept is simple, I track the price of a certain item, and push a notification whenever a users desired price point is hit.
The Price of the item (ActualPrice) is reflected through a Firebase Realtime Database field that is updated ever few seconds.
The users and their requested prices (RequestedPrice), as it stands, is saved in Firestore documents, each with two fields:
Price
FCM Token
The token is an FCM token to push notifications to devices.
In Firebase Cloud Functions, I have a listener that triggers whenever the ActualPrice changes, which is every few seconds, through the .onWrite() function. It then cross compares all the users prices, and pushes notifications only to the ones that have their RequestedPrice met.
The issue is that, this event is triggered frequently, so users that have their prices met keep receiving notifications ever few seconds.
One idea I had is to add a field to users Firestore documents, and update it whenever the user has already received the notification or not yet. The only issue is that you can not alter document fields through Firebase Functions.
If you have any ideas I would very much appreciate them.
Edit:
const UIDRef = db.collection("/Currency/UserIDs");
const snapshot = await UIDRef.where("Price", ">=", RTDPrice).get();
snapshot.forEach(doc => {
const Temp = {
Status: 'Los Angeles',
};
doc.set(Temp);
You will need to maintain the last 'sent' status in each user with their FCM. using a secondary condition, you can query if the date is older than the current threshold.
Once you send a message to that user, you simply update the current timestamp to the database through the admin sdk
Price
FCM token
lastNotified
References:
https://firebase.google.com/docs/functions/firestore-events#writing-triggered_functions
https://firebase.google.com/docs/database/admin/save-data#node.js
https://firebase.google.com/docs/firestore/manage-data/add-data#node.js

Outlook REST API is returning 404 for event in message

I have the following case:
I use the Outlook REST API (without any library) to visualize the users' emails - including Event invites. First, I make a call to get only the message properties and if the message has MeetingMessageType value, then another request is sent to:
https://outlook.office.com/api/v2.0/me/messages/<messageId>?$select=Microsoft.OutlookServices.EventMessage/MeetingMessageType&$expand=Microsoft.OutlookServices.EventMessage/event($select=Id,SeriesMasterId,iCalUID,Type,CreatedDateTime,LastModifiedDateTime,WebLink,Calendar,Start,End,IsAllDay,IsCancelled,Organizer,Attendees,Location,Subject,ResponseStatus,OnlineMeetingUrl,Recurrence,ResponseRequested)
to get the Event information and provide the customer with the option to respond to the invite.
The problem:
Since yesterday one of our clients reported that he can't see the event information. It turns out that the request for getting this information is returning 404.
The response body:
{
"error": {
"code": "ErrorItemNotFound",
"message": "The specified object was not found in the store., The process failed to get the correct properties."
}
}
The event is shown in the Outlook desktop mail client.
The client also shared that they have enabled ATP (advance threat protection) at his company. Not sure if this can have anything to do with the problem.
I see that other clients also have this problem.
Update:
I asked the user to try the following requests from the Outlook sandbox:
https://outlook.office.com/api/v2.0/me/messages/<messageId>
This request returns the EventMessage with "MeetingMessageType": "MeetingRequest".
Then when he tried accessing the Event:
https://outlook.office.com/api/v2.0/me/messages/<messageId>?$select=Microsoft.OutlookServices.EventMessage%2FMeetingMessageType&$expand=Microsoft.OutlookServices.EventMessage%2Fevent
The Outlook REST API returns 404.
For me, the same formatted requests work, so I can't really understand what is going on.
Please, any information will be well appreciated!

Progressive Web Application receiving data to trigger notification

Hello i'm newbie and im hardly to understand this notification in service-worker, and because my knowledge isn't good yet then probably i will unable to explain my problem clearly.
so here's the code :
// triggered everytime, when a push notification is received.
self.addEventListener('push', function(event) {
console.info('Event: Push');
var title = 'New commit on Github Repo: RIL';
var body = {
'body': 'Click to see the latest commit',
'tag': 'pwa',
'icon': './images/48x48.png'
};
event.waitUntil(
self.registration.showNotification(title, body)
);
});
this is the code that trigger to POP the notification, what I do not understand is where the argument to accept/ receive the data ?
I've been searched a lot: https://auth0.com/blog/introduction-to-progressive-web-apps-push-notifications-part-3/ ,
https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web
there's some new data JSON or from git-server or push api, but I still hardly to understand where's to accept the data.
sorry if you still do not understand what's my problem.
Here to make it simple what I want :
Let's say i make a button, and everytime i click the button it will value as 'True' and I want that 'True' value to pass into argument and trigger the push of notication in service-worker.
2nd questions: am I able to trigger notification with header or text in html ? since we can manipulate the text with DOM ?
am I able to trigger notification without GCM, or API cause I just want a simple notification in serivce-worker like above without passing much data.
If you give more advice or maybe notification without service-worker but real time , I am surely happy to read it but I hope Im able to understand.
There are basically two concepts involved that work well together but can be used independently. The first is the visible UI shown to a user that tells them information or prompts them for an action. The second is sending an event from a server to the browser without requiring the user to currently be active on the site. For full details I recommend reading Google's Web Push docs.
Before either of those scenarios you have to request permission from the user. Once permission is granted you can just create a notification. No server or service worker required.
If you want to send events from a server you will need a service worker and you will need to get a subscription for the user. Once you have a subscription you would send it to a server for when you want to send an event to that specific browser instance.
Once you receive a push event from a server you display the UI the same as in the first scenario except you have to do it from the service worker.

Set CustomProperties on appointment for all attendees

tl;dr
When setting CustomProperties to an appointment that has attendees, only the appointment for the organizer gets the CustomProperties. The properties do not propagate to the appointments of the other attendees.
Longer version
When we create an appointment with multiple attendees and then log in as each attendee, we notice that each ItemId is different. So, it appears that each attendee in a meeting gets their own copy of an appointment. (Would really like someone to confirm this is true).
However, when setting a custom property from our add-in (using the Outlook JavaScript API), only the organizer's appointment gets the custom property as we are unable to see the custom property when we log in as any of the other attendees.
Snippets from our code that is relevant:
Office.initialize = function (reason) {
$(document).ready(function () {
Office.context.mailbox.item.loadCustomPropertiesAsync (onCustomPropertiesLoaded);
});
};
function onCustomPropertiesLoaded(asyncResults) {
_customProps = asyncResults.value;
}
//Set custom properties
_customProps.set("myProp", "true");
_customProps.saveAsync(customPropertiesOnSaved);
Is there a way to have each copy of the appointment have the custom property?
When we create an appointment and have multiple attendees and then log in as each attendee, we notice that each ItemId is different. So, it appears that each attendee in a meeting gets their own copy of an appointment. (Would really like someone to confirm this is true).
Yes that's correct an attendees copy of the appointment is a separate new Item in that mailbox. On the back end Exchange server its a separate Mailbox Store Item they are not linked in any way (other then properties that can be used to correlate them) and the server does not update appointments in attendee mailboxes so they must always be updated by a client process (in the case of room mailbox the Mailbox assistant does this but this is still a client process that runs on the server).
However, when setting a custom property from our add-in, only the organizer's appointment gets the custom property as we are unable to see the custom property when we log in as any of the other attendees.
That is most likely happening because you need to first save the custom property on the Appointment before you add any attendees and send meeting invitations. Its important to first save the appointment with the property (or attachments) before you add any attendees, then when the server produces the invites those invites should include the custom property (you can check that is happening using a Mapi editor and looking at the invite being produced in the Sent Items folder of the Organiser). Its important to remember as the appointments aren't linked on the server updating the property on the organiser won't be reflected on the attendees copy unless your sending a Meeting update and that Meeting update is then accepted by the attendees which would then update their calendars.

Resources