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 { addGreet, addProfile } from '../api';
import { bonjoroAuth, BonjoroAuthType } from '../auth';
import {
  buildCampaignDropdown,
  buildTemplateDropdown,
  buildUserDropdown,
} from '../props';

export const addGreetAction = createAction({
  name: 'add_greet',
  classification: 'WRITE',
  auth: bonjoroAuth,
  displayName: 'Create a Greet',
  description: 'Create a new Greet in Bonjoro',
  audience: 'both',
  aiMetadata: { description: 'Creates a personal-video Greet task in Bonjoro for a recipient identified by email (upserting their profile first), with a note and optional assignee, campaign, and message template. Use to queue a new outreach video for a customer. Not idempotent: each call creates a new Greet, so repeating it produces duplicates.', idempotent: false },
  props: {
    note: Property.LongText({
      displayName: 'Note',
      description: 'Note to send with the greet',
      required: true,
    }),
    email: Property.ShortText({
      displayName: 'Email',
      description: 'Email to send the greet to',
      required: true,
    }),
    first: Property.ShortText({
      displayName: 'First Name',
      description: 'First name of the person to greet',
      required: false,
    }),
    last: Property.ShortText({
      displayName: 'Last Name',
      description: 'Last name of the person to greet',
      required: false,
    }),
    assignee: Property.Dropdown({
      auth: bonjoroAuth,
      displayName: 'Assignee',
      description: 'Who to assign the greet to',
      required: false,
      refreshers: [],
      options: async ({ auth }) =>
        {
        if (!auth) {
          return {
            disabled: true,
            options: [],
            placeholder: 'Please connect your Bonjoro account first',
          };
        }
        return await buildUserDropdown(auth.props);
        }
    }),
    campaign: Property.Dropdown({
      auth: bonjoroAuth,
      displayName: 'Campaign',
      description: 'The campaign to add the greet to',
      required: false,
      refreshers: [],
      options: async ({ auth }) =>
        {
          if (!auth) {
            return {
              disabled: true,
              options: [],
              placeholder: 'Please connect your Bonjoro account first',
            };
          }
          return await buildCampaignDropdown(auth.props);
        }
    }),
    template: Property.Dropdown({
      auth: bonjoroAuth,
      displayName: 'Template',
      description: 'The template to use for the greet',
      required: false,
      refreshers: [],
      options: async ({ auth }) =>
        {
          if (!auth) {
            return {
              disabled: true,
              options: [],
              placeholder: 'Please connect your Bonjoro account first',
            };
          }
          return  await buildTemplateDropdown(auth.props);
        }
    }),
    custom: Property.Json({
      displayName: 'Custom Attributes',
      description: 'Enter custom attributes to send with the greet',
      required: false,
      defaultValue: {},
    }),
  },
  async run(context) {
    const user = {
      email: context.propsValue.email,
      first_name: context.propsValue.first,
      last_name: context.propsValue.last,
    };
    addProfile(context.auth.props, user);

    const greet = {
      profiles: [context.propsValue.email],
      note: context.propsValue.note,
      assignee_id: context.propsValue.assignee,
      campaign_id: context.propsValue.campaign,
      template_id: context.propsValue.template,
      custom_attributes: context.propsValue.custom,
    };

    if (!greet.assignee_id) delete greet.assignee_id;
    if (!greet.campaign_id) delete greet.campaign_id;
    if (!greet.template_id) delete greet.template_id;
    if (!greet.custom_attributes) delete greet.custom_attributes;

    return await addGreet(context.auth.props, greet);
  },
});