test send message
This commit is contained in:
23
main.py
23
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)
|
||||
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:
|
||||
print("Token not found.")
|
||||
raise Exception('something sent wrong!')
|
||||
Reference in New Issue
Block a user