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.3 KB
Raw Blame
import { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { streakAuth } from '../common/auth';
import { streakApiCall } from '../common/client';
import { flattenStreakBox } from '../common/flatten';
import { pipelineDropdown, stageDropdown } from '../common/props';
import { StreakBox } from '../common/types';

export const createBoxAction = createAction({
  auth: streakAuth,
  name: 'create_box',
  classification: 'WRITE',
  displayName: 'Create Box',
  description: 'Create a new box (record) in a pipeline.',
  audience: 'both',
  aiMetadata: {
    description:
      'Create a new box (Streak\'s CRM record, e.g. a deal, lead, or candidate) inside a pipeline. Use when an agent needs to add a new record to a Streak pipeline; requires the target pipeline and a name, with optional starting stage, notes, and assignee emails. Not idempotent: each call creates another box even with identical inputs.',
    idempotent: false,
  },
  props: {
    pipelineKey: pipelineDropdown,
    name: Property.ShortText({
      displayName: 'Name',
      description:
        'The display name for this box (e.g. the deal name or the candidate name).',
      required: true,
    }),
    stageKey: stageDropdown,
    notes: Property.LongText({
      displayName: 'Notes',
      description: 'Free-form notes attached to the box.',
      required: false,
    }),
    assignedToEmails: Property.Array({
      displayName: 'Assigned To (Emails)',
      description:
        'Email addresses of Streak users to assign to this box. Leave empty for no assignees.',
      required: false,
    }),
  },
  async run(context) {
    const { pipelineKey, name, stageKey, notes, assignedToEmails } =
      context.propsValue;

    const body: Record<string, unknown> = { name };
    if (stageKey) body['stageKey'] = stageKey;
    if (notes) body['notes'] = notes;
    if (assignedToEmails && assignedToEmails.length > 0) {
      body['assignedToSharingEntries'] = (assignedToEmails as string[]).map(
        (email) => ({ email }),
      );
    }

    const response = await streakApiCall<StreakBox>({
      apiKey: context.auth.secret_text,
      method: HttpMethod.POST,
      path: `/api/v2/pipelines/${pipelineKey}/boxes`,
      contentType: 'application/json',
      body,
    });

    return flattenStreakBox(response.body);
  },
});