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.9 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { productboardAuth } from '../common/auth';
import { productboardCommon } from '../common/client';

/**
 * Action to create a new note/feedback in Productboard.
 */
export const createNote = createAction({
    name: 'create_note',
    displayName: 'Create Note',
    description: 'Creates a new note in Productboard',
    audience: 'both',
    aiMetadata: { description: 'Creates a new feedback note in Productboard from a title and HTML content, optionally attaching it to a user (by email) or a company (by domain) — these two attachments are mutually exclusive — plus optional source/display-url metadata and tags. Use to capture customer feedback or external input into the inbox. Not idempotent: each call creates a separate note.', idempotent: false },
    auth: productboardAuth,
    props: {
        title: Property.ShortText({
            displayName: 'Note Title',
            description: 'Title of the feedback note',
            required: true,
        }),
        content: Property.LongText({
            displayName: 'Content',
            description: 'HTML-encoded rich text content of the feedback note',
            required: true,
        }),
        user_email: Property.ShortText({
            displayName: 'User Email',
            description: "Email address of a user to be attached to the note. This field can't be combined with `Company Domain`.",
            required: false,
        }),
        company_domain: Property.ShortText({
            displayName: 'Company Domain',
            description: "Domain of a company the note should be linked to. This field can't be combined with `User Email`.",
            required: false,
        }),
        display_url: Property.ShortText({
            displayName: 'Display URL',
            description: 'URL where the external entity can be accessed.',
            required: false,
        }),
        source_origin: Property.ShortText({
            displayName: 'Source Origin',
            description: 'A unique string identifying the external system from which the data came.',
            required: false,
        }),
        source_record_id: Property.ShortText({
            displayName: 'Source Record ID',
            description: 'The unique id of the record in the origin system.',
            required: false,
        }),
        tags: Property.Array({
            displayName: 'Tags',
            description: 'A set of tags for categorizing the note.',
            required: false,
            properties: {
                tag: Property.ShortText({
                    displayName: 'Tag',
                    required: true,
                }),
            },
        }),
    },
    async run(context) {
        const {
            title,
            content,
            user_email,
            company_domain,
            display_url,
            source_origin,
            source_record_id,
            tags,
        } = context.propsValue;

        const noteBody: Record<string, any> = {
            title,
            content,
        };

        if (user_email) {
            noteBody['user'] = { email: user_email };
        }

        if (company_domain) {
            noteBody['company'] = { domain: company_domain };
        }

        if (display_url) {
            noteBody['display_url'] = display_url;
        }

        if (source_origin && source_record_id) {
            noteBody['source'] = {
                origin: source_origin,
                record_id: source_record_id,
            };
        }

        if (tags) {
            noteBody['tags'] = (tags as { tag: string }[]).map((t) => t.tag);
        }

        const response = await productboardCommon.apiCall({
            auth: context.auth,
            method: HttpMethod.POST,
            resourceUri: '/notes',
            body: noteBody,
        });

        return response.body;
    },
});