Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pieces/community/slack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-slack",
"version": "0.12.2",
"version": "0.12.3",
"dependencies": {
"@slack/web-api": "7.9.0",
"slackify-markdown": "4.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const inviteUserToChannelAction = createAction({
props: {
info: singleSelectChannelInfo,
channel: slackChannel(true),
userId,
userId: userId(true),
},
async run(context) {
const client = new WebClient(context.auth.access_token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const requestActionDirectMessageAction = createAction({
description:
'Send a message to a user and wait until the user selects an action',
props: {
userId,
userId: userId(true),
text,
actions,
username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const requestApprovalDirectMessageAction = createAction({
description:
'Send approval message to a user and then wait until the message is approved or disapproved',
props: {
userId,
userId: userId(true),
text,
username,
profilePicture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const slackSendDirectMessageAction = createAction({
displayName: 'Send Message To A User',
description: 'Send message to a user',
props: {
userId,
userId: userId(true),
text,
username,
profilePicture,
Expand Down
75 changes: 38 additions & 37 deletions packages/pieces/community/slack/src/lib/common/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,45 +90,46 @@ export const blocks = Property.Json({
defaultValue: []
});

export const userId = Property.Dropdown<string,true,typeof slackAuth>({
auth: slackAuth,
displayName: 'User',
required: true,
refreshers: [],
async options({ auth }) {
if (!auth) {
return {
disabled: true,
placeholder: 'connect slack account',
options: [],
};
}
export const userId = <R extends boolean>(required: R) =>
Property.Dropdown<string, R, typeof slackAuth>({
auth: slackAuth,
displayName: 'User',
required,
refreshers: [],
async options({ auth }) {
if (!auth) {
return {
disabled: true,
placeholder: 'connect slack account',
options: [],
};
}

const accessToken = (auth as OAuth2PropertyValue).access_token;

const client = new WebClient(accessToken);
const users: { label: string; value: string }[] = [];
for await (const page of client.paginate('users.list', {
limit: 1000, // Only limits page size, not total number of results
})) {
const response = page as UsersListResponse;
if (response.members) {
users.push(
...response.members
.filter((member) => !member.deleted)
.map((member) => {
return { label: member.name || '', value: member.id || '' };
})
);
const accessToken = (auth as OAuth2PropertyValue).access_token;

const client = new WebClient(accessToken);
const users: { label: string; value: string }[] = [];
for await (const page of client.paginate('users.list', {
limit: 1000, // Only limits page size, not total number of results
})) {
const response = page as UsersListResponse;
if (response.members) {
users.push(
...response.members
.filter((member) => !member.deleted)
.map((member) => {
return { label: member.name || '', value: member.id || '' };
})
);
}
}
}
return {
disabled: false,
placeholder: 'Select User',
options: users,
};
},
});
return {
disabled: false,
placeholder: 'Select User',
options: users,
};
},
});

export const text = Property.LongText({
displayName: 'Message',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const newCommandInDirectMessageTrigger = createTrigger({
description:
'Triggers when a specific command is sent to the bot (e.g., @bot command arg1 arg2) via Direct Message.',
props: {
user: userId,
user: userId(true),
commands: Property.Array({
displayName: 'Commands',
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const newCommand = createTrigger({
'Triggers when a specific command is sent to the bot (e.g., @bot command arg1 arg2)',
props: {
info: multiSelectChannelInfo,
user: userId,
user: userId(true),
commands: Property.Array({
displayName: 'Commands',
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const newMentionInDirectMessageTrigger = createTrigger({
description:
'Triggers when a username is mentioned in a direct message channel.',
props: {
user: userId,
user: userId(true),
ignoreBots: Property.Checkbox({
displayName: 'Ignore Bot Messages ?',
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const newMention = createTrigger({
description: 'Triggers when a username is mentioned.',
props: {
info: multiSelectChannelInfo,
user: userId,
user: userId(true),
channels: Property.MultiSelectDropdown({
auth: slackAuth,
displayName: 'Channels',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createTrigger,
} from '@activepieces/pieces-framework';
import { slackAuth } from '../../';
import { getChannels, multiSelectChannelInfo } from '../common/props';
import { getChannels, multiSelectChannelInfo, userId } from '../common/props';


export const newReactionAdded = createTrigger({
Expand All @@ -20,6 +20,7 @@ export const newReactionAdded = createTrigger({
description: 'Select emojis to trigger on',
required: false,
}),
user: userId(false),
channels: Property.MultiSelectDropdown({
auth: slackAuth,
displayName: 'Channels',
Expand Down Expand Up @@ -67,6 +68,11 @@ export const newReactionAdded = createTrigger({
const payloadBody = context.payload.body as PayloadBody;
const channels = (context.propsValue.channels as string[]) ?? [];

// Filter by user if specified
if (context.propsValue.user && payloadBody.event.user !== context.propsValue.user) {
return [];
}

// Filter by emoji if specified
if (context.propsValue.emojis) {
if (!context.propsValue.emojis.includes(payloadBody.event.reaction)) {
Expand All @@ -85,6 +91,7 @@ export const newReactionAdded = createTrigger({

type PayloadBody = {
event: {
user: string;
reaction: string;
item: {
channel: string;
Expand Down
Loading