pdf generatsiya qilish qoshildi

This commit is contained in:
behruz-dev
2025-11-27 15:53:42 +05:00
parent 380ba01e82
commit b59bad4425
5 changed files with 210 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
import os
# packages
import requests
# django
from django.conf import settings
def send_to_telegram(chat_id, file_path=None):
bot_token = settings.BOT_TOKEN
try:
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
data = {
"chat_id": chat_id,
"text": "Buyurtma uchun yuklangan PDF file",
"parse_mode": "HTML"
}
if file_path and os.path.exists(file_path):
url = f"https://api.telegram.org/bot{bot_token}/sendDocument"
with open(file_path, 'rb') as f:
files = {'document': f}
data = {'chat_id': chat_id}
requests.post(url, files=files, data=data)
return True
except Exception as e:
print(f"Telegram xatolik: {e}")
return False