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 { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { chatbaseAuth } from '../auth';
import { makeRequest } from '../common';
import { chatbotIdDropdown } from '../common/props';

export const searchConversationsAction = createAction({
	auth: chatbaseAuth,
	name: 'search_conversations',
	classification: 'SEARCH',
	displayName: 'Search Conversations by Query',
	description: 'Searches for conversations from a specific chatbot.',
	audience: 'both',
	aiMetadata: { description: 'Retrieves logged conversations for a specific Chatbase chatbot (selected by its ID), with optional filters for source channels (API, WhatsApp, Slack, etc.), a start/end date range, and pagination. Use when an agent needs to review or audit past chatbot conversations; leaving the optional filters empty returns all conversations for the chatbot. Idempotent read-only lookup.', idempotent: true },
	props: {
		chatbotId: chatbotIdDropdown,
		filteredSources: Property.StaticMultiSelectDropdown({
			displayName: 'Sources',
			description: 'Filter by one or more conversation sources.',
			required: false,
			options: {
				disabled: false,
				options: [
					{ label: 'API', value: 'API' },
					{ label: 'Chatbase site', value: 'Chatbase site' },
					{ label: 'Instagram', value: 'Instagram' },
					{ label: 'Messenger', value: 'Messenger' },
					{ label: 'Slack', value: 'Slack' },
					{ label: 'Unspecified', value: 'Unspecified' },
					{ label: 'WhatsApp', value: 'WhatsApp' },
					{ label: 'Widget or Iframe', value: 'Widget or Iframe' },
				],
			},
		}),
		startDate: Property.DateTime({
			displayName: 'Start Date',
			required: false,
		}),
		endDate: Property.DateTime({
			displayName: 'End Date',
			required: false,
		}),
		page: Property.Number({
			displayName: 'Page',
			description: 'Pagination page number (default = 1)',
			required: false,
		}),
		size: Property.Number({
			displayName: 'Page Size',
			description: 'Number of results per page (default = 10, max = 100)',
			required: false,
		}),
	},

	async run(context) {
		const { chatbotId, filteredSources, startDate, endDate, page, size } = context.propsValue;

		const apiKey = context.auth.secret_text;

		const queryParams = new URLSearchParams({ chatbotId });

		if (filteredSources?.length) {
			queryParams.append('filteredSources', filteredSources.join(','));
		}
		if (startDate) {
			queryParams.append('startDate', startDate.toString().split('T')[0]);
		}
		if (endDate) {
			queryParams.append('endDate', endDate.toString().split('T')[0]);
		}
		if (page) {
			queryParams.append('page', page.toString());
		}
		if (size) {
			queryParams.append('size', size.toString());
		}

		const response = await makeRequest(
			apiKey,
			HttpMethod.GET,
			`/get-conversations?${queryParams.toString()}`,
		);

		return response;
	},
});