How to send an audio? what is the mimetype? and else..
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.
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:
You have to only fill the exported fields (beginning with capital letters). Define the recipient in the Info field as RemoteJid. The
Lengthis the length of the audio file in seconds.Typedescribes the mimetype, which is the actual type of the file. For images it is oftenimage/jpegand for audios sent by whatsapp the default isaudio/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 ofDocumentMessage. The only downside is, that it appears as an sent audio file and not as an spoken one. Finally you have to provide anio.Readerto the media struct, to provide the actual data. The easiest way is to useos.Open(filePath)to open a file and get a*File, which implementsio.Readeralready.