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.8 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { slackAuth } from '../auth';
import { singleSelectChannelInfo, slackChannel, onlyBotChannels, messageTs } from '../common/props';
import { processMessageTimestamp } from '../common/utils';
import { WebClient } from '@slack/web-api';
import { getBotToken, SlackAuthValue } from '../common/auth-helpers';
import { getMessageActionOutputSchema } from '../output-schemas';

export const getMessageAction = createAction({
	name: 'get-message',
	classification: 'READ',
	displayName: 'Get Message by Timestamp',
	description: `Retrieves a specific message from a channel history using the message's timestamp.`,
	audience: 'human',
	aiMetadata: { description: "Fetch a single message from a channel by its exact timestamp; read-only and repeatable. Use this when you already have the message ts and channel; use Get channel history to read a range of messages or Search messages to find one by content.", idempotent: true },
	auth: slackAuth,
	outputSchema: getMessageActionOutputSchema,
	propertyGroups: [
		{
			key: 'channel_picker',
			display: 'section',
			label: 'Channel',
			icon: 'markdown',
			props: ['info', 'onlyBotChannels', 'channel'],
		},
		{
			key: 'message',
			display: 'section',
			label: 'Message',
			icon: 'text',
			props: ['ts'],
		},
	],
	props: {
		info: singleSelectChannelInfo,
		onlyBotChannels,
		channel: slackChannel(true),
		ts: messageTs,
	},
	async run({ auth, propsValue }) {
		const messageTimestamp = processMessageTimestamp(propsValue.ts);
		if (!messageTimestamp) {
			throw new Error('Invalid Timestamp Value.');
		}
		const client = new WebClient(getBotToken(auth as SlackAuthValue));

		return await client.conversations.history({
			channel: propsValue.channel,
			oldest: messageTimestamp,
			limit: 1,
			inclusive: true,
		});
	},
});