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.4 KB
Raw Blame
import { Property } from '@activepieces/pieces-framework';
import { timelinesAiAuth, timelinesAiCommon } from '.';

export const chatDropdown = ({
  description = 'Select the chat to send the message to',
  required = true,
}: {
  description?: string;
  required?: boolean;
}) =>
  Property.Dropdown({
   auth: timelinesAiAuth,
    displayName: 'Chat',
    description: description,
    required,
    refreshers: ['auth'],
    refreshOnSearch: true,
    options: async ({ auth: apiKey }, { searchValue }) => {
      if (!apiKey) {
        return {
          disabled: true,
          placeholder: 'Please select an authentication first',
          options: [],
        };
      }
      const response = await timelinesAiCommon.getChats({
        apiKey:   apiKey,


        name: searchValue,
      });
      const { chats } = response.data;
      return {
        options: chats.map((chat) => ({
          label: chat.name,
          value: chat.id,
        })),
      };
    },
  });

export const whatsappAccountDropdown = ({ required = true }) =>
  Property.Dropdown({
   auth: timelinesAiAuth,
    displayName: 'WhatsApp Account',
    description: 'Select the WhatsApp account',
    required,
    refreshers: ['auth'],
    options: async ({ auth: apiKey }) => {
      if (!apiKey) {
        return {
          disabled: true,
          placeholder: 'Please select an authentication first',
          options: [],
        };
      }
      const response = await timelinesAiCommon.listWhatsappAccounts({
        apiKey:   apiKey,


      });
      const accounts = response.data;
      return {
        options: accounts.whatsapp_accounts.map((account) => ({
          label: account.account_name,
          value: account.id,
        })),
      };
    },
  });

export const fileDropdown = ({ required = true }) =>
  Property.Dropdown({
   auth: timelinesAiAuth,
    displayName: 'Uploaded File',
    description: 'Select the uploaded file',
    required,
    refreshers: ['auth'],
    options: async ({ auth: apiKey }) => {
      if (!apiKey) {
        return {
          disabled: true,
          placeholder: 'Please select an authentication first',
          options: [],
        };
      }
      const response = await timelinesAiCommon.listUploadedFiles({
        apiKey:   apiKey,


      });
      const files = response.data;
      return {
        options: files.map((file) => ({
          label: file.filename,
          value: file.uid,
        })),
      };
    },
  });