Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #52 from trustpilot/custom-triggers
Browse files Browse the repository at this point in the history
Custom triggers
  • Loading branch information
miklosaubert authored Feb 6, 2019
2 parents 2979fce + 23b1bbc commit 0dbc115
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/slackapp/feed-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const showIntroMessage = (message, bot) => {
}
};

const showFeedSettings = (bot, message) => {
const showFeedSettings = (slackapp) => (bot, message) => {
const team = bot.team_info;
const { starFilter = 'all', canReply } = getChannelFeedSettingsOrDefault(team, message.channel);
const sourceMessage = {
Expand Down Expand Up @@ -135,6 +135,7 @@ const showFeedSettings = (bot, message) => {
console.log(err, res);
}
});
slackapp.trigger('feed_settings_dialog_opened', [bot]);
};

const handleNewFeedSettings = async (bot, message, slackapp) => {
Expand Down Expand Up @@ -180,9 +181,13 @@ const deleteFeedSettings = (slackapp) => async (bot, message) => {
if (team.incoming_webhook && team.incoming_webhook.channel_id === channelId) {
team.incoming_webhook = null;
}
const deletedFeed = team.feeds && team.feeds.find((f) => f.channelId === channelId);
team.feeds = (team.feeds || []).filter((f) => f.channelId !== channelId);
slackapp.saveTeamAsync = slackapp.saveTeamAsync || promisify(slackapp.saveTeam);
await slackapp.saveTeamAsync(team);
if (deletedFeed) {
slackapp.trigger('feed_settings_deleted', [{ businessUnitId: deletedFeed.businessUnitId }]);
}
showIntroMessage(message, bot);
};

Expand Down
7 changes: 6 additions & 1 deletion app/slackapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const setupAppHandlers = (slackapp, apiClient, enableReviewQueries) => {
);
} else {
reviewReply.showReplyDialog(bot, message);
slackapp.trigger('reply_dialog_opened', [
{
reviewId: message.callback_id,
},
]);
}
};

Expand Down Expand Up @@ -119,7 +124,7 @@ const setupAppHandlers = (slackapp, apiClient, enableReviewQueries) => {
const action = message.actions[0].value;
const actionHandlers = {
['step_1_write_reply']: handleReplyButton,
['open_feed_settings']: feedSettings.showFeedSettings,
['open_feed_settings']: feedSettings.showFeedSettings(slackapp),
['delete_feed_settings']: feedSettings.deleteFeedSettings(slackapp),
};
await actionHandlers[action](bot, message);
Expand Down

0 comments on commit 0dbc115

Please sign in to comment.