nvd commited on
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -121,19 +121,25 @@ async def send_message(chat_id, text, reply_markup=None):
|
|
| 121 |
params["reply_markup"] = json.dumps(reply_markup)
|
| 122 |
return await bale_request("sendMessage", params)
|
| 123 |
|
|
|
|
|
|
|
| 124 |
async def send_document_file(chat_id, file_path, caption=""):
|
| 125 |
-
"""Upload a local file to Bale using sendDocument
|
| 126 |
url = BALE_API + "sendDocument"
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
async def answer_callback(callback_id, text=""):
|
| 139 |
params = {
|
|
|
|
| 121 |
params["reply_markup"] = json.dumps(reply_markup)
|
| 122 |
return await bale_request("sendMessage", params)
|
| 123 |
|
| 124 |
+
import httpx # add near the top imports
|
| 125 |
+
|
| 126 |
async def send_document_file(chat_id, file_path, caption=""):
|
| 127 |
+
"""Upload a local file to Bale using sendDocument (httpx, multipart)."""
|
| 128 |
url = BALE_API + "sendDocument"
|
| 129 |
+
data = {"chat_id": str(chat_id)}
|
| 130 |
+
if caption:
|
| 131 |
+
data["caption"] = caption
|
| 132 |
+
|
| 133 |
+
with open(file_path, "rb") as f:
|
| 134 |
+
files = {"document": f} # identical to the working TG bot
|
| 135 |
+
async with httpx.AsyncClient() as client:
|
| 136 |
+
resp = await client.post(url, data=data, files=files, timeout=60)
|
| 137 |
+
if resp.status_code != 200:
|
| 138 |
+
logger.error(f"❌ Bale upload failed: {resp.status_code} {resp.text}")
|
| 139 |
+
return {"ok": False, "description": resp.text}
|
| 140 |
+
result = resp.json()
|
| 141 |
+
logger.info(f"📨 sendDocument (file) response: {result}")
|
| 142 |
+
return result
|
| 143 |
|
| 144 |
async def answer_callback(callback_id, text=""):
|
| 145 |
params = {
|