Отправит все что в папке temp
TOKEN = "1234646854fdghdfhfghfghssfhhgh"
def send_group_img(chat_id, text):
temp_files_list = list()
media = list()
files = dict()
for filename in os.listdir("temp"):
temp_files_list.append(f'{os.getcwd()}\\temp\\{filename}')
for f in enumerate(temp_files_list):
files[f"random-name-{f[0]}"] = open(f[1], "rb")
if f[0] == 0:
media.append({"type": "photo",
"media": f"attach://random-name-{f[0]}",
"caption": text}
)
else:
media.append({"type": "photo",
"media": f"attach://random-name-{f[0]}"})
params = {
"chat_id": chat_id, "media": str(media).replace("'", '"')}
request_url = "https://api.telegram.org/bot" + TOKEN + "/sendMediaGroup"
result = requests.post(request_url, params=params, files=files)
if result.status_code == 200:
return True
else:
return False