diff --git a/bot/bot.py b/bot/bot.py index 3c50e10..8960dae 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -46,6 +46,7 @@ def load_page(url: str, driver: webdriver, screenshot_type=""): def extract_amazon_url_with_referer(text: str): product_code = "" extra_params = "" + original_message = re.sub(r'https?://\S+|www\.\S+', '', text) start = text.find("amzn.to") if start != -1: @@ -64,7 +65,7 @@ def extract_amazon_url_with_referer(text: str): extra_params = (''.join(str(w) for w in vendor_and_smid_result if w is not None)) extra_params = extra_params.replace('?','&') - return helpers.new_refer_url(product_code, extra_params) + return helpers.new_refer_url(product_code, extra_params), original_message def resolve_captcha(driver: webdriver): @@ -101,7 +102,7 @@ def find_amazon_link(update: Update, context: CallbackContext) -> None: user, chat, chat_id, message_id = update.message.from_user, update.message.chat, update.message.chat_id, update.message.message_id - amazon_url_with_referer = extract_amazon_url_with_referer(msg) + amazon_url_with_referer, original_message = extract_amazon_url_with_referer(msg) if amazon_url_with_referer: logging.info(f"Link sent by {user} - {msg}") @@ -138,7 +139,7 @@ def find_amazon_link(update: Update, context: CallbackContext) -> None: helpers.create_image(product_id, product_data.price) keyboard = [[InlineKeyboardButton("Ir a Amazon", url=f"{amazon_url_with_referer}")]] markup = InlineKeyboardMarkup(keyboard) - context.bot.send_photo(chat_id=chat_id, photo=open(f"/app/data/images/products/{product_id}_composed.png", 'rb'), caption=f"URL enviada por @{user['username']}: \n\n{product_data.title}", reply_markup=markup) + context.bot.send_photo(chat_id=chat_id, photo=open(f"/app/data/images/products/{product_id}_composed.png", 'rb'), caption=f"URL enviada por @{user['username']}: \n\n{product_data.title}\n\nMensaje original: {original_message}", reply_markup=markup) def main() -> None: