mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
unit test for quoting groups
This commit is contained in:
@@ -38,7 +38,6 @@
|
|||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"protobufjs": "^6.9.0",
|
"protobufjs": "^6.9.0",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"user-agents": "^1.0.559",
|
|
||||||
"ws": "^7.3.0"
|
"ws": "^7.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MessageType, GroupSettingChange, createTimeout, ChatModification } from '../WAConnection/WAConnection'
|
import { MessageType, GroupSettingChange, createTimeout, ChatModification, whatsappID } from '../WAConnection/WAConnection'
|
||||||
import * as assert from 'assert'
|
import * as assert from 'assert'
|
||||||
import { WAConnectionTest, testJid } from './Common'
|
import { WAConnectionTest, testJid, sendAndRetreiveMessage } from './Common'
|
||||||
|
|
||||||
WAConnectionTest('Groups', (conn) => {
|
WAConnectionTest('Groups', (conn) => {
|
||||||
let gid: string
|
let gid: string
|
||||||
@@ -31,6 +31,17 @@ WAConnectionTest('Groups', (conn) => {
|
|||||||
it('should send a message on the group', async () => {
|
it('should send a message on the group', async () => {
|
||||||
await conn.sendMessage(gid, 'hello', MessageType.text)
|
await conn.sendMessage(gid, 'hello', MessageType.text)
|
||||||
})
|
})
|
||||||
|
it('should quote a message on the group', async () => {
|
||||||
|
const messages = await conn.loadConversation (gid, 20)
|
||||||
|
const quotableMessage = messages.find (m => m.message)
|
||||||
|
assert.ok (quotableMessage, 'need at least one message')
|
||||||
|
|
||||||
|
const response = await conn.sendMessage(gid, 'hello', MessageType.extendedText, {quoted: messages[0]})
|
||||||
|
const messagesNew = await conn.loadConversation(gid, 10, null, true)
|
||||||
|
const message = messagesNew.find (m => m.key.id === response.key.id)?.message?.extendedTextMessage
|
||||||
|
assert.ok(message)
|
||||||
|
assert.equal (message.contextInfo.stanzaId, quotableMessage.key.id)
|
||||||
|
})
|
||||||
it('should update the subject', async () => {
|
it('should update the subject', async () => {
|
||||||
const subject = 'V Cool Title'
|
const subject = 'V Cool Title'
|
||||||
await conn.groupUpdateSubject(gid, subject)
|
await conn.groupUpdateSubject(gid, subject)
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class WAConnection extends Base {
|
|||||||
|
|
||||||
let receivedContacts = false
|
let receivedContacts = false
|
||||||
let receivedMessages = false
|
let receivedMessages = false
|
||||||
let convoResolve
|
let convoResolve: () => void
|
||||||
|
|
||||||
this.log('waiting for chats & contacts', MessageLogLevel.info) // wait for the message with chats
|
this.log('waiting for chats & contacts', MessageLogLevel.info) // wait for the message with chats
|
||||||
const waitForConvos = () =>
|
const waitForConvos = () =>
|
||||||
@@ -91,7 +91,7 @@ export class WAConnection extends Base {
|
|||||||
|
|
||||||
if (messages) {
|
if (messages) {
|
||||||
messages.reverse().forEach (([, __, message]: ['message', null, WAMessage]) => {
|
messages.reverse().forEach (([, __, message]: ['message', null, WAMessage]) => {
|
||||||
const jid = message.key.remoteJid.replace('@s.whatsapp.net', '@c.us')
|
const jid = message.key.remoteJid
|
||||||
const chat = chats.get(jid)
|
const chat = chats.get(jid)
|
||||||
chat?.messages.unshift (message)
|
chat?.messages.unshift (message)
|
||||||
})
|
})
|
||||||
@@ -114,6 +114,7 @@ export class WAConnection extends Base {
|
|||||||
this.log (`unexpectedly got null chat: ${item}, ${chat}`, MessageLogLevel.info)
|
this.log (`unexpectedly got null chat: ${item}, ${chat}`, MessageLogLevel.info)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
chat.jid = Utils.whatsappID (chat.jid)
|
||||||
chat.count = +chat.count
|
chat.count = +chat.count
|
||||||
chat.messages = []
|
chat.messages = []
|
||||||
chats.insert (chat) // chats data (log json to see what it looks like)
|
chats.insert (chat) // chats data (log json to see what it looks like)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
WAUrlInfo,
|
WAUrlInfo,
|
||||||
WAMessageContent, WAMetric, WAFlag, WANode, WAMessage, WAMessageProto, BaileysError, MessageLogLevel, WA_MESSAGE_STATUS_TYPE
|
WAMessageContent, WAMetric, WAFlag, WANode, WAMessage, WAMessageProto, BaileysError, MessageLogLevel, WA_MESSAGE_STATUS_TYPE
|
||||||
} from './Constants'
|
} from './Constants'
|
||||||
import { generateMessageID, sha256, hmacSign, aesEncrypWithIV, randomBytes, generateThumbnail, getMediaKeys, decodeMediaMessageBuffer, extensionForMediaMessage } from './Utils'
|
import { generateMessageID, sha256, hmacSign, aesEncrypWithIV, randomBytes, generateThumbnail, getMediaKeys, decodeMediaMessageBuffer, extensionForMediaMessage, whatsappID } from './Utils'
|
||||||
|
|
||||||
export class WAConnection extends Base {
|
export class WAConnection extends Base {
|
||||||
/** Get the message info, who has read it, who its been delivered to */
|
/** Get the message info, who has read it, who its been delivered to */
|
||||||
@@ -328,7 +328,7 @@ export class WAConnection extends Base {
|
|||||||
if (!options.timestamp) options.timestamp = new Date() // set timestamp to now
|
if (!options.timestamp) options.timestamp = new Date() // set timestamp to now
|
||||||
|
|
||||||
// prevent an annoying bug (WA doesn't accept sending messages with '@c.us')
|
// prevent an annoying bug (WA doesn't accept sending messages with '@c.us')
|
||||||
id = id.replace ('@c.us', '@s.whatsapp')
|
id = whatsappID (id)
|
||||||
|
|
||||||
const key = Object.keys(message)[0]
|
const key = Object.keys(message)[0]
|
||||||
const timestamp = options.timestamp.getTime()/1000
|
const timestamp = options.timestamp.getTime()/1000
|
||||||
|
|||||||
@@ -29,10 +29,9 @@ function hashCode(s: string) {
|
|||||||
}
|
}
|
||||||
export const waChatUniqueKey = (c: WAChat) => ((+c.t*100000) + (hashCode(c.jid)%100000))*-1 // -1 to sort descending
|
export const waChatUniqueKey = (c: WAChat) => ((+c.t*100000) + (hashCode(c.jid)%100000))*-1 // -1 to sort descending
|
||||||
|
|
||||||
/*export function userAgentString (browser) {
|
export function whatsappID (jid: string) {
|
||||||
const agent = new UserAgent (new RegExp(browser))
|
return jid.replace ('@c.us', '@s.whatsapp.net')
|
||||||
return agent.toString ()
|
}
|
||||||
}*/
|
|
||||||
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
||||||
export function aesDecrypt(buffer: Buffer, key: Buffer) {
|
export function aesDecrypt(buffer: Buffer, key: Buffer) {
|
||||||
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16))
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16))
|
||||||
|
|||||||
Reference in New Issue
Block a user