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.7 KB
Raw Blame
import { intercomAuth } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { intercomClient } from '../common';
import dayjs from 'dayjs';
import { contactOutputSchema } from '../output-schemas';

export const createUserAction = createAction({
	auth: intercomAuth,
	name: 'create-user',
	classification: 'WRITE',
	displayName: 'Create User',
	description: 'Creates a new user.',
	audience: 'both',
	aiMetadata: { description: 'Create a new user-role contact in Intercom from email and optional name, external user ID, signup time, and custom attributes. Always creates a record and does not check for an existing match, so it is not idempotent and repeated calls may produce duplicates. To update-if-exists instead, use Create/Update User.', idempotent: false },
	props: {
		email: Property.ShortText({
			displayName: 'Email',
			required: true,
		}),
		createdAt: Property.DateTime({
			displayName: 'Created At',
			required: false,
		}),
		userId: Property.ShortText({
			displayName: 'User ID',
			required: false,
		}),
		name: Property.ShortText({
			displayName: 'Full Name',
			required: false,
		}),
		customAttributes: Property.Object({
			displayName: 'Custom Attributes',
			required: false,
		}),
	},
	outputSchema: contactOutputSchema,
	async run(context) {
		const client = await intercomClient(context.auth);

		const response = await client.contacts.create({
			role: 'user',
			email: context.propsValue.email,
			name: context.propsValue.name,
			custom_attributes: context.propsValue.customAttributes,
			signed_up_at: context.propsValue.createdAt
				? dayjs(context.propsValue.createdAt).unix()
				: undefined,
			external_id: context.propsValue.userId,
		});

		return response;
	},
});