mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
typo: retreive -> retrieve (#371)
This commit is contained in:
@@ -30,7 +30,7 @@ export const makeConnection = () => {
|
||||
return conn
|
||||
}
|
||||
|
||||
export async function sendAndRetreiveMessage(conn: WAConnection, content, type: MessageType, options: MessageOptions = {}, recipientJid = testJid) {
|
||||
export async function sendAndRetrieveMessage(conn: WAConnection, content, type: MessageType, options: MessageOptions = {}, recipientJid = testJid) {
|
||||
const response = await conn.sendMessage(recipientJid, content, type, options)
|
||||
const {messages} = await conn.loadMessages(recipientJid, 10)
|
||||
const message = messages.find (m => m.key.id === response.key.id)
|
||||
@@ -73,4 +73,4 @@ export const assertChatDBIntegrity = (conn: WAConnection) => {
|
||||
[]
|
||||
)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MessageType, GroupSettingChange, delay, ChatModification, whatsappID } from '../WAConnection'
|
||||
import * as assert from 'assert'
|
||||
import { WAConnectionTest, testJid, sendAndRetreiveMessage } from './Common'
|
||||
import { WAConnectionTest, testJid, sendAndRetrieveMessage } from './Common'
|
||||
|
||||
WAConnectionTest('Groups', (conn) => {
|
||||
let gid: string
|
||||
@@ -15,12 +15,12 @@ WAConnectionTest('Groups', (conn) => {
|
||||
|
||||
console.log('created group: ' + JSON.stringify(response))
|
||||
})
|
||||
it('should retreive group invite code', async () => {
|
||||
it('should retrieve group invite code', async () => {
|
||||
const code = await conn.groupInviteCode(gid)
|
||||
assert.ok(code)
|
||||
assert.strictEqual(typeof code, 'string')
|
||||
})
|
||||
it('should retreive group metadata', async () => {
|
||||
it('should retrieve group metadata', async () => {
|
||||
const metadata = await conn.groupMetadata(gid)
|
||||
assert.strictEqual(metadata.id, gid)
|
||||
assert.strictEqual(metadata.participants.filter((obj) => obj.jid.split('@')[0] === testJid.split('@')[0]).length, 1)
|
||||
@@ -49,10 +49,10 @@ WAConnectionTest('Groups', (conn) => {
|
||||
assert.strictEqual(metadata.desc, newDesc)
|
||||
})
|
||||
it('should send a message on the group', async () => {
|
||||
await sendAndRetreiveMessage(conn, 'Hello!', MessageType.text, {}, gid)
|
||||
await sendAndRetrieveMessage(conn, 'Hello!', MessageType.text, {}, gid)
|
||||
})
|
||||
it('should delete a message on the group', async () => {
|
||||
const message = await sendAndRetreiveMessage(conn, 'Hello!', MessageType.text, {}, gid)
|
||||
const message = await sendAndRetrieveMessage(conn, 'Hello!', MessageType.text, {}, gid)
|
||||
await delay(1500)
|
||||
await conn.deleteMessage(message.key)
|
||||
})
|
||||
@@ -185,4 +185,4 @@ WAConnectionTest('Groups', (conn) => {
|
||||
await conn.modifyChat(gid, 'delete')
|
||||
await waitForEvent
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { MessageType, Mimetype, delay, promiseTimeout, WA_MESSAGE_STATUS_TYPE, generateMessageID, WAMessage } from '../WAConnection'
|
||||
import { promises as fs } from 'fs'
|
||||
import * as assert from 'assert'
|
||||
import { WAConnectionTest, testJid, sendAndRetreiveMessage } from './Common'
|
||||
import { WAConnectionTest, testJid, sendAndRetrieveMessage } from './Common'
|
||||
|
||||
WAConnectionTest('Messages', conn => {
|
||||
|
||||
it('should send a text message', async () => {
|
||||
const message = await sendAndRetreiveMessage(conn, 'hello fren', MessageType.text)
|
||||
const message = await sendAndRetrieveMessage(conn, 'hello fren', MessageType.text)
|
||||
assert.strictEqual(message.message.conversation || message.message.extendedTextMessage?.text, 'hello fren')
|
||||
})
|
||||
it('should send a pending message', async () => {
|
||||
const message = await sendAndRetreiveMessage(conn, 'hello fren', MessageType.text, { waitForAck: false })
|
||||
const message = await sendAndRetrieveMessage(conn, 'hello fren', MessageType.text, { waitForAck: false })
|
||||
|
||||
await new Promise(resolve => conn.on('chat-update', update => {
|
||||
if (update.jid === testJid &&
|
||||
@@ -33,7 +33,7 @@ WAConnectionTest('Messages', conn => {
|
||||
})
|
||||
it('should send a link preview', async () => {
|
||||
const text = 'hello this is from https://www.github.com/adiwajshing/Baileys'
|
||||
const message = await sendAndRetreiveMessage(conn, text, MessageType.text, { detectLinks: true })
|
||||
const message = await sendAndRetrieveMessage(conn, text, MessageType.text, { detectLinks: true })
|
||||
const received = message.message.extendedTextMessage
|
||||
|
||||
assert.strictEqual(received.text, text)
|
||||
@@ -43,7 +43,7 @@ WAConnectionTest('Messages', conn => {
|
||||
})
|
||||
it('should quote a message', async () => {
|
||||
const quoted = (await conn.loadMessages(testJid, 2)).messages[0]
|
||||
const message = await sendAndRetreiveMessage(conn, 'hello fren 2', MessageType.extendedText, { quoted })
|
||||
const message = await sendAndRetrieveMessage(conn, 'hello fren 2', MessageType.extendedText, { quoted })
|
||||
assert.strictEqual(
|
||||
message.message.extendedTextMessage.contextInfo.stanzaId,
|
||||
quoted.key.id
|
||||
@@ -61,33 +61,33 @@ WAConnectionTest('Messages', conn => {
|
||||
}
|
||||
})
|
||||
it('should send a gif', async () => {
|
||||
const message = await sendAndRetreiveMessage(conn, { url: './Media/ma_gif.mp4' }, MessageType.video, { mimetype: Mimetype.gif })
|
||||
const message = await sendAndRetrieveMessage(conn, { url: './Media/ma_gif.mp4' }, MessageType.video, { mimetype: Mimetype.gif })
|
||||
|
||||
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.mp4Audio })
|
||||
const message = await sendAndRetrieveMessage(conn, content, MessageType.audio, { mimetype: Mimetype.mp4Audio })
|
||||
// check duration was okay
|
||||
assert.ok (message.message.audioMessage.seconds > 0)
|
||||
await conn.downloadAndSaveMediaMessage(message,'./Media/received_aud')
|
||||
})
|
||||
it('should send an audio as a voice note', async () => {
|
||||
const content = await fs.readFile('./Media/sonata.mp3')
|
||||
const message = await sendAndRetreiveMessage(conn, content, MessageType.audio, { mimetype: Mimetype.mp4Audio, ptt: true })
|
||||
const message = await sendAndRetrieveMessage(conn, content, MessageType.audio, { mimetype: Mimetype.mp4Audio, ptt: true })
|
||||
|
||||
assert.ok (message.message.audioMessage.seconds > 0)
|
||||
assert.strictEqual (message.message?.audioMessage?.ptt, true)
|
||||
await conn.downloadAndSaveMediaMessage(message,'./Media/received_aud')
|
||||
})
|
||||
it('should send a jpeg image', async () => {
|
||||
const message = await sendAndRetreiveMessage(conn, { url: './Media/meme.jpeg' }, MessageType.image)
|
||||
const message = await sendAndRetrieveMessage(conn, { url: './Media/meme.jpeg' }, MessageType.image)
|
||||
assert.ok(message.message.imageMessage.jpegThumbnail.length > 0)
|
||||
const msg = await conn.downloadMediaMessage(message)
|
||||
assert.deepStrictEqual(msg, await fs.readFile('./Media/meme.jpeg'))
|
||||
})
|
||||
it('should send a remote jpeg image', async () => {
|
||||
const message = await sendAndRetreiveMessage(
|
||||
const message = await sendAndRetrieveMessage(
|
||||
conn,
|
||||
{ url: 'https://www.memestemplates.com/wp-content/uploads/2020/05/tom-with-phone.jpg' },
|
||||
MessageType.image
|
||||
@@ -97,13 +97,13 @@ WAConnectionTest('Messages', conn => {
|
||||
})
|
||||
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' })
|
||||
const message = await sendAndRetrieveMessage(conn, content, MessageType.image, { mimetype: 'image/png' })
|
||||
assert.ok (message.message?.imageMessage?.jpegThumbnail)
|
||||
await conn.downloadMediaMessage(message)
|
||||
})
|
||||
it('should send a sticker', async () => {
|
||||
const content = await fs.readFile('./Media/octopus.webp')
|
||||
const message = await sendAndRetreiveMessage(conn, content, MessageType.sticker)
|
||||
const message = await sendAndRetrieveMessage(conn, content, MessageType.sticker)
|
||||
|
||||
await conn.downloadMediaMessage(message)
|
||||
})
|
||||
@@ -152,13 +152,13 @@ WAConnectionTest('Messages', conn => {
|
||||
it('should send an image & quote', async () => {
|
||||
const quoted = (await conn.loadMessages(testJid, 2)).messages[0]
|
||||
const content = await fs.readFile('./Media/meme.jpeg')
|
||||
const message = await sendAndRetreiveMessage(conn, content, MessageType.image, { quoted })
|
||||
const message = await sendAndRetrieveMessage(conn, content, MessageType.image, { quoted })
|
||||
|
||||
await conn.downloadMediaMessage(message) // check for successful decoding
|
||||
assert.strictEqual(message.message.imageMessage.contextInfo.stanzaId, quoted.key.id)
|
||||
})
|
||||
it('should send a message & delete it', async () => {
|
||||
const message = await sendAndRetreiveMessage(conn, 'hello fren', MessageType.text)
|
||||
const message = await sendAndRetrieveMessage(conn, 'hello fren', MessageType.text)
|
||||
await delay (2000)
|
||||
await conn.deleteMessage (testJid, message.key)
|
||||
})
|
||||
@@ -169,14 +169,14 @@ WAConnectionTest('Messages', conn => {
|
||||
})
|
||||
it('should send media after close', async () => {
|
||||
const content = await fs.readFile('./Media/octopus.webp')
|
||||
await sendAndRetreiveMessage(conn, content, MessageType.sticker)
|
||||
await sendAndRetrieveMessage(conn, content, MessageType.sticker)
|
||||
|
||||
conn.close ()
|
||||
|
||||
await conn.connect ()
|
||||
|
||||
const content2 = await fs.readFile('./Media/cat.jpeg')
|
||||
await sendAndRetreiveMessage(conn, content2, MessageType.image)
|
||||
await sendAndRetrieveMessage(conn, content2, MessageType.image)
|
||||
})
|
||||
it('should fail to send a text message', async () => {
|
||||
const JID = '1234-1234@g.us'
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Presence, ChatModification, delay, newMessagesDB, WA_DEFAULT_EPHEMERAL,
|
||||
import { promises as fs } from 'fs'
|
||||
import * as assert from 'assert'
|
||||
import got from 'got'
|
||||
import { WAConnectionTest, testJid, sendAndRetreiveMessage } from './Common'
|
||||
import { WAConnectionTest, testJid, sendAndRetrieveMessage } from './Common'
|
||||
|
||||
WAConnectionTest('Misc', conn => {
|
||||
|
||||
@@ -160,7 +160,7 @@ WAConnectionTest('Misc', conn => {
|
||||
assert.ok(idx < idx2) // should move further down the array
|
||||
|
||||
await delay (2000)
|
||||
await sendAndRetreiveMessage(conn, 'test', MessageType.text)
|
||||
await sendAndRetrieveMessage(conn, 'test', MessageType.text)
|
||||
// should be unarchived
|
||||
const idx3 = conn.chats.all().findIndex(chat => chat.jid === testJid)
|
||||
assert.strictEqual(idx, idx3) // should be back there
|
||||
@@ -359,7 +359,7 @@ WAConnectionTest('Misc', conn => {
|
||||
|
||||
await delay(1000)
|
||||
|
||||
let msg = await sendAndRetreiveMessage(
|
||||
let msg = await sendAndRetrieveMessage(
|
||||
conn,
|
||||
'This will go poof 😱',
|
||||
MessageType.text
|
||||
@@ -378,7 +378,7 @@ WAConnectionTest('Misc', conn => {
|
||||
|
||||
await delay(1000)
|
||||
|
||||
msg = await sendAndRetreiveMessage(
|
||||
msg = await sendAndRetrieveMessage(
|
||||
conn,
|
||||
'This will not go poof 😔',
|
||||
MessageType.text
|
||||
@@ -427,4 +427,4 @@ WAConnectionTest('Misc', conn => {
|
||||
assert.strictEqual(error.status, 422)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user