-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUploadFileAsync.py
More file actions
31 lines (25 loc) · 976 Bytes
/
UploadFileAsync.py
File metadata and controls
31 lines (25 loc) · 976 Bytes
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
import asyncio
from maxbot_api_client_python.api import API, Config
from maxbot_api_client_python.types.constants import UploadType
from maxbot_api_client_python.utils import attach_image
async def main():
target_user_id = 123456789 # recipient user ID
try:
async with API(Config(
base_url="https://platform-api.max.ru",
token="YOUR_BOT_TOKEN"
)) as bot:
response = await bot.uploads.UploadFileAsync(
type=UploadType.image,
file_path="examples/assets/file.jpg"
)
if response and response.token:
await bot.messages.SendMessageAsync(
user_id=target_user_id,
attachments=[attach_image(token=response.token)]
)
print("File successfully sent to chat!")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(main())