Polling Triggers

Polling triggers allow you to poll for new events by periodically fetching records and comparing them with previously fetched records.

Example#

async function fetchAllUsers() {
// fetch and return list of all Users from oldest to newest
// this should be an array of objects with `id` property
}
const allUsers = await fetchAllUsers();
// compute new id snapshot
const newIdSnapshot = new Set(allUsers.map((a) => a.id));
// determine new Users added since previous snapshot
const newUserIds = utils.diffIdSnapshot(newIdSnapshot, context.prevIdSnapshot);
// events is an array of objects of the Trigger Payload shape
const events = allUsers
.filter((a) => newUserIds.has(a.id))
.map((a) => utils.flattenTriggerPayload(a));
return {
newIdSnapshot,
events,
};

Polling execution context#

ClaimTypeDescription
prevIdSnapshotSet<string>The set of polled IDs returned from previous poll
authDataobjectThe object holding the auth data from JWT / OAuth

Polling execution return value#

ClaimTypeDescription
nextIdSnapshotSet<string>The set of polled IDs in this poll
eventsobject[]An array of new events - objects of the Trigger Payload shape.