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 { createTrigger, TriggerStrategy, AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common';
import { bexioAuth } from '../auth';
import { BexioClient } from '../common/client';
import dayjs from 'dayjs';
const polling: Polling<
AppConnectionValueForAuthProperty<typeof bexioAuth>,
Record<string, never>
> = {
strategy: DedupeStrategy.TIMEBASED,
items: async ({ auth, lastFetchEpochMS }) => {
const client = new BexioClient(auth);
const isTest = lastFetchEpochMS === 0;
const lastFetchDate = isTest
? dayjs().subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss')
: dayjs(lastFetchEpochMS).format('YYYY-MM-DD HH:mm:ss');
const searchBody = [
{
field: 'contact_type_id',
value: '2', // 2 = person
criteria: '=',
},
{
field: 'updated_at',
value: lastFetchDate,
criteria: '>=',
},
];
const queryParams: Record<string, string> = {
order_by: 'updated_at_desc',
limit: isTest ? '5' : '500',
};
const persons = await client.post<Array<{
id: number;
nr?: string | null;
contact_type_id: number;
name_1: string;
name_2?: string | null;
salutation_id?: number | null;
salutation_form?: string | null;
title_id?: number | null;
birthday?: string | null;
address?: string | null;
street_name?: string | null;
house_number?: string | null;
address_addition?: string | null;
postcode?: string | null;
city?: string | null;
country_id?: number | null;
mail?: string | null;
mail_second?: string | null;
phone_fixed?: string | null;
phone_fixed_second?: string | null;
phone_mobile?: string | null;
fax?: string | null;
url?: string | null;
skype_name?: string | null;
remarks?: string | null;
language_id?: number | null;
is_lead?: boolean;
contact_group_ids?: string | null;
contact_branch_ids?: string | null;
user_id?: number;
owner_id?: number;
updated_at?: string;
}>>('/2.0/contact/search', searchBody, queryParams);
return persons.map((person) => {
const updatedAt = person.updated_at || new Date().toISOString();
const epochMilliSeconds = dayjs(updatedAt).valueOf();
return {
epochMilliSeconds,
data: person,
};
});
},
};
export const newUpdatedPersonTrigger = createTrigger({
auth: bexioAuth,
name: 'new_updated_person',
classification: 'READ',
displayName: 'New/Updated Person',
description: 'Triggers when a person is added or updated',
aiMetadata: {
description: 'Fires when a person contact is created or its updated timestamp changes in Bexio. Emits each matching person with their name, address, contact details (email, phone), birthday, group memberships, and lead status. Use to react to new or modified individual contacts.',
},
type: TriggerStrategy.POLLING,
props: {},
sampleData: {
id: 4,
nr: null,
contact_type_id: 2,
name_1: 'John',
name_2: 'Doe',
salutation_id: 1,
salutation_form: null,
title_id: null,
birthday: '1990-01-01',
address: 'Smith Street 22',
street_name: 'Smith Street',
house_number: '77',
address_addition: 'Building C',
postcode: '8004',
city: 'Zurich',
country_id: 1,
mail: '[email protected]',
mail_second: '',
phone_fixed: '',
phone_fixed_second: '',
phone_mobile: '',
fax: '',
url: '',
skype_name: '',
remarks: '',
language_id: null,
is_lead: false,
contact_group_ids: '1,2',
contact_branch_ids: null,
user_id: 1,
owner_id: 1,
updated_at: '2019-04-08 13:17:32',
},
onEnable: async (context) => {
await pollingHelper.onEnable(polling, context);
},
onDisable: async (context) => {
await pollingHelper.onDisable(polling, context);
},
test: async (context) => {
return await pollingHelper.test(polling, context);
},
run: async (context) => {
return await pollingHelper.poll(polling, context);
},
});