-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_file_async.py
More file actions
32 lines (27 loc) · 1.12 KB
/
upload_file_async.py
File metadata and controls
32 lines (27 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import asyncio
from maxbot_api_client_python import API, Config
from maxbot_api_client_python.types.constants import UploadType
from maxbot_api_client_python.types.models import UploadFileReq, SendMessageReq
from maxbot_api_client_python.utils import attach_image
async def main():
try:
async with API(Config(
base_url="https://platform-api.max.ru",
token="YOUR_BOT_TOKEN"
)) as bot:
upload_request = UploadFileReq(
type=UploadType.IMAGE,
file_path="examples/assets/file.jpg"
)
response = await bot.uploads.upload_file_async(upload_request)
if response and response.token:
message_request = SendMessageReq(
user_id=123456789, # recipient user ID
attachments=[attach_image(token=response.token)]
)
await bot.messages.send_message_async(message_request)
print("File successfully sent to chat!")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(main())