mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 07:37:39 +00:00
feat: include screenshot for emails + sms notifications (#144)
This commit is contained in:
@@ -2,6 +2,7 @@ import nodemailer from 'nodemailer';
|
|||||||
import Mail from 'nodemailer/lib/mailer';
|
import Mail from 'nodemailer/lib/mailer';
|
||||||
import {Config} from '../config';
|
import {Config} from '../config';
|
||||||
import {Logger} from '../logger';
|
import {Logger} from '../logger';
|
||||||
|
import {Link} from '../store/model';
|
||||||
|
|
||||||
const email = Config.notifications.email;
|
const email = Config.notifications.email;
|
||||||
const subject = 'NVIDIA - BUY NOW';
|
const subject = 'NVIDIA - BUY NOW';
|
||||||
@@ -20,9 +21,18 @@ const mailOptions: Mail.Options = {
|
|||||||
subject
|
subject
|
||||||
};
|
};
|
||||||
|
|
||||||
export function sendEmail(cartUrl: string) {
|
export function sendEmail(cartUrl: string, link: Link) {
|
||||||
mailOptions.text = cartUrl;
|
mailOptions.text = cartUrl;
|
||||||
|
|
||||||
|
if (link.screenshot) {
|
||||||
|
mailOptions.attachments = [
|
||||||
|
{
|
||||||
|
filename: link.screenshot,
|
||||||
|
path: `./${link.screenshot}`
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
transporter.sendMail(mailOptions, (error, info) => {
|
transporter.sendMail(mailOptions, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const notifications = Config.notifications;
|
|||||||
|
|
||||||
export function sendNotification(cartUrl: string, link: Link) {
|
export function sendNotification(cartUrl: string, link: Link) {
|
||||||
if (notifications.email.username && notifications.email.password) {
|
if (notifications.email.username && notifications.email.password) {
|
||||||
sendEmail(cartUrl);
|
sendEmail(cartUrl, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notifications.slack.channel && notifications.slack.token) {
|
if (notifications.slack.channel && notifications.slack.token) {
|
||||||
@@ -30,7 +30,7 @@ export function sendNotification(cartUrl: string, link: Link) {
|
|||||||
if (notifications.phone.number) {
|
if (notifications.phone.number) {
|
||||||
const carrier = notifications.phone.carrier.toLowerCase();
|
const carrier = notifications.phone.carrier.toLowerCase();
|
||||||
if (carrier && notifications.phone.availableCarriers.has(carrier)) {
|
if (carrier && notifications.phone.availableCarriers.has(carrier)) {
|
||||||
sendSMS(cartUrl);
|
sendSMS(cartUrl, link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -2,6 +2,7 @@ import nodemailer from 'nodemailer';
|
|||||||
import Mail from 'nodemailer/lib/mailer';
|
import Mail from 'nodemailer/lib/mailer';
|
||||||
import {Config} from '../config';
|
import {Config} from '../config';
|
||||||
import {Logger} from '../logger';
|
import {Logger} from '../logger';
|
||||||
|
import {Link} from '../store/model';
|
||||||
|
|
||||||
const subject = 'NVIDIA - BUY NOW';
|
const subject = 'NVIDIA - BUY NOW';
|
||||||
const [email, phone] = [Config.notifications.email, Config.notifications.phone];
|
const [email, phone] = [Config.notifications.email, Config.notifications.phone];
|
||||||
@@ -20,9 +21,18 @@ const mailOptions: Mail.Options = {
|
|||||||
subject
|
subject
|
||||||
};
|
};
|
||||||
|
|
||||||
export function sendSMS(text: string) {
|
export function sendSMS(text: string, link: Link) {
|
||||||
mailOptions.text = text;
|
mailOptions.text = text;
|
||||||
|
|
||||||
|
if (link.screenshot) {
|
||||||
|
mailOptions.attachments = [
|
||||||
|
{
|
||||||
|
filename: link.screenshot,
|
||||||
|
path: `./${link.screenshot}`
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
transporter.sendMail(mailOptions, (error, info) => {
|
transporter.sendMail(mailOptions, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
|
|||||||
+2
-1
@@ -84,7 +84,8 @@ async function lookup(browser: Browser, store: Store) {
|
|||||||
|
|
||||||
if (Config.page.capture) {
|
if (Config.page.capture) {
|
||||||
Logger.debug('ℹ saving screenshot');
|
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;
|
const givenUrl = link.cartUrl ? link.cartUrl : link.url;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export interface Link {
|
|||||||
model: string;
|
model: string;
|
||||||
series: string;
|
series: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
screenshot?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Labels {
|
export interface Labels {
|
||||||
|
|||||||
Reference in New Issue
Block a user