Spaces:
Paused
Paused
Commit
·
ff0cc88
1
Parent(s):
f3cea98
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,24 +6,25 @@ from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
|
| 6 |
from config import api_key
|
| 7 |
|
| 8 |
# تعريف الدالة الخاصة برفع الملفات
|
| 9 |
-
def upload_file(
|
| 10 |
-
|
| 11 |
-
file_url = update.message.text
|
| 12 |
-
|
|
|
|
| 13 |
file = requests.get(file_url)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
# تعريف الدالة الخاصة بإرسال رسالة استجابة
|
| 29 |
def reply_message(update, context ):
|
|
|
|
| 6 |
from config import api_key
|
| 7 |
|
| 8 |
# تعريف الدالة الخاصة برفع الملفات
|
| 9 |
+
def upload_file(bot, update):
|
| 10 |
+
# Get the file URL from the user message
|
| 11 |
+
file_url = update.message.text
|
| 12 |
+
|
| 13 |
+
# Download the file from the URL
|
| 14 |
file = requests.get(file_url)
|
| 15 |
+
|
| 16 |
+
# Upload the file to Telegram using the bot API
|
| 17 |
+
url = f"https://api.telegram.org/bot{bot.token}/sendDocument"
|
| 18 |
+
data = {"chat_id": update.message.chat_id}
|
| 19 |
+
files = {"document": file.content}
|
| 20 |
+
response = requests.post(url, data=data, files=files)
|
| 21 |
+
|
| 22 |
+
# Check if the file was uploaded successfully
|
| 23 |
+
if response.status_code == 200:
|
| 24 |
+
update.message.reply_text("File uploaded successfully to Telegram!")
|
| 25 |
+
else:
|
| 26 |
+
update.message.reply_text("Failed to upload file to Telegram.")
|
| 27 |
+
|
| 28 |
|
| 29 |
# تعريف الدالة الخاصة بإرسال رسالة استجابة
|
| 30 |
def reply_message(update, context ):
|