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.7 KB
Raw Blame
import { slackAuth } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { WebClient } from '@slack/web-api';
import { getBotToken, SlackAuthValue } from '../common/auth-helpers';
import { channelResponseOutputSchema } from '../output-schemas';

export const createChannelAction = createAction({
  auth: slackAuth,
  name: 'slack-create-channel',
  classification: 'WRITE',
  displayName: 'Create Channel',
  description: 'Creates a new channel.',
  audience: 'human',
  aiMetadata: { description: 'Create a new public or private channel with the given name. Not idempotent: calling again with a name that already exists fails with a name-taken error rather than reusing the existing channel. Channel names are normalized by Slack (lowercased, spaces to hyphens).', idempotent: false },
  outputSchema: channelResponseOutputSchema,
  propertyGroups: [
    {
      key: 'new_channel',
      display: 'section',
      label: 'Channel',
      icon: 'markdown',
      props: ['channelName', 'isPrivate'],
    },
  ],
  props: {
    channelName: Property.ShortText({
      displayName: 'Channel Name',
      description: 'Lowercase letters, numbers, dashes and underscores only.',
      placeholder: 'project-updates',
      required: true,
    }),
    isPrivate: Property.Checkbox({
      displayName: 'Private Channel',
      description: 'Only invited members can see and join it.',
      required: false,
      defaultValue: false,
    }),
  },
  async run({ auth, propsValue }) {
    const client = new WebClient(getBotToken(auth as SlackAuthValue));
    return await client.conversations.create({
      name: propsValue.channelName,
      is_private: propsValue.isPrivate,
    });
  },
});