send-message-action.ts•1.85 kB
import { createAction, Property } from '@activepieces/pieces-framework';
import {
profilePicture,
slackChannel,
username,
blocks,
threadTs,
singleSelectChannelInfo,
} from '../common/props';
import { processMessageTimestamp, slackSendMessage } from '../common/utils';
import { slackAuth } from '../../';
import { Block,KnownBlock } from '@slack/web-api';
export const slackSendMessageAction = createAction({
auth: slackAuth,
name: 'send_channel_message',
displayName: 'Send Message To A Channel',
description: 'Send message to a channel',
props: {
info: singleSelectChannelInfo,
channel: slackChannel(true),
text: Property.LongText({
displayName: 'Message',
description: 'The text of your message',
required: true,
}),
username,
profilePicture,
file: Property.File({
displayName: 'Attachment',
required: false,
}),
threadTs,
replyBroadcast: Property.Checkbox({
displayName: 'Broadcast reply to channel',
description: 'When replying to a thread, also make the message visible to everyone in the channel (only applicable when Thread Timestamp is provided)',
required: false,
defaultValue: false,
}),
blocks,
},
async run(context) {
const token = context.auth.access_token;
const { text, channel, username, profilePicture, threadTs, file, blocks, replyBroadcast } =
context.propsValue;
const blockList = blocks ?[{ type: 'section', text: { type: 'mrkdwn', text } }, ...(blocks as unknown as (KnownBlock | Block)[])] :undefined
return slackSendMessage({
token,
text,
username,
profilePicture,
conversationId: channel,
threadTs: threadTs ? processMessageTimestamp(threadTs) : undefined,
file,
blocks: blockList,
replyBroadcast,
});
},
});