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

1.7 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { kapsoAuth } from '../common';
import { makeClient } from '../common';
import { businessAccountIdProp, phoneNumberIdDropdown } from '../common/props';

export const sendAudio = createAction({
  auth: kapsoAuth,
  name: 'send_audio',
  classification: 'WRITE',
  displayName: 'Send Audio',
  description: 'Send an audio message via WhatsApp.',
  audience: 'both',
  aiMetadata: {
    description: 'Sends an audio file to a WhatsApp recipient. Supply the audio either as a public URL or as the media ID of a previously uploaded file (use one or the other). Each call delivers a new message, so it is not idempotent.',
    idempotent: false,
  },
  props: {
    businessAccountId: businessAccountIdProp,
    phoneNumberId: phoneNumberIdDropdown,
    to: Property.ShortText({
      displayName: 'Recipient Phone Number',
      description:
        'The recipient\'s phone number in international format (e.g. 15551234567).',
      required: true,
    }),
    audioUrl: Property.ShortText({
      displayName: 'Audio URL',
      description: 'Public URL of the audio file to send.',
      required: false,
    }),
    audioId: Property.ShortText({
      displayName: 'Audio Media ID',
      description: 'Media ID of a previously uploaded audio. Use either URL or Media ID.',
      required: false,
    }),
  },
  async run(context) {
    const { phoneNumberId, to, audioUrl, audioId } = context.propsValue;
    const client = makeClient(context.auth.secret_text);

    const response = await client.messages.sendAudio({
      phoneNumberId,
      to,
      audio: {
        link: audioUrl ?? undefined,
        id: audioId ?? undefined,
      },
    });

    return response;
  },
});