test send message

This commit is contained in:
2024-11-16 22:27:40 +03:30
parent 893ad7bb83
commit b25f61c812

25
main.py
View File

@@ -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!')