A
A
axoN742019-10-25 11:46:59
PHP
axoN74, 2019-10-25 11:46:59

How to save an attachment in a message via vk_api?

Good afternoon! My bot can synthesize text from a text message into a voice message using the yandex speech kit.
Now I'm trying to do the opposite so that the bot responds to a voice message with text. Tell me, how can I save the received voice message?

$data = json_decode(file_get_contents('php://input')); 
$attchType = $data->object->attachments[0]->type;

if ($data->type == 'message_new') {
    
    if($attchType == 'audio_message') {
        
       //Как скачать полученное сообщение?
        
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
axoN74, 2019-10-25
@axoN74

Guys, thank you all! Found at random, this is how the code works, and saves the message.

if($attachType == 'audio_message') {
        
        file_put_contents('audiomsg.ogg', file_get_contents($data->object->attachments[0]->audio_message->link_ogg));
        
    }

M
Makssof, 2019-10-25
@makssof

file_put_contents('audiomsg.ogg', file_get_contents($data->object->attachments[0]->link_ogg))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question