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
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { createAction } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { callClickSendApi, clicksendCommon } from '../common';
import { clicksendAuth } from '../..';
function isValidEmail(email: string) {
return /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email);
}
export const clicksendFindContactByEmailAction = createAction({
auth: clicksendAuth,
name: 'find_contact_by_email',
classification: 'READ',
description: 'Finds contact by email address.',
audience: 'both',
aiMetadata: {
description:
'Searches a specific ClickSend contact list for a contact whose email exactly matches the given address, paging through the whole list until a match is found. Choose this to look up or verify a contact by email before updating or messaging them. Requires a valid email and the target list id; read-only and idempotent.',
idempotent: true,
},
displayName: 'Find Contact by Email',
props: {
contact_list_id: clicksendCommon.contact_list_id,
email: clicksendCommon.email,
},
async run(context) {
const { contact_list_id, email } = context.propsValue;
if (!isValidEmail(email)) {
throw new Error('Invalid email address.');
}
const username = context.auth.username;
const password = context.auth.password;
let currentPage = 1;
let hasNext = true;
do {
const response = await callClickSendApi<{
data: {
next_page_url?: string;
data: { email: string }[];
};
}>({
method: HttpMethod.GET,
username,
password,
path: `/lists/${contact_list_id}/contacts`,
query: { page: currentPage.toString(), limit: '100' },
});
const items = response.body.data?.data ?? [];
const matched = items.find((item) => item.email === email);
if (matched) {
return {
found: true,
data: matched,
};
}
currentPage++;
hasNext = !!response.body.data?.next_page_url;
} while (hasNext);
return {
found: false,
data: {},
};
},
});