From 3906ed73aa0702e7ce3a3fca56038092300ac0e8 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 21 Feb 2022 16:55:31 -0800 Subject: [PATCH] Fix non enabled telegram order taken --- api/logics.py | 2 -- api/messages.py | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/api/logics.py b/api/logics.py index cc88aec0..265924f2 100644 --- a/api/logics.py +++ b/api/logics.py @@ -7,8 +7,6 @@ from api.models import Order, LNPayment, MarketTick, User, Currency from api.messages import Telegram from decouple import config -from api.tasks import follow_send_payment - import math import ast diff --git a/api/messages.py b/api/messages.py index 11a24f51..704baf25 100644 --- a/api/messages.py +++ b/api/messages.py @@ -1,11 +1,13 @@ from decouple import config from secrets import token_urlsafe from api.models import Order -import requests +from api.utils import get_tor_session class Telegram(): ''' Simple telegram messages by requesting to API''' + session = get_tor_session() + def get_context(user): """returns context needed to enable TG notifications""" context = {} @@ -23,7 +25,7 @@ class Telegram(): return context - def send_message(user, text): + def send_message(self, user, text): """ sends a message to a user with telegram notifications enabled""" bot_token=config('TELEGRAM_TOKEN') @@ -31,7 +33,7 @@ class Telegram(): chat_id = user.profile.telegram_chat_id message_url = f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={text}' - response = requests.get(message_url).json() + response = self.session.get(message_url).json() print(response) return @@ -51,6 +53,9 @@ class Telegram(): @classmethod def order_taken(cls, order): user = order.maker + if not user.profile.telegram_enabled: + return + lang = user.profile.telegram_lang_code taker_nick = order.taker.username site = config('HOST_NAME')