forward = json.dumps({'peer_id': 2000000000 + chatid,
'conversation_message_ids': [event.object.message['conversation_message_id']],
'is_reply': True})
upload = VkUpload(vk)
graffiti = upload.graffiti(image='filename.png', peer_id=peer_id)
owner_id = graffiti['graffiti']['owner_id']
graffiti_id = graffiti['graffiti']['id']
attachment = 'doc{}_{}'.format(owner_id, graffiti_id)
vk.messages.send(peer_id=peer_ids, attachment=attachment, random_id=get_random_id())
import vk_api
from vk_api import VkUpload
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id
import requests
token = ""
session = requests.Session()
auth = vk_api.VkApi(token=token, api_version='5.131')
vk = auth.get_api()
long_poll = VkLongPoll(auth)
def upload_audio_msg(peer_ids):
upload = VkUpload(vk)
audio_msg = upload.audio_message('filename.mp3', peer_id=peer_ids)
attachment = 'doc{}_{}'.format(audio_msg['audio_message']['owner_id'], audio_msg['audio_message']['id'])
vk.messages.send(peer_id=peer_ids, attachment=attachment, random_id=get_random_id())
while True:
try:
for event in long_poll.listen():
if event.type == VkEventType.MESSAGE_NEW:
peer_id = event.peer_id
if event.from_me:
if event.text == 'test':
upload_audio_msg(peer_id)
except Exception as er:
print(er)