Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include screenshot for emails + sms notifications #144

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/notification/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import nodemailer from 'nodemailer';
import Mail from 'nodemailer/lib/mailer';
import {Config} from '../config';
import {Logger} from '../logger';
import {Link} from '../store/model';

const email = Config.notifications.email;
const subject = 'NVIDIA - BUY NOW';
Expand All @@ -20,9 +21,18 @@ const mailOptions: Mail.Options = {
subject
};

export function sendEmail(cartUrl: string) {
export function sendEmail(cartUrl: string, link: Link) {
mailOptions.text = cartUrl;

if (link.screenshot) {
mailOptions.attachments = [
{
filename: link.screenshot,
path: `./${link.screenshot}`
}
];
}

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
Logger.error(error);
Expand Down
4 changes: 2 additions & 2 deletions src/notification/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const notifications = Config.notifications;

export function sendNotification(cartUrl: string, link: Link) {
if (notifications.email.username && notifications.email.password) {
sendEmail(cartUrl);
sendEmail(cartUrl, link);
}

if (notifications.slack.channel && notifications.slack.token) {
Expand All @@ -30,7 +30,7 @@ export function sendNotification(cartUrl: string, link: Link) {
if (notifications.phone.number) {
const carrier = notifications.phone.carrier.toLowerCase();
if (carrier && notifications.phone.availableCarriers.has(carrier)) {
sendSMS(cartUrl);
sendSMS(cartUrl, link);
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/notification/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import nodemailer from 'nodemailer';
import Mail from 'nodemailer/lib/mailer';
import {Config} from '../config';
import {Logger} from '../logger';
import {Link} from '../store/model';

const subject = 'NVIDIA - BUY NOW';
const [email, phone] = [Config.notifications.email, Config.notifications.phone];
Expand All @@ -20,9 +21,18 @@ const mailOptions: Mail.Options = {
subject
};

export function sendSMS(text: string) {
export function sendSMS(text: string, link: Link) {
mailOptions.text = text;

if (link.screenshot) {
mailOptions.attachments = [
{
filename: link.screenshot,
path: `./${link.screenshot}`
}
];
}

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
Logger.error(error);
Expand Down
3 changes: 2 additions & 1 deletion src/store/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ async function lookup(browser: Browser, store: Store) {

if (Config.page.capture) {
Logger.debug('ℹ saving screenshot');
await page.screenshot({path: `success-${Date.now()}.png`});
link.screenshot = `success-${Date.now()}.png`;
await page.screenshot({path: link.screenshot});
}

const givenUrl = link.cartUrl ? link.cartUrl : link.url;
Expand Down
1 change: 1 addition & 0 deletions src/store/model/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Link {
model: string;
series: string;
url: string;
screenshot?: string;
}

export interface Labels {
Expand Down