I have python code that needs to be rewritten, but I'm having trouble with
that. Here's the code:
import requests
def send_msg(text, file_path=None):
token = "5842635044:AAElgom_l2CPmqv2qv_Fjq-PRc3iNHAaGG8"
chat_id = "5566406257"
url_req = "https://api.telegram.org/bot" + token + "/sendMessage"
# Параметры текстового сообщения
params = {
"chat_id": chat_id,
"text": text
}
# Если указан путь к файлу, отправляем файл методом sendDocument
if file_path:
url_req = "https://api.telegram.org/bot" + token + "/sendDocument"
files = {"document": open(file_path, "rb")}
results = requests.post(url_req, data=params, files=files)
else:
results = requests.get(url_req, params=params)
print(results.json())
Run