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 #48 from trustpilot/fix-test-slash-command
Browse files Browse the repository at this point in the history
Fix test slash command
  • Loading branch information
miklosaubert authored Nov 2, 2018
2 parents 9447115 + fb137c3 commit f1b9e7b
Show file tree
Hide file tree
Showing 5 changed files with 1,832 additions and 715 deletions.
2 changes: 1 addition & 1 deletion app/slackapp/feed-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const upsertFeedSettings = (team, channelId, settings, slackapp) => {
// Using a Map to upsert the new settings
const feedsMap = new Map(feeds.map((f) => [f.channelId, f]));
const oldSettings = feedsMap.get(channelId);
feedsMap.set(channelId, oldSettings ? { ...oldSettings, ...settings } : settings);
feedsMap.set(channelId, { ...oldSettings, ...settings });
team.feeds = [...feedsMap.values()];
slackapp.saveTeamAsync = slackapp.saveTeamAsync || promisify(slackapp.saveTeam);
return slackapp.saveTeamAsync(team);
Expand Down
7 changes: 4 additions & 3 deletions app/slackapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
};

const testFeeds = async (bot) => {
const testReview = {
const review = {
stars: 5,
createdAt: new Date(),
title: 'Test Review',
Expand All @@ -57,7 +57,8 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
displayName: 'The Trustpilot Slack App',
},
};
slackapp.trigger('trustpilot_review_received', [testReview, bot.team_info.id]);
const { id: teamId, businessUnitId } = bot.team_info;
slackapp.trigger('trustpilot_review_received', [{ review, teamId, businessUnitId }]);
};

const handleReplyButton = async (bot, message) => {
Expand Down Expand Up @@ -140,7 +141,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
Custom handler : incoming review
*/

slackapp.on('trustpilot_review_received', async (review, teamId, businessUnitId) => {
slackapp.on('trustpilot_review_received', async ({ review, teamId, businessUnitId }) => {
slackapp.findTeamByIdAsync = slackapp.findTeamByIdAsync || promisify(slackapp.findTeamById);
const team = await slackapp.findTeamByIdAsync(teamId);
const bot = slackapp.spawn(team);
Expand Down
8 changes: 7 additions & 1 deletion app/webserver-extensions/extra-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ module.exports = (slackapp) => {
.forEach((e) => {
e.eventData.consumer.displayName = e.eventData.consumer.name; // Massaging into expected format
slackapp.log(`Posting new review for team ${teamId}, business unit ${businessUnitId}`);
slackapp.trigger('trustpilot_review_received', [e.eventData, teamId, businessUnitId]);
slackapp.trigger('trustpilot_review_received', [
{
review: e.eventData,
teamId,
businessUnitId,
},
]);
});
res.sendStatus(200);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"precommit": "npm run lint"
},
"dependencies": {
"botkit": "^0.6.8",
"botkit": "^0.6.19",
"botkit-storage-dynamodb": "^0.2.0",
"botkit-storage-mongo": "^1.0.4",
"moment": "^2.13.0",
Expand Down
Loading

0 comments on commit f1b9e7b

Please sign in to comment.