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.9 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 sendVideo = createAction({
  auth: kapsoAuth,
  name: 'send_video',
  classification: 'WRITE',
  displayName: 'Send Video',
  description: 'Send a video message via WhatsApp.',
  audience: 'both',
  aiMetadata: {
    description: 'Sends a video to a WhatsApp recipient, optionally with a caption. Supply the video 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,
    }),
    videoUrl: Property.ShortText({
      displayName: 'Video URL',
      description: 'Public URL of the video to send.',
      required: false,
    }),
    videoId: Property.ShortText({
      displayName: 'Video Media ID',
      description: 'Media ID of a previously uploaded video. Use either URL or Media ID.',
      required: false,
    }),
    caption: Property.LongText({
      displayName: 'Caption',
      description: 'Optional caption for the video.',
      required: false,
    }),
  },
  async run(context) {
    const { phoneNumberId, to, videoUrl, videoId, caption } = context.propsValue;
    const client = makeClient(context.auth.secret_text);

    const response = await client.messages.sendVideo({
      phoneNumberId,
      to,
      video: {
        link: videoUrl ?? undefined,
        id: videoId ?? undefined,
        caption: caption ?? undefined,
      },
    });

    return response;
  },
});