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.0 KB
Raw Blame
import { createAction, Property, PiecePropValueSchema } from '@activepieces/pieces-framework';
import { teamworkAuth } from '../common/auth';
import { teamworkRequest } from '../common/client';
import { HttpMethod } from '@activepieces/pieces-common';

export const createMessageReply = createAction({
	name: 'create_message_reply',
	classification: 'WRITE',
	displayName: 'Create Message Reply',
	description: 'Post a reply in a message thread.',
	audience: 'both',
	aiMetadata: { description: 'Posts a reply to an existing Teamwork message thread, optionally notifying all project users. Use to respond within a message/discussion. Requires the message ID and reply body. Not idempotent — each call adds another reply.', idempotent: false },
	auth: teamworkAuth,
	props: {
		messageId: Property.Dropdown({
auth: teamworkAuth,
			displayName: 'Message',
			description: 'The message to reply to.',
			required: true,
			refreshers: [],
			options: async ({ auth }) => {
				if (!auth) {
					return {
						disabled: true,
						placeholder: 'Please authenticate first.',
						options: [],
					};
				}
				const res = await teamworkRequest(auth, {
					method: HttpMethod.GET,
					path: '/posts.json',
				});
				const options = res.data.posts.map((p: { id: string; title: string }) => ({
					label: p.title,
					value: p.id,
				}));
				return {
					disabled: false,
					options,
				};
			},
		}),
		body: Property.LongText({
			displayName: 'Body',
			description: 'The content of the reply.',
			required: true,
		}),
		notify: Property.Checkbox({
			displayName: 'Notify All',
			description: 'Notify all project users of this reply.',
			required: false,
		}),
	},
	async run({ auth, propsValue }) {
		const body = {
			messagereply: {
				body: propsValue.body,
				notify: propsValue.notify ? 'All' : undefined,
			},
		};
		return await teamworkRequest(auth, {
			method: HttpMethod.POST,
			path: `/messages/${propsValue.messageId}/messageReplies.json`,
			body,
		});
	},
});