diff --git a/src/notification/email.ts b/src/notification/email.ts index 7275473a10..80e561f6cf 100644 --- a/src/notification/email.ts +++ b/src/notification/email.ts @@ -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'; @@ -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); diff --git a/src/notification/notification.ts b/src/notification/notification.ts index 9d74890544..dc632ea6f9 100644 --- a/src/notification/notification.ts +++ b/src/notification/notification.ts @@ -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) { @@ -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); } } diff --git a/src/notification/sms.ts b/src/notification/sms.ts index b31afacf46..54b411c79b 100644 --- a/src/notification/sms.ts +++ b/src/notification/sms.ts @@ -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]; @@ -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); diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 5d54667d3f..af7b0d8c34 100644 --- a/src/store/lookup.ts +++ b/src/store/lookup.ts @@ -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; diff --git a/src/store/model/store.ts b/src/store/model/store.ts index 06d42cfc0f..26dbd11ed8 100644 --- a/src/store/model/store.ts +++ b/src/store/model/store.ts @@ -4,6 +4,7 @@ export interface Link { model: string; series: string; url: string; + screenshot?: string; } export interface Labels {