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

Commit

Permalink
Use new version of Trustpilot module
Browse files Browse the repository at this point in the history
  • Loading branch information
miklosaubert committed Jan 18, 2019
1 parent db26c3f commit 2f6e145
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/trustpilot-api.js → app/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(client) {
return requestWrapper(options);
}

class ApiBridge {
class ApiClient {
async getLastUnansweredReview({ stars, businessUnitId }) {
const data = await privateRequest({
method: 'GET',
Expand All @@ -29,5 +29,5 @@ module.exports = function(client) {
}
}

return new ApiBridge();
return new ApiClient();
};
10 changes: 5 additions & 5 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Entry point of this app, sets us up and running from config and env variables
*/

const TrustpilotApi = require('./trustpilot-api');
const ApiClient = require('./api-client');
const StorageEngine = require('./storage-engine');
const SlackApp = require('./slackapp');

Expand All @@ -14,9 +14,9 @@ const run = (config, trustpilotClient, webserverExtensions) => {
process.exit(-1);
}

const trustpilotApi = TrustpilotApi(trustpilotClient);
const apiClient = ApiClient(trustpilotClient);
const storageEngine = StorageEngine(config.BOTKIT_STORAGE_TYPE);
const slackapp = SlackApp(config, trustpilotApi, storageEngine);
const slackapp = SlackApp(config, apiClient, storageEngine);

// Set up a web server to expose oauth and webhook endpoints
slackapp.setupWebserver(config.PORT, () => {
Expand All @@ -40,8 +40,8 @@ if (require.main !== module) {
console.error('Unhandled Rejection at:', p, 'reason:', reason);
});

const trustpilotClient = new Trustpilot({
apiKey: config.API_KEY,
const trustpilotClient = new Trustpilot.TrustpilotApi({
key: config.API_KEY,
secret: config.API_SECRET,
username: config.BUSINESS_USER_NAME,
password: config.BUSINESS_USER_PASS,
Expand Down
10 changes: 5 additions & 5 deletions app/slackapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { composeReviewMessage } = require('./lib/review-message');
const reviewReply = require('./review-reply');
const feedSettings = require('./feed-settings');

const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
const setupAppHandlers = (slackapp, apiClient, enableReviewQueries) => {
const slashCommandType = (text) => {
if (/^[1-5] stars?$/i.test(text) || /^la(te)?st$/i.test(text)) {
return 'review_query';
Expand All @@ -24,7 +24,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
const businessUnitId = team.businessUnitId;
const { canReply } = feedSettings.getChannelFeedSettingsOrDefault(team, sourceMessage.channel);

const lastReview = await trustpilotApi.getLastUnansweredReview({
const lastReview = await apiClient.getLastUnansweredReview({
stars,
businessUnitId,
});
Expand Down Expand Up @@ -130,7 +130,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
bot.dialogOk();
const { dialogType } = JSON.parse(message.callback_id);
const dialogHandlers = {
['review_reply']: reviewReply.handleReply(trustpilotApi),
['review_reply']: reviewReply.handleReply(apiClient),
['feed_settings']: feedSettings.handleDialogSubmission(slackapp),
};
await dialogHandlers[dialogType](bot, message);
Expand Down Expand Up @@ -174,7 +174,7 @@ const setupAppHandlers = (slackapp, trustpilotApi, enableReviewQueries) => {
});
};

module.exports = (config, trustpilotApi, storage) => {
module.exports = (config, apiClient, storage) => {
// Fallback to jfs when no storage middleware provided
const slackapp = botkit.slackbot({
debug: false,
Expand All @@ -187,6 +187,6 @@ module.exports = (config, trustpilotApi, storage) => {
rtm_receive_messages: false, // eslint-disable-line camelcase
scopes: ['bot', 'incoming-webhook', 'commands'],
});
setupAppHandlers(slackapp, trustpilotApi, config.ENABLE_REVIEW_QUERIES);
setupAppHandlers(slackapp, apiClient, config.ENABLE_REVIEW_QUERIES);
return slackapp;
};
4 changes: 2 additions & 2 deletions app/slackapp/review-reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const confirmReply = async (bot, message, originalTs) => {
}
};

const handleReply = (trustpilotApi) => async (bot, message) => {
const handleReply = (apiClient) => async (bot, message) => {
const { originalTs, reviewId } = JSON.parse(message.callback_id);
try {
await trustpilotApi.replyToReview({
await apiClient.replyToReview({
reviewId,
message: message.submission.reply,
});
Expand Down

0 comments on commit 2f6e145

Please sign in to comment.