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:
@@ -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 { WAConnectionTest, testJid } from './Common'
|
||||
import { WAConnectionTest, testJid, sendAndRetreiveMessage } from './Common'
|
||||
|
||||
WAConnectionTest('Groups', (conn) => {
|
||||
let gid: string
|
||||
@@ -31,6 +31,17 @@ WAConnectionTest('Groups', (conn) => {
|
||||
it('should send a message on the group', async () => {
|
||||
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 () => {
|
||||
const subject = 'V Cool Title'
|
||||
await conn.groupUpdateSubject(gid, subject)
|
||||
|
||||
@@ -72,7 +72,7 @@ export class WAConnection extends Base {
|
||||
|
||||
let receivedContacts = false
|
||||
let receivedMessages = false
|
||||
let convoResolve
|
||||
let convoResolve: () => void
|
||||
|
||||
this.log('waiting for chats & contacts', MessageLogLevel.info) // wait for the message with chats
|
||||
const waitForConvos = () =>
|
||||
@@ -91,7 +91,7 @@ export class WAConnection extends Base {
|
||||
|
||||
if (messages) {
|
||||
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)
|
||||
chat?.messages.unshift (message)
|
||||
})
|
||||
@@ -114,6 +114,7 @@ export class WAConnection extends Base {
|
||||
this.log (`unexpectedly got null chat: ${item}, ${chat}`, MessageLogLevel.info)
|
||||
return
|
||||
}
|
||||
chat.jid = Utils.whatsappID (chat.jid)
|
||||
chat.count = +chat.count
|
||||
chat.messages = []
|
||||
chats.insert (chat) // chats data (log json to see what it looks like)
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
WAUrlInfo,
|
||||
WAMessageContent, WAMetric, WAFlag, WANode, WAMessage, WAMessageProto, BaileysError, MessageLogLevel, WA_MESSAGE_STATUS_TYPE
|
||||
} 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 {
|
||||
/** 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
|
||||
|
||||
// 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 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 function userAgentString (browser) {
|
||||
const agent = new UserAgent (new RegExp(browser))
|
||||
return agent.toString ()
|
||||
}*/
|
||||
export function whatsappID (jid: string) {
|
||||
return jid.replace ('@c.us', '@s.whatsapp.net')
|
||||
}
|
||||
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
||||
export function aesDecrypt(buffer: Buffer, key: Buffer) {
|
||||
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16))
|
||||
|
||||
Reference in New Issue
Block a user