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.8 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { autocallsAuth } from '../..';
import { baseApiUrl } from '../..';

export const makePhoneCall = createAction({
  auth:autocallsAuth,
  name: 'makePhoneCall',
  classification: 'WRITE',
  displayName: 'Make Phone Call',
  description: "Call a customer by it's phone number using an assistant from our platform.",
  audience: 'both',
  aiMetadata: { description: 'Places an outbound AI phone call to a single customer phone number using a selected Autocalls outbound assistant, passing template variables (e.g. customer_name) into the conversation. Use to dial one contact on demand rather than enrolling them in a campaign. Requires a valid outbound assistant id and a phone number; each call dials again, so it is not idempotent.', idempotent: false },
  props: {
    assistant: Property.Dropdown({
      auth: autocallsAuth,
      displayName: 'Assistant',
      description: 'Select an assistant',
      required: true,
      refreshers: ['auth'],
      refreshOnSearch: false,
      options: async ({ auth }) => {
        const res = await httpClient.sendRequest({
          method: HttpMethod.GET,
          url: baseApiUrl + 'api/user/assistants/outbound',
          headers: {
            Authorization: "Bearer " + auth?.secret_text,
          },
        });

        if (res.status !== 200) {
          return {
            disabled: true,
            placeholder: 'Error fetching assistants',
            options: [],
          };
        } else if (res.body.length === 0) {
          return {
            disabled: true,
            placeholder: 'No outbound assistants found. Create one first.',
            options: [],
          };
        }

        return {
          options: res.body.map((assistant: any) => ({
            value: assistant.id,
            label: assistant.name,
          })),
        };
      }
    }),
    phone_number: Property.ShortText({
      displayName: 'Customer phone number',
      description: 'Enter the phone number of the customer',
      required: true,
    }),

    variables: Property.Object({
      displayName: 'Variables',
      description: 'Variables to pass to the assistant',
      required: true,
      defaultValue: {
        customer_name: 'John',
      }
    })
  },
  async run(context) {
    const res = await httpClient.sendRequest<string[]>({
      method: HttpMethod.POST,
      url: baseApiUrl + 'api/user/make_call',
      body: {
        assistant_id: context.propsValue['assistant'],
        phone_number: context.propsValue['phone_number'],
        variables: context.propsValue['variables'],
      },
      headers: {
        Authorization: "Bearer " + context.auth.secret_text,
      },
    });
    return res.body;
  },
});