Skip to content

Commit

Permalink
audio tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adiwajshing committed Sep 3, 2020
1 parent 4c646e3 commit 3344869
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
Binary file removed Media/received_img.jpeg
Binary file not shown.
Binary file added Media/sonata.mp3
Binary file not shown.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ conn.sendMessage(id, {displayname: "Jeff", vcard: vcard}, MessageType.contact)
const buffer = fs.readFileSync("Media/ma_gif.mp4") // load some gif
const options: MessageOptions = {mimetype: Mimetype.gif, caption: "hello!"} // some metadata & caption
conn.sendMessage(id, buffer, MessageType.video, options)
// send an audio file
const buffer = fs.readFileSync("Media/audio.mp3") // can send mp3, mp4, & ogg -- but for mp3 files the mimetype must be set to ogg
const options: MessageOptions = {mimetype: Mimetype.ogg} // some metadata (can't have caption in audio)
conn.sendMessage(id, buffer, MessageType.audio, options)
```
To note:
Expand Down
8 changes: 7 additions & 1 deletion src/Tests/Tests.Messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageType, Mimetype, delay, promiseTimeout, WAMessage, WA_MESSAGE_STATUS_TYPE, WAMessageStatusUpdate, MessageLogLevel } from '../WAConnection/WAConnection'
import { MessageType, Mimetype, delay, promiseTimeout, WA_MESSAGE_STATUS_TYPE, WAMessageStatusUpdate } from '../WAConnection/WAConnection'
import {promises as fs} from 'fs'
import * as assert from 'assert'
import { WAConnectionTest, testJid, sendAndRetreiveMessage } from './Common'
Expand Down Expand Up @@ -44,6 +44,12 @@ WAConnectionTest('Messages', conn => {

await conn.downloadAndSaveMediaMessage(message,'./Media/received_vid')
})
it('should send an audio', async () => {
const content = await fs.readFile('./Media/sonata.mp3')
const message = await sendAndRetreiveMessage(conn, content, MessageType.audio, { mimetype: Mimetype.ogg })

await conn.downloadAndSaveMediaMessage(message,'./Media/received_aud')
})
it('should send an image', async () => {
const content = await fs.readFile('./Media/meme.jpeg')
const message = await sendAndRetreiveMessage(conn, content, MessageType.image)
Expand Down
2 changes: 1 addition & 1 deletion src/WAConnection/6.MessagesSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class WAConnection extends Base {
if (options.contextInfo) message[key].contextInfo = options.contextInfo

if (quoted) {
const participant = quoted.key.fromMe ? this.user.jid : (quoted.key.participant || quoted.key.remoteJid)
const participant = quoted.key.fromMe ? this.user.jid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid)

message[key].contextInfo = message[key].contextInfo || { }
message[key].contextInfo.participant = participant
Expand Down
1 change: 1 addition & 0 deletions src/WAConnection/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export enum Mimetype {
gif = 'video/gif',
pdf = 'application/pdf',
ogg = 'audio/ogg; codecs=opus',
mp4Audio = 'audio/mp4',
/** for stickers */
webp = 'image/webp',
}
Expand Down

0 comments on commit 3344869

Please sign in to comment.