From 777c31b420a38cab860d98bc6bd8b7ba990c55e7 Mon Sep 17 00:00:00 2001 From: VictorV Date: Wed, 18 Nov 2020 07:23:31 -0800 Subject: [PATCH] feat(notification): add product link to email and telegram (#816) --- src/logger.ts | 6 ++++++ src/notification/email.ts | 2 +- src/notification/telegram.ts | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index c82157e..a5e7849 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -180,6 +180,12 @@ export const Print = { return `✖ ${buildProductString(link, store)} :: OUT OF STOCK`; }, + productInStock(link: Link): string { + let productString = `Product Page: ${link.url}`; + if (link.cartUrl) productString += `\nAdd To Cart Link: ${link.cartUrl}`; + + return productString; + }, rateLimit(link: Link, store: Store, color?: boolean): string { if (color) { return ( diff --git a/src/notification/email.ts b/src/notification/email.ts index cc7bbbe..1e0644c 100644 --- a/src/notification/email.ts +++ b/src/notification/email.ts @@ -40,7 +40,7 @@ export function sendEmail(link: Link, store: Store) { : undefined, from: email.username, subject: Print.inStock(link, store), - text: link.cartUrl ? link.cartUrl : link.url, + text: Print.productInStock(link), to: email.to }; diff --git a/src/notification/telegram.ts b/src/notification/telegram.ts index 9c78708..b5822c1 100644 --- a/src/notification/telegram.ts +++ b/src/notification/telegram.ts @@ -14,7 +14,7 @@ export function sendTelegramMessage(link: Link, store: Store) { logger.debug('↗ sending telegram message'); (async () => { - const givenUrl = link.cartUrl ? link.cartUrl : link.url; + const message = Print.productInStock(link); const results = []; for (const chatId of telegram.chatId) { @@ -22,7 +22,7 @@ export function sendTelegramMessage(link: Link, store: Store) { results.push( client.sendMessage( chatId, - `${Print.inStock(link, store)}\n${givenUrl}` + `${Print.inStock(link, store)}\n${message}` ) ); logger.info('✔ telegram message sent');