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.1 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { frontAuth } from '../common/auth';
import { makeRequest } from '../common/client';
import { HttpMethod } from '@activepieces/pieces-common';
import { contactIdDropdown } from '../common/dropdown';

export const addContactHandle = createAction({
  auth: frontAuth,
  name: 'addContactHandle',
  displayName: 'Add Contact Handle',
  description:
    'Add a handle (email, phone number, etc.) to an existing Contact.',
  audience: 'both',
  aiMetadata: {
    description:
      'Add one additional handle (email, phone, social, or custom) of a chosen type to an existing Front contact identified by contact ID. Use to register a new address for someone already in the address book; to create a brand-new contact use "Create Contact". Not idempotent: re-adding the same handle may error or duplicate.',
    idempotent: false,
  },
  props: {
    contact_id: contactIdDropdown,
    handle_type: Property.StaticDropdown({
      displayName: 'Handle Type',
      description: 'Type of handle to add.',
      required: true,
      options: {
        options: [
          { label: 'Email', value: 'email' },
          { label: 'Phone', value: 'phone' },
          { label: 'Twitter', value: 'twitter' },
          { label: 'Facebook', value: 'facebook' },
          { label: 'Intercom', value: 'intercom' },
          { label: 'front_chat', value: 'front_chat' },
          { label: 'custom', value: 'custom' },
        ],
      },
    }),
    handle_value: Property.ShortText({
      displayName: 'Handle Value',
      description:
        'The value of the handle (e.g., email address, phone number).',
      required: true,
    }),
  },
  async run({ auth, propsValue }) {
    const { contact_id, handle_type, handle_value } = propsValue;
    const path = `/contacts/${contact_id}/handles`;
    const body = {
      source: handle_type,
      handle: handle_value,
    };

    await makeRequest(auth, HttpMethod.POST, path, body);
    return {
      success: true,
      message: `Handle added successfully to ${contact_id}`,
    };
  },
});