11// Imports
22import { Bot } from "grammy"
33import { BOT_TOKEN , ADMINS , LIMIT } from "./config.js"
4- import { isUrl , getRandomId , getProductDetails } from "./utils.js"
4+ import { isUrl , getRandomId , getProductDetails , productCommonUrl } from "./utils.js"
55import { manageProducts , manageUsers } from "./db.js"
66import unshort from "./unshort.js"
77
@@ -28,12 +28,11 @@ const processUrl = async (msg, ctx) => {
2828 if ( isUrl ( productUrl ) ) {
2929 const merchant = productUrl . replace ( "www." , "" ) . split ( "//" ) [ 1 ] . split ( "." ) [ 0 ] ;
3030 if ( merchant . match ( / a m a z o n | f l i p k a r t | s n a p d e a l / gi) ) {
31- const noOfProducts = (
32- await manageProducts ( { userId : ctx . from . id } , "read" )
33- ) ?. result ?. length ;
31+ const noOfProducts = ( await manageProducts ( { userId : ctx . from . id } , "read" ) ) ?. result ?. length ;
3432 if ( noOfProducts < LIMIT ) {
3533 const sentMsg = await ctx . reply ( `Tracking ${ merchant } product...` , { reply_to_message_id : ctx . message . message_id } ) ;
3634 const details = await getProductDetails ( productUrl , merchant ) ;
35+
3736 if ( details . ok ) {
3837 try {
3938 const tracking_id = getRandomId ( ) ;
@@ -240,14 +239,14 @@ const track = async () => {
240239 user . userId ,
241240 `<a href="${ details . image } "> </a><b>Price has been ${ details . price > product . price ? "increased" : "decreased"
242241 } by ${ Math . abs ( product . price - details . price ) } </b>. \n\n<b>${ details . title
243- } </b>\n\nCurrent Price: <b>${ details . price } </b>\nLink: <a href="${ details . link
242+ } </b>\n\nCurrent Price: <b>${ details . price } </b>\nLink: <a href="${ productCommonUrl ( details . link , true )
244243 } ">${ product . merchant } </a>\n\nTo stop tracking send /stop_${ user . tracking_id
245244 } `,
246245 {
247246 parse_mode : "HTML" ,
248247 reply_markup : {
249248 inline_keyboard : details ?. link ? [
250- [ { text : "Buy Now" , url : details . link } ] ,
249+ [ { text : "Buy Now" , url : productCommonUrl ( details . link , true ) } ] ,
251250 [ { text : "Stop Tracking - " + user . tracking_id , callback_data : `stopTracking` , } ] ]
252251 : [ ]
253252 }
0 commit comments