-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUploadFile.py
More file actions
41 lines (35 loc) · 1.23 KB
/
UploadFile.py
File metadata and controls
41 lines (35 loc) · 1.23 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
33
34
35
36
37
38
39
40
41
import logging
from maxbot_api_client_python.api import API, Config
from maxbot_api_client_python.types.models import *
from maxbot_api_client_python.utils import attach_image
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
log = logging.getLogger(__name__)
def main():
try:
bot = API(Config(
base_url="https://platform-api.max.ru", # Base url for MAX API requests
token="YOUR_BOT_TOKEN", # Max bot token
global_rps=25,
timeout=35
))
except ValueError as e:
log.error(f"Initialization error: {e}")
return
target_user_id=123456789 # recipient user ID
try:
file_info = bot.uploads.UploadFile(UploadFileReq(
type="image",
file_path="examples/assets/file.jpg"
))
if file_info and file_info.token:
bot.messages.SendMessage(SendMessageReq(
user_id=target_user_id,
attachments=[attach_image(token=file_info.token)]
))
log.info("File successfully sent to chat!")
except Exception as e:
log.error(f"Error: {e}")
finally:
bot.close()
if __name__ == "__main__":
main()