Skip to content

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

1.9 KB
Raw Blame
import { activeCampaignAuth } from '../auth';
import { TriggerStrategy, createTrigger } from '@activepieces/pieces-framework';
import { makeClient } from '../common';
import { CreateWebhookResponse } from '../common/types';
import { WEBHOOK_SOURCES } from '../common/constants';

export const updatedContactTrigger = createTrigger({
	auth: activeCampaignAuth,
	name: 'activecampaign_updated_contact',
	classification: 'READ',
	displayName: 'Updated Contact',
	description: 'Triggers when an existing contact details are updated.',
	aiMetadata: {
		description: 'Fires when an existing contact\'s details are updated. The payload contains the updated contact record including its current field values and tags.',
	},
	type: TriggerStrategy.WEBHOOK,
	props: {},
	async onEnable(context) {
		const client = makeClient(context.auth.props);
		const res = await client.subscribeWebhook({
			name: `Activepieces Updated Contact Hook`,
			url: context.webhookUrl,
			events: ['update'],
			sources: WEBHOOK_SOURCES,
		});
		await context.store.put<CreateWebhookResponse>('activecampaign_updated_contact', res);
	},
	async run(context) {
		return [context.payload.body];
	},
	async onDisable(context) {
		const webhook = await context.store.get<CreateWebhookResponse>(
			'activecampaign_updated_contact',
		);
		if (webhook != null) {
			const client = makeClient(context.auth.props);
			await client.unsubscribeWebhook(webhook.webhook.id);
		}
	},
	sampleData: {
		type: 'update',
		date_time: '2024-02-28T07:16:48-06:00',
		initiated_from: 'admin',
		initiated_by: 'admin',
		list: '0',
		contact: {
			id: '3',
			email: '[email protected]',
			first_name: 'John',
			last_name: 'Wick',
			phone: '',
			ip: '0.0.0.0',
			tags: 'tag1, tag2',
			fields: ['Option 1', '||Option 1||Option 2||'],
			customer_acct_name: '',
			orgname: '',
		},
		customer_acct_name: '',
		customer_acct_id: '0',
		orgname: '',
	},
});