ruffed
This commit is contained in:
15
bot/api.py
15
bot/api.py
@@ -5,7 +5,7 @@ from bot.config import BOT_TOKEN
|
||||
import logging
|
||||
|
||||
# Create a logger instance
|
||||
logger = logging.getLogger('bot.api')
|
||||
logger = logging.getLogger("bot.api")
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
api_base = f"https://api.telegram.org/bot{BOT_TOKEN}/"
|
||||
@@ -14,17 +14,20 @@ api_base = f"https://api.telegram.org/bot{BOT_TOKEN}/"
|
||||
async def telegram_api(endpoint: str, json_data=None, **kwargs):
|
||||
try:
|
||||
url = api_base + f"{endpoint}?{urlencode(kwargs)}"
|
||||
is_polling = endpoint == 'getUpdates'
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
is_polling = endpoint == "getUpdates"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
async with aiohttp.ClientSession() as session:
|
||||
url = api_base + f"{endpoint}?{urlencode(kwargs)}"
|
||||
if not is_polling:
|
||||
logger.info(f' >>> {url} {json_data if json_data else ""}')
|
||||
async with session.get(url, data=json.dumps(json_data), headers=headers) as response:
|
||||
async with session.get(
|
||||
url, data=json.dumps(json_data), headers=headers
|
||||
) as response:
|
||||
data = await response.json()
|
||||
if not is_polling:
|
||||
logger.info(f' <<< {data}')
|
||||
logger.info(f" <<< {data}")
|
||||
return data
|
||||
except Exception as ex:
|
||||
except Exception:
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
|
Reference in New Issue
Block a user