4D-NetKit

GraphNotification Class

Overview

GraphNotification manages Microsoft Graph change notifications for mail messages or calendar events. It supports two modes:

A GraphNotification object is obtained by calling .notifier() on an Office365Calendar object, or .notifier() on an Office365Mail object. Call start() to begin monitoring and stop() to end it.

Callbacks (onCreate, onDelete, onModify) are dispatched in the 4D worker where .start() was originally called. The subscription is automatically closed when the notifier object is destroyed.

Table of Contents

Functions

Properties

A GraphNotification object exposes the following properties:

Property Type Description
endPoint Text (read-only) Webhook URL configured at construction. Empty string in pull mode.
expiration Text (read-only) ISO 8601 expiration date/time of the current Graph subscription. Empty string in pull mode or before start() is called.
isStarted Boolean (read-only) true when monitoring is active.
timer Integer (read-only) Pull polling interval in seconds (default: 30; pull mode only).

Functions

.start()

.start() : Object

Parameters

Parameter Type   Description
Result Object <- Status object with success (Boolean), statusText (Text), and errors (Collection).

Description

.start() activates change notifications.

No-op when already started.

.stop()

.stop() : Object

Parameters

Parameter Type   Description
Result Object <- Status object with success (Boolean), statusText (Text), and errors (Collection).

Description

.stop() stops change notifications.

No-op when not started.

Example

Calendar notifications via delta polling every 60 seconds (pull mode):

$calNotif:=$office365.calendar.notifier({ \
    timer: 60; \
    onCreate: Formula(handleNewEvent($1; $2)); \
    onModify: Formula(handleEventUpdate($1; $2)) \
})
$status:=$calNotif.start()

// Stop monitoring
$status:=$calNotif.stop()

Mail notifications via webhook (push mode):

var $notif:=$office365.mail.notifier({ \
    endPoint: "https://myserver.com"; \
    onCreate: Formula(ALERT("New mail: "+String($2.ids))); \
    onDelete: Formula(ALERT("Mail deleted: "+String($2.ids))) \
})
$status:=$notif.start()

See also