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

1.6 KB
Raw Blame
import { slackAuth } from '../auth';
import { createAction } from '@activepieces/pieces-framework';
import { singleSelectChannelInfo, slackChannel, onlyBotChannels, userId } from '../common/props';
import { WebClient } from '@slack/web-api';
import { getBotToken, SlackAuthValue } from '../common/auth-helpers';
import { channelResponseOutputSchema } from '../output-schemas';

export const inviteUserToChannelAction = createAction({
	auth: slackAuth,
	name: 'invite-user-to-channel',
	classification: 'WRITE',
	displayName: 'Invite User to Channel',
	description: 'Invites an existing User to an existing channel.',
	audience: 'human',
	aiMetadata: { description: 'Add an existing workspace user to an existing channel as a member. Both the channel and the user must already exist. Effectively idempotent in result since a user already in the channel stays a member, though Slack returns an error if they are already present.', idempotent: false },
	outputSchema: channelResponseOutputSchema,
	propertyGroups: [
		{
			key: 'channel_picker',
			display: 'section',
			label: 'Channel',
			icon: 'markdown',
			props: ['info', 'onlyBotChannels', 'channel'],
		},
		{
			key: 'user_picker',
			display: 'section',
			label: 'User',
			icon: 'user',
			props: ['userId'],
		},
	],
	props: {
		info: singleSelectChannelInfo,
		onlyBotChannels,
		channel: slackChannel(true),
		userId: userId(true),
	},
	async run(context) {
		const client = new WebClient(getBotToken(context.auth as SlackAuthValue));

		return await client.conversations.invite({
			channel: context.propsValue.channel,
			users: `${context.propsValue.userId}`,
		});
	},
});