Skip to main content
Glama
new-parsed-document-found.ts2.97 kB
import { DedupeStrategy, Polling, pollingHelper, } from '@activepieces/pieces-common'; import { AppConnectionValueForAuthProperty, TriggerStrategy, createTrigger, } from '@activepieces/pieces-framework'; import { HttpMethod, httpClient } from '@activepieces/pieces-common'; import { flowParserAuth } from '../common/auth'; import dayjs from 'dayjs'; const BASE_URL = 'https://api.flowparser.one/v1'; const polling: Polling<AppConnectionValueForAuthProperty<typeof flowParserAuth>, Record<string, never>> = { strategy: DedupeStrategy.TIMEBASED, items: async ({ auth, lastFetchEpochMS }) => { try { const queryParams: Record<string, string> = { status: 'parsed', }; if (lastFetchEpochMS) { queryParams['since'] = new Date(lastFetchEpochMS).toISOString(); } const response = await httpClient.sendRequest< Array<{ id: string; status: string; [key: string]: any; }> >({ method: HttpMethod.GET, url: `${BASE_URL}/documents/status-changes`, headers: { flow_api_key: auth.secret_text, }, queryParams, }); const statusChanges = Array.isArray(response.body) ? response.body : []; // Filter to only include parsed status changes const parsedDocuments = statusChanges.filter( (doc) => doc.status === 'parsed' ); return parsedDocuments.map((doc) => { // Use the status change timestamp or current time as fallback const timestamp = doc['updatedAt'] || doc['createdAt'] || new Date().toISOString(); return { epochMilliSeconds: dayjs(timestamp).valueOf(), data: doc, }; }); } catch (error: any) { console.error('Error fetching parsed documents:', error); return []; } }, }; export const newParsedDocumentFound = createTrigger({ auth: flowParserAuth, name: 'new_parsed_document_found', displayName: 'New Parsed Document Found', description: 'Triggers when a document has been successfully parsed', props: {}, sampleData: { id: 'uuid', documentId: 'uuid', templateId: 'uuid', createdAt: '2024-01-01T00:00:00Z', parsedAt: '2024-01-01T00:00:00Z', status: 'parsed', }, type: TriggerStrategy.POLLING, async test(context) { const { store, auth, propsValue, files } = context; return await pollingHelper.test(polling, { store, auth, propsValue, files }); }, async onEnable(context) { const { store, auth, propsValue } = context; await pollingHelper.onEnable(polling, { store, auth, propsValue }); }, async onDisable(context) { const { store, auth, propsValue } = context; await pollingHelper.onDisable(polling, { store, auth, propsValue }); }, async run(context) { const { store, auth, propsValue, files } = context; return await pollingHelper.poll(polling, { store, auth, propsValue, files }); }, });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/activepieces/activepieces'

If you have feedback or need assistance with the MCP directory API, please join our Discord server