Skip to content

Commit

Permalink
fixing notification provider
Browse files Browse the repository at this point in the history
  • Loading branch information
orangecoding committed Sep 27, 2023
1 parent fbad445 commit 17b4bad
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 135 deletions.
2 changes: 1 addition & 1 deletion lib/notification/adapter/mailJet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const template = fs.readFileSync(path.resolve(__dirname + '/notification/emailTe
const emailTemplate = Handlebars.compile(template);
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { apiPublicKey, apiPrivateKey, receiver, from } = notificationConfig.find(
(adapter) => adapter.id === 'mailjet'
(adapter) => adapter.id === config.id,
).fields;
const to = receiver
.trim()
Expand Down
4 changes: 2 additions & 2 deletions lib/notification/adapter/mattermost.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { markdown2Html } from '../../services/markdown.js';
import { getJob } from '../../services/storage/jobStorage.js';
import fetch from 'node-fetch';
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { webhook, channel } = notificationConfig.find((adapter) => adapter.id === 'mattermost').fields;
const { webhook, channel } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
const job = getJob(jobKey);
const jobName = job == null ? jobKey : job.name;
let message = `### *${jobName}* (${serviceName}) found **${newListings.length}** new listings:\n\n`;
message += `| Title | Address | Size | Price |\n|:----|:----|:----|:----|\n`;
message += newListings.map(
(o) => `| [${o.title}](${o.link}) | ` + [o.address, o.size.replace(/2m/g, '$m^2$'), o.price].join(' | ') + ' |\n'
(o) => `| [${o.title}](${o.link}) | ` + [o.address, o.size.replace(/2m/g, '$m^2$'), o.price].join(' | ') + ' |\n',
);
return fetch(webhook, {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion lib/notification/adapter/ntfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getJob } from '../../services/storage/jobStorage.js';
import fetch from 'node-fetch';

export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { priority, server, topic } = notificationConfig.find((adapter) => adapter.id === 'ntfy').fields;
const { priority, server, topic } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
const job = getJob(jobKey);
const jobName = job == null ? jobKey : job.name;
const promises = newListings.map((newListing) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/notification/adapter/sendGrid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sgMail from '@sendgrid/mail';
import { markdown2Html } from '../../services/markdown.js';
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { apiKey, receiver, from, templateId } = notificationConfig.find((adapter) => adapter.id === 'sendGrid').fields;
const { apiKey, receiver, from, templateId } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
sgMail.setApiKey(apiKey);
const msg = {
templateId,
Expand Down
4 changes: 2 additions & 2 deletions lib/notification/adapter/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Slack from 'slack';
import { markdown2Html } from '../../services/markdown.js';
const msg = Slack.chat.postMessage;
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { token, channel } = notificationConfig.find((adapter) => adapter.id === 'slack').fields;
const { token, channel } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
return newListings.map((payload) =>
msg({
token,
Expand Down Expand Up @@ -35,7 +35,7 @@ export const send = ({ serviceName, newListings, notificationConfig, jobKey }) =
ts: new Date().getTime() / 1000,
},
],
})
}),
);
};
export const config = {
Expand Down
4 changes: 2 additions & 2 deletions lib/notification/adapter/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function shorten(str, len = 30) {
return str.length > len ? str.substring(0, len) + '...' : str;
}
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { token, chatId } = notificationConfig.find((adapter) => adapter.id === 'telegram').fields;
const { token, chatId } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
const job = getJob(jobKey);
const jobName = job == null ? jobKey : job.name;
//we have to split messages into chunk, because otherwise messages are going to become too big and will fail
Expand All @@ -30,7 +30,7 @@ export const send = ({ serviceName, newListings, notificationConfig, jobKey }) =
(o) =>
`<a href='${o.link}'><b>${shorten(o.title.replace(/\*/g, ''), 45).trim()}</b></a>\n` +
[o.address, o.price, o.size].join(' | ') +
'\n\n'
'\n\n',
);
/**
* This is to not break the rate limit. It is to only send 1 message per second
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fredy",
"version": "7.3.2",
"version": "7.4.0",
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
"scripts": {
"start": "node index.js",
Expand Down Expand Up @@ -55,11 +55,11 @@
"Firefox ESR"
],
"dependencies": {
"@douyinfe/semi-ui": "2.42.4",
"@douyinfe/semi-ui": "2.44.0",
"@rematch/core": "2.2.0",
"@rematch/loading": "2.1.2",
"@sendgrid/mail": "7.7.0",
"@vitejs/plugin-react": "4.0.4",
"@vitejs/plugin-react": "4.1.0",
"better-sqlite3": "8.6.0",
"body-parser": "1.20.2",
"cookie-session": "2.0.0",
Expand Down Expand Up @@ -88,21 +88,21 @@
"x-ray": "2.3.4"
},
"devDependencies": {
"@babel/core": "7.22.15",
"@babel/core": "7.23.0",
"@babel/eslint-parser": "7.22.15",
"@babel/preset-env": "7.22.15",
"@babel/preset-env": "7.22.20",
"@babel/preset-react": "7.22.15",
"chai": "4.3.8",
"eslint": "8.48.0",
"chai": "4.3.9",
"eslint": "8.50.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-react": "7.33.2",
"esmock": "2.4.0",
"esmock": "2.5.1",
"history": "5.3.0",
"husky": "4.3.8",
"less": "4.2.0",
"lint-staged": "13.2.2",
"mocha": "10.2.0",
"prettier": "2.8.8",
"prettier": "3.0.3",
"redux-logger": "3.0.6"
}
}

0 comments on commit 17b4bad

Please sign in to comment.