Skip to content

Commit 8cea5e5

Browse files
committed
More logs
1 parent ae89ca4 commit 8cea5e5

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

social/utils/telegram_groups.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414

1515

1616
def get_chat_info(id: int) -> dict:
17-
return requests.post(
17+
resp = requests.post(
1818
f'https://api.telegram.org/bot{settings.TELEGRAM_BOT_TOKEN}/getChat',
1919
json={'chat_id': id},
20-
).json()
20+
)
21+
if not resp.ok:
22+
logger.error(resp.text)
23+
return {}
24+
else:
25+
return resp.json()
2126

2227

2328
def create_telegram_group(update: Update):
@@ -59,8 +64,14 @@ def approve_telegram_group(update: Update):
5964
logger.info("Telegram group %d validated (secret=%s)", group.id, text)
6065

6166

62-
def update_tg_chat(group: TelegramChat):
63-
chat_info = get_chat_info(group.chat_id)
67+
def update_tg_chat(group: TelegramChat | TelegramChannel):
68+
if isinstance(group, TelegramChat):
69+
chat_info = get_chat_info(group.chat_id)
70+
elif isinstance(group, TelegramChannel):
71+
chat_info = get_chat_info(group.channel_id)
72+
else:
73+
raise TypeError("Only TelegramChat and TelegramChannel are supported")
74+
logger.info("TG chat info: %s", chat_info)
6475
group.name = chat_info.get("title")
6576
group.description = chat_info.get("description")
6677
group.invite_link = chat_info.get("invite_link")

social/utils/vk_groups.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
settings = get_settings()
1313

1414

15-
def get_chat_info(peer_id):
15+
def get_chat_info(peer_id) -> dict:
1616
"""Получить название чата ВК"""
1717
conversation = requests.post(
1818
"https://api.vk.com/method/messages.getConversationsById",
@@ -87,7 +87,9 @@ def approve_vk_chat(request_data: dict[str]):
8787
def update_vk_chat(group: VkChat):
8888
"""Обновляет информацию о группе ВК"""
8989
chat_info = get_chat_info(group.peer_id)
90+
chat_invite = get_chat_invite_link(group.peer_id)
91+
logger.info("Chat info: %s, invite: %s", chat_info, chat_invite)
9092
group.name = chat_info.get("title")
9193
group.description = chat_info.get("description")
92-
group.invite_link = get_chat_invite_link(group.peer_id)
94+
group.invite_link = chat_invite
9395
return group

0 commit comments

Comments
 (0)