Skip to content

Commit

Permalink
More explicit media sending
Browse files Browse the repository at this point in the history
  • Loading branch information
adiwajshing committed Oct 1, 2020
1 parent 8277590 commit 67d82b4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
Binary file added Media/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/Tests/Tests.Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ WAConnectionTest('Messages', conn => {
it('should send an image', async () => {
const content = await fs.readFile('./Media/meme.jpeg')
const message = await sendAndRetreiveMessage(conn, content, MessageType.image)

assert.ok (message.message?.imageMessage?.jpegThumbnail)
await conn.downloadMediaMessage(message)
})
it('should send a png image', async () => {
const content = await fs.readFile('./Media/icon.png')
const message = await sendAndRetreiveMessage(conn, content, MessageType.image, { mimetype: 'image/png' })
assert.ok (message.message?.imageMessage?.jpegThumbnail)
await conn.downloadMediaMessage(message)
})
it('should send a sticker', async () => {
Expand Down
6 changes: 5 additions & 1 deletion src/WAConnection/6.MessagesSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export class WAConnection extends Base {
case MessageType.contact:
m.contactMessage = WAMessageProto.ContactMessage.create(message as any)
break
default:
case MessageType.image:
case MessageType.sticker:
case MessageType.document:
case MessageType.video:
case MessageType.audio:
m = await this.prepareMessageMedia(message as Buffer, type, options)
break
}
Expand Down
2 changes: 1 addition & 1 deletion src/WAConnection/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export const mediaMessageSHA256B64 = (message: WAMessageContent) => {

/** generates a thumbnail for a given media, if required */
export async function generateThumbnail(buffer: Buffer, mediaType: MessageType, info: MessageOptions) {
if (info.thumbnail === null || info.thumbnail) {
if ('thumbnail' in info) {
// don't do anything if the thumbnail is already provided, or is null
if (mediaType === MessageType.audio) {
throw new Error('audio messages cannot have thumbnails')
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@
integrity sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==

"@types/ws@^7.2.6":
version "7.2.6"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.2.6.tgz#516cbfb818310f87b43940460e065eb912a4178d"
integrity sha512-Q07IrQUSNpr+cXU4E4LtkSIBPie5GLZyyMC1QtQYRLWz701+XcoVygGUZgvLqElq1nU4ICldMYPnexlBsg3dqQ==
version "7.2.7"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.2.7.tgz#362ad1a1d62721bdb725e72c8cccf357078cf5a3"
integrity sha512-UUFC/xxqFLP17hTva8/lVT0SybLUrfSD9c+iapKb0fEiC8uoDbA+xuZ3pAN603eW+bY8ebSMLm9jXdIPnD0ZgA==
dependencies:
"@types/node" "*"

Expand Down Expand Up @@ -1288,9 +1288,9 @@ map-obj@^1.0.0, map-obj@^1.0.1:
integrity sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=

marked@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/marked/-/marked-1.1.1.tgz#e5d61b69842210d5df57b05856e0c91572703e6a"
integrity sha512-mJzT8D2yPxoPh7h0UXkB+dBj4FykPJ2OIfxAWeIHrvoHDkFxukV/29QxoFQoPM6RLEwhIFdJpmKBlqVM3s2ZIw==
version "1.2.0"
resolved "https://registry.yarnpkg.com/marked/-/marked-1.2.0.tgz#7221ce2395fa6cf6d722e6f2871a32d3513c85ca"
integrity sha512-tiRxakgbNPBr301ihe/785NntvYyhxlqcL3YaC8CaxJQh7kiaEtrN9B/eK2I2943Yjkh5gw25chYFDQhOMCwMA==

meow@^3.3.0:
version "3.7.0"
Expand Down

0 comments on commit 67d82b4

Please sign in to comment.