From b25f61c8122432b207f0ea5224241a64dfe3ffee Mon Sep 17 00:00:00 2001 From: Meghdad Date: Sat, 16 Nov 2024 22:27:40 +0330 Subject: [PATCH] test send message --- main.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 5b76e21..0d3e07c 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,24 @@ import os +import time +import requests token = os.getenv("EITAAYAR_TOKEN") +chat_id = os.getenv("CHAT_ID") -if token: - print("Token received successfully!") - print("token is:", token) -else: - print("Token not found.") +if not token: + raise EnvironmentError("MY_SECRET_TOKEN is not set!") + +if not chat_id: + raise EnvironmentError("CHAT_ID is not set!") + +def send_message(text: str) -> dict: + sent_at: int = int(time.time()) + url = f'https://eitaayar.ir/api/{token}/sendMessage?chat_id={chat_id}&text={text}&title={sent_at=}' + return requests.get(url).json() + +response = send_message('test') +if not response.get('ok'): + if response.get('description'): + raise Exception(response.get('description')) + else: + raise Exception('something sent wrong!') \ No newline at end of file