import requests
import config
url = f"https://api.ok.ru/graph/me/fileUploadUrl?access_token={config.access_token}&type=IMAGE"
response1 = requests.get(url)
response1 = response1.json()
print(response1)
multiple_files = [
('images', ('bot.png', open('bot.png', 'rb'), 'image/png'))
]
response2 = requests.post(response1['url'], files=multiple_files)
response2 = response2.json()
print(response2)
chat_id = "chat:C7d78ad3d0000"
token = response2['photos'][response1['file_id']]['token']
print(token)
params = {
"recipient": {"chat_id": chat_id},
"message": {
"attachment": {
"type": "IMAGE",
"payload": {"token": token}
}
}
}
url = f"https://api.ok.ru/graph/{chat_id}/messages?access_token={config.access_token}"
response3 = requests.post(url, json=params, headers={"Content-Type": "application/json;charset=utf-8"})
response3 = response3.json()
print(response3)