welcomecenterbot/bot/handlers/handle_feedback.py
2023-09-17 13:01:19 +03:00

59 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
from api import (
send_message,
forward_message,
delete_message,
get_chat_administrators,
)
from handlers.send_button import show_request_msg
from utils.mention import userdata_extract
from storage import storage, Profile
from config import FEEDBACK_CHAT_ID
async def handle_feedback(msg, state):
mid = msg["message_id"]
cid = msg["chat"]["id"]
uid = msg["from"]["id"]
if msg["text"] == "/start":
r = await send_message(cid, "Напишите своё сообщение для администрации чата")
print(r)
elif state.is_talking(uid):
r = await forward_message(cid, mid, state.talking[uid])
print(r)
state.aho(uid)
else:
r = await forward_message(cid, mid, FEEDBACK_CHAT_ID)
print(r)
support_msg_id = r["result"]["message_id"]
# сохранение айди сообщения в приватной переписке с ботом
storage.set(
f"fbk-{support_msg_id}",
json.dumps(
{"author_id": uid, "message_id": mid, "chat_id": cid}
),
)
async def handle_answer(msg):
answered_msg = msg["reply_to_message"]
r = await get_chat_administrators(msg["chat"]["id"])
print(r)
admins = []
for a in r["result"]:
admins.append(a["user"]["id"])
if answered_msg["from"]["is_bot"] and msg["from"]["id"] in admins:
support_msg_id = str(answered_msg["message_id"])
# получение сохраненного информации о сообщении для ответа
stored_feedback = storage.get(f"fbk-{support_msg_id}")
if stored_feedback:
print("handle an answer from feedback group")
stored_feedback = json.loads(stored_feedback)
r = await send_message(
f'{stored_feedback["chat_id"]}',
msg["text"],
reply_to=stored_feedback["message_id"],
)
print(r)