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

3.6 KB
Raw Blame
import { intercomAuth } from '../auth';
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { intercomClient, TriggerPayload } from '../common';
import { contactTriggerOutputSchema } from '../output-schemas';

export const newUserTrigger = createTrigger({
	auth: intercomAuth,
	name: 'new-user',
	classification: 'READ',
	displayName: 'New User',
	description: 'Triggers when a new user is created.',
	aiMetadata: {
		description: 'Fires when a new user is created in Intercom. A user is an identified, signed-up contact (role "user"), as opposed to a lead. Outputs the newly created user contact object with its attributes.',
	},
	props: {},
	outputSchema: contactTriggerOutputSchema,
	type: TriggerStrategy.APP_WEBHOOK,
	async onEnable(context) {
		const client = await intercomClient(context.auth);
		const response = await client.admins.identify();

		if (!response.app?.id_code) {
			throw new Error('Could not find admin id code');
		}

		context.app.createListeners({
			events: ['contact.user.created'],
			identifierValue: response['app']['id_code'],
		});
	},
	async onDisable() {
		return;
	},
	async test(context) {
		const client = await intercomClient(context.auth);

		const response = await client.contacts.search({
			query: {
				field: 'role',
				operator: '=',
				value: 'user',
			},
			pagination: { per_page: 5 },
		});

		return response.data;
	},
	async run(context) {
		const payload = context.payload.body as TriggerPayload;
		return [payload.data.item];
	},
	sampleData: {
		type: 'contact',
		id: '67a9b9dfcc14109e073fbe19',
		workspace_id: 'nzekhfwb',
		external_id: '5b803f65-bcec-4198-b4f4-a0588454b537',
		role: 'user',
		email: '[email protected]',
		phone: null,
		name: 'John Doe',
		avatar: null,
		owner_id: null,
		social_profiles: {
			type: 'list',
			data: [],
		},
		has_hard_bounced: false,
		marked_email_as_spam: false,
		unsubscribed_from_emails: false,
		created_at: '2025-02-10T08:33:35.910+00:00',
		updated_at: '2025-02-10T08:33:35.907+00:00',
		signed_up_at: null,
		last_seen_at: null,
		last_replied_at: null,
		last_contacted_at: null,
		last_email_opened_at: null,
		last_email_clicked_at: null,
		language_override: null,
		browser: null,
		browser_version: null,
		browser_language: null,
		os: null,
		location: {
			type: 'location',
			country: null,
			region: null,
			city: null,
			country_code: null,
			continent_code: null,
		},
		android_app_name: null,
		android_app_version: null,
		android_device: null,
		android_os_version: null,
		android_sdk_version: null,
		android_last_seen_at: null,
		ios_app_name: null,
		ios_app_version: null,
		ios_device: null,
		ios_os_version: null,
		ios_sdk_version: null,
		ios_last_seen_at: null,
		custom_attributes: {},
		tags: {
			type: 'list',
			data: [],
			url: '/contacts/67a9b9dfcc14109e073fbe19/tags',
			total_count: 0,
			has_more: false,
		},
		notes: {
			type: 'list',
			data: [],
			url: '/contacts/67a9b9dfcc14109e073fbe19/notes',
			total_count: 0,
			has_more: false,
		},
		companies: {
			type: 'list',
			data: [],
			url: '/contacts/67a9b9dfcc14109e073fbe19/companies',
			total_count: 0,
			has_more: false,
		},
		opted_out_subscription_types: {
			type: 'list',
			data: [],
			url: '/contacts/67a9b9dfcc14109e073fbe19/subscriptions',
			total_count: 0,
			has_more: false,
		},
		opted_in_subscription_types: {
			type: 'list',
			data: [],
			url: '/contacts/67a9b9dfcc14109e073fbe19/subscriptions',
			total_count: 0,
			has_more: false,
		},
		utm_campaign: null,
		utm_content: null,
		utm_medium: null,
		utm_source: null,
		utm_term: null,
		referrer: null,
		sms_consent: false,
		unsubscribed_from_sms: false,
		enabled_push_messaging: null,
	},
});