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

3.3 KB
Raw Blame
import { Property } from "@activepieces/pieces-framework";
import { makeRequest } from "./client";
import { HttpMethod } from "@activepieces/pieces-common";
import { SiteSpeakAuth } from "./auth";

export const chatbotIdDropdown = Property.Dropdown({
  auth: SiteSpeakAuth,
  displayName: 'chatbotId',
  description: 'Chat bot ID ',
  required: false,
  refreshers: ['auth'],
  async options({ auth, }) {
    if (!auth ) {
      return {
        disabled: true,
        options: [],
        placeholder: 'Select a chatbot first',
      };
    }

    try {
      const response = await makeRequest(
        auth.secret_text,
        HttpMethod.GET,
        `/me/chatbots`
      );

      return {
        disabled: false,
        options: response.map((chatbot: any) => ({
          label: chatbot.name || chatbot.id,
          value: chatbot.id,
        })),
      };
    } catch (e: any) {
      return {
        disabled: true,
        options: [],
        placeholder: 'Failed to fetch conversations',
      };
    }
  },
});
export const conversationIdDropdown = Property.Dropdown<string,false,typeof SiteSpeakAuth>({
    auth: SiteSpeakAuth,
    displayName: 'Conversation',
    description: 'Pick a conversation for context, or leave empty to start a new one.',
    required: false,
    refreshers: ['chatbotId'],
    async options({ auth, chatbotId }) {
    
        if (!auth || !chatbotId) {
            return {
                disabled: true,
                options: [],
                placeholder: "Select a chatbot first",
            };
        }

        try {
            const response = await makeRequest(
                auth.secret_text,
                HttpMethod.GET,
                `/${chatbotId}/conversations`
            );

            return {
                disabled: false,
                options: response.map((conv: any) => ({
                    label: `Speaker: ${conv.speaker}, Started: ${new Date(conv.created_at).toLocaleDateString()}` || conv.id,
                    value: conv.id,
                })),
            };
        } catch (e: any) {
            return {
                disabled: true,
                options: [],
                placeholder: "Failed to fetch conversations",
            };
        }
    },
});
export const finetuneIdDropdown = Property.Dropdown<string,true,typeof SiteSpeakAuth>({
  auth: SiteSpeakAuth,
  displayName: 'Finetune Entry',
  description: 'Select the finetune entry to delete.',
  required: true,
  refreshers: ['chatbotId'],
  async options({ auth, chatbotId }) {
    
    if (!auth || !chatbotId) {
      return {
        disabled: true,
        options: [],
        placeholder: "Please enter/select a chatbot ID first",
      };
    }

    try {
      const response = await makeRequest(
        auth.secret_text,
        HttpMethod.GET,
        `/${chatbotId}/finetunes`
      );

      if (!response || response.length === 0) {
        return {
          disabled: true,
          options: [],
          placeholder: "No finetune entries found for this chatbot",
        };
      }

      return {
        disabled: false,
        options: response.map((item: any) => ({
          label: item.question || item.id,
          value: item.id,
        })),
      };
    } catch (e: any) {
      return {
        disabled: true,
        options: [],
        placeholder: "Failed to fetch finetune entries",
      };
    }
  },
});