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

export const slackGetMessagePermalinkAction = createAction({
  auth: slackAuth,
  name: 'slack_get_message_permalink',
  classification: 'READ',
  displayName: 'Get Message Permalink',
  description: 'Get a shareable permalink URL for a specific message.',
  audience: 'ai',
  aiMetadata: {
    description:
      'Return a stable, shareable permalink URL for one message identified by channel ID and message timestamp (ts); read-only and repeatable. Obtain the ts from Post Message, Search Messages, or Get Channel History. Use this when you need a link to reference a message elsewhere.',
    idempotent: true,
  },
  outputSchema: permalinkActionOutputSchema,
  props: {
    channel: Property.ShortText({
      displayName: 'Channel',
      description:
        'Channel ID containing the message (e.g. C0123ABCD). Resolve a #name with Find Channel.',
      required: true,
    }),
    messageTs: Property.ShortText({
      displayName: 'Message Timestamp',
      description:
        'Timestamp (ts) of the message, e.g. 1710304378.475129. Obtain it from Post Message / Search Messages / Get Channel History.',
      required: true,
    }),
  },
  async run({ auth, propsValue }) {
    const messageTimestamp = processMessageTimestamp(propsValue.messageTs);
    if (!messageTimestamp) {
      throw new Error('Invalid Timestamp Value.');
    }
    const client = new WebClient(getBotToken(auth as SlackAuthValue));
    return await client.chat.getPermalink({
      channel: propsValue.channel,
      message_ts: messageTimestamp,
    });
  },
});