Go-whatsapp: Send Audio

Created on 16 Aug 2018  Â·  1Comment  Â·  Source: Rhymen/go-whatsapp

How to send an audio? what is the mimetype? and else..

Most helpful comment

Sending an audio is basicly the same as sending an image. The sending of an image is provided here. The AudioMessage is structured like this:

type AudioMessage struct {
    Info          MessageInfo
    Length        uint32
    Type          string
    Content       io.Reader
    url           string
    mediaKey      []byte
    fileEncSha256 []byte
    fileSha256    []byte
    fileLength    uint64
}

You have to only fill the exported fields (beginning with capital letters). Define the recipient in the Info field as RemoteJid. The Length is the length of the audio file in seconds. Type describes the mimetype, which is the actual type of the file. For images it is often image/jpeg and for audios sent by whatsapp the default is audio/ogg; codecs=opus. I do not know if whatsapp supports sending audio files in other formats. But you can send every kind of file with the help of DocumentMessage. The only downside is, that it appears as an sent audio file and not as an spoken one. Finally you have to provide an io.Reader to the media struct, to provide the actual data. The easiest way is to use os.Open(filePath) to open a file and get a *File, which implements io.Reader already.

>All comments

Sending an audio is basicly the same as sending an image. The sending of an image is provided here. The AudioMessage is structured like this:

type AudioMessage struct {
    Info          MessageInfo
    Length        uint32
    Type          string
    Content       io.Reader
    url           string
    mediaKey      []byte
    fileEncSha256 []byte
    fileSha256    []byte
    fileLength    uint64
}

You have to only fill the exported fields (beginning with capital letters). Define the recipient in the Info field as RemoteJid. The Length is the length of the audio file in seconds. Type describes the mimetype, which is the actual type of the file. For images it is often image/jpeg and for audios sent by whatsapp the default is audio/ogg; codecs=opus. I do not know if whatsapp supports sending audio files in other formats. But you can send every kind of file with the help of DocumentMessage. The only downside is, that it appears as an sent audio file and not as an spoken one. Finally you have to provide an io.Reader to the media struct, to provide the actual data. The easiest way is to use os.Open(filePath) to open a file and get a *File, which implements io.Reader already.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sbruder picture sbruder  Â·  9Comments

jhow2892 picture jhow2892  Â·  3Comments

tkovs picture tkovs  Â·  3Comments

bamjohn2222 picture bamjohn2222  Â·  5Comments

highness28 picture highness28  Â·  5Comments