AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { createAction, Property } from '@activepieces/pieces-framework';
import { PageCollection } from '@microsoft/microsoft-graph-client';
import { Message } from '@microsoft/microsoft-graph-types';
import { microsoftOutlookAuth } from '../common/auth';
import { outlookAtomicCommon } from '../common/atomic-common';
import { outlookCommon } from '../common/client';
import { outlookListMessagesDeltaActionOutputSchema } from '../output-schemas';
export const outlookListMessagesDeltaAction = createAction({
auth: microsoftOutlookAuth,
name: 'outlook_list_messages_delta',
classification: 'SEARCH',
displayName: 'List Message Changes (Delta)',
description: 'Tracks created, updated and deleted messages in a folder.',
audience: 'ai',
aiMetadata: {
description:
'Returns the messages added, changed or removed in one mail folder since a previous delta link, plus a fresh delta link for the next call. Use this for incremental sync instead of re-listing a folder; a first call without a delta link returns the current contents. The delta link must be one this action returned on the same connection: any other URL is rejected instead of being followed. Each change carries a removed flag: when it is true the item was deleted and only its id and removedReason are meaningful. Delta payloads omit message bodies and attachments, so follow up with Get Message for full content. Read-only and safe to retry.',
idempotent: true,
},
props: {
folderId: Property.ShortText({
displayName: 'Folder ID',
description: `Folder to track. ${outlookAtomicCommon.wellKnownFolderHint}`,
required: true,
defaultValue: 'inbox',
}),
deltaLink: Property.ShortText({
displayName: 'Delta Link',
description: `The deltaLink returned by a previous run. Leave empty to start a new sync from the current folder state. ${outlookAtomicCommon.deltaLinkHint}`,
required: false,
}),
},
outputSchema: outlookListMessagesDeltaActionOutputSchema,
async run(context) {
const { folderId, deltaLink } = context.propsValue;
const client = outlookCommon.createClient(context.auth);
const prefix = outlookCommon.mailboxPrefix(context.auth);
const operation = 'Listing Outlook message changes';
const url = deltaLink
? outlookAtomicCommon.resolveDeltaUrl({
auth: context.auth,
deltaLink,
expectedPath: `${prefix}/mailFolders/*/messages/delta`,
operation,
})
: `${prefix}/mailFolders/${outlookAtomicCommon.encodeGraphId(folderId)}/messages/delta?$select=${outlookAtomicCommon.messageSelect}`;
try {
const response: PageCollection = await client
.api(url)
.headers({ Prefer: 'odata.maxpagesize=50' })
.get();
const changes = ((response.value ?? []) as Message[]).map((change) =>
outlookAtomicCommon.withDeltaRemoval(change),
);
const nextLink = response['@odata.nextLink'] as string | undefined;
const nextDeltaLink = response['@odata.deltaLink'] as string | undefined;
return {
changes,
count: changes.length,
hasMore: !!nextLink,
nextLink: nextLink ?? null,
deltaLink: nextDeltaLink ?? null,
};
} catch (error) {
throw outlookAtomicCommon.graphError({ error, operation });
}
},
});