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

2.0 KB
Raw Blame
import { intercomAuth } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { commonProps, intercomClient } from '../common';
import { collectionIdProp } from '../common/props';
import { articleOutputSchema } from '../output-schemas';

export const createArticleAction = createAction({
	auth: intercomAuth,
	name: 'create-article',
	classification: 'WRITE',
	displayName: 'Create Article',
	description: 'Creates a new article in your Help Center.',
	audience: 'human',
	aiMetadata: { description: 'Create a new Help Center article with title, optional description and body, an author admin, and a draft or published state, optionally nested under a parent collection. Always creates a new article, so it is not idempotent and repeated calls produce duplicates.', idempotent: false },
	props: {
		title: Property.LongText({
			displayName: 'Title',
			required: true,
		}),
		description: Property.ShortText({
			displayName: 'Description',
			required: false,
		}),
		body: Property.LongText({
			displayName: 'Body',
			required: false,
		}),
		authorId: commonProps.admins({ displayName: 'Author', required: true }),
		state: Property.StaticDropdown({
			displayName: 'State',
			required: true,
			defaultValue: 'draft',
			options: {
				disabled: false,
				options: [
					{ label: 'Draft', value: 'draft' },
					{ label: 'Published', value: 'published' },
				],
			},
		}),
		collectionId: collectionIdProp('Parent Collection', false),
	},
	outputSchema: articleOutputSchema,
	async run(context) {
		const { authorId, collectionId, title, description, body, state } = context.propsValue;

		if (!authorId) {
			throw new Error('Author is required');
		}

		const client = await intercomClient(context.auth);

		const response = await client.articles.create({
			title,
			description,
			body,
			author_id: Number(authorId),
			state: state as 'published' | 'draft',
			parent_id: collectionId ? Number(collectionId) : undefined,
		});

		return response;
	},
});