Skip to content

Commit

Permalink
fix: results in alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Jan 20, 2024
1 parent 67c3805 commit 6114a0a
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions insights/insights/doctype/insights_alert/insights_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,15 @@ def send_email_alert(self):

def evaluate_condition(self, for_validate=False):
query = frappe.get_doc("Insights Query", self.query)
results = (
query.fetch_results()
if not for_validate
else frappe.parse_json(query.results)
)
results = query.fetch_results() if not for_validate else query.retrieve_results()

if not results:
return False

column_names = [d.get("label") for d in results[0]]
results = DataFrame(results[1:], columns=column_names)

return frappe.safe_eval(
self.condition, eval_locals=frappe._dict(results=results, any=any)
)
return frappe.safe_eval(self.condition, eval_locals=frappe._dict(results=results, any=any))

def evaluate_message(self):
query = frappe.get_doc("Insights Query", self.query)
Expand Down Expand Up @@ -115,9 +109,7 @@ def send_alerts():

class Telegram:
def __init__(self, chat_id: str = None):
self.token = frappe.get_single("Insights Settings").get_password(
"telegram_api_token"
)
self.token = frappe.get_single("Insights Settings").get_password("telegram_api_token")
if not self.token:
frappe.throw("Telegram Bot Token not set in Insights Settings")

Expand All @@ -128,9 +120,7 @@ def send(self, message):
try:
text = message[: telegram.MAX_MESSAGE_LENGTH]
parse_mode = telegram.ParseMode.MARKDOWN
return self.bot.send_message(
chat_id=self.chat_id, text=text, parse_mode=parse_mode
)
return self.bot.send_message(chat_id=self.chat_id, text=text, parse_mode=parse_mode)
except Exception:
frappe.log_error("Telegram Bot Error")
raise
Expand Down

0 comments on commit 6114a0a

Please sign in to comment.