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, Property } from '@activepieces/pieces-framework';
import { frontAuth } from '../common/auth';
import { makeMultipartRequest, makeRequest } from '../common/client';
import { frontAttachments } from '../common/attachments';
import { HttpMethod } from '@activepieces/pieces-common';
import {
channelIdDropdown,
conversationIdDropdown,
teammateIdDropdown,
} from '../common/dropdown';
export const createDraftReply = createAction({
auth: frontAuth,
name: 'createDraftReply',
displayName: 'Create Draft Reply',
description:
'Create a draft reply to an existing conversation (subject/quote etc.) without sending immediately.',
audience: 'both',
aiMetadata: {
description:
'Create an unsent draft reply within an existing conversation (by conversation ID), optionally private to the author or shared (Mode). Use when a human should review before sending; "Send Reply" dispatches immediately, and "Create Draft" drafts a new conversation instead. Not idempotent: each call creates a new draft.',
idempotent: false,
},
props: {
conversation_id: conversationIdDropdown,
body: Property.LongText({
displayName: 'Message Body',
description: 'The content of the draft reply.',
required: true,
}),
subject: Property.ShortText({
displayName: 'Subject',
description: 'The subject of the draft reply (for email channels).',
required: false,
}),
author_id: teammateIdDropdown,
channel_id: channelIdDropdown,
to: Property.Array({
displayName: 'To',
description: 'List of recipient handles (email addresses, etc.).',
required: false,
}),
cc: Property.Array({
displayName: 'CC',
description: 'List of CC recipient handles.',
required: false,
}),
bcc: Property.Array({
displayName: 'BCC',
description: 'List of BCC recipient handles.',
required: false,
}),
attachments: frontAttachments.property,
mode: Property.StaticDropdown({
displayName: 'Mode',
description: 'Mode of the draft reply',
required: true,
options: {
options: [
{ label: 'Private', value: 'private' },
{ label: 'Shared', value: 'shared' },
],
},
defaultValue: 'private',
}),
signature_id: Property.ShortText({
displayName: 'Signature ID',
description:
'The ID of the signature to use for the draft reply (if applicable).',
required: false,
}),
should_add_default_signature: Property.Checkbox({
displayName: 'Add Default Signature',
description:
'Whether to append the default signature to the draft reply (if applicable).',
required: false,
defaultValue: false,
}),
},
async run({ auth, propsValue }) {
const {
conversation_id,
body,
subject,
author_id,
channel_id,
to,
cc,
bcc,
attachments,
mode,
signature_id,
should_add_default_signature,
} = propsValue;
const path = `/conversations/${conversation_id}/drafts`;
const requestBody: Record<string, unknown> = { body };
if (subject) requestBody['subject'] = subject;
if (author_id) requestBody['author_id'] = author_id;
if (channel_id) requestBody['channel_id'] = channel_id;
if (to) requestBody['to'] = to;
if (cc) requestBody['cc'] = cc;
if (bcc) requestBody['bcc'] = bcc;
if (mode) requestBody['mode'] = mode;
if (signature_id) requestBody['signature_id'] = signature_id;
if (should_add_default_signature !== undefined)
requestBody['should_add_default_signature'] =
should_add_default_signature;
const files = frontAttachments.resolve(attachments);
if (files.length > 0) {
return await makeMultipartRequest({
auth,
method: HttpMethod.POST,
path: path,
form: frontAttachments.buildBody({ fields: requestBody, files }),
});
}
return await makeRequest(auth, HttpMethod.POST, path, requestBody);
},
});