mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Bug fix + Url query
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import WAConnection from '../WAConnection/WAConnection'
|
||||
import { MessageStatus, MessageStatusUpdate, PresenceUpdate, Presence, ChatModification, WABroadcastListInfo } from './Constants'
|
||||
import { MessageStatus, MessageStatusUpdate, PresenceUpdate, Presence, ChatModification, WABroadcastListInfo, WAUrlInfo } from './Constants'
|
||||
import {
|
||||
WAMessage,
|
||||
WANode,
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
WAFlag,
|
||||
MessageLogLevel,
|
||||
} from '../WAConnection/Constants'
|
||||
import { proto } from '../../WAMessage/WAMessage'
|
||||
|
||||
export default class WhatsAppWebBase extends WAConnection {
|
||||
/** Set the callback for message status updates (when a message is delivered, read etc.) */
|
||||
@@ -186,4 +187,13 @@ export default class WhatsAppWebBase extends WAConnection {
|
||||
const json = ['action', {epoch: this.msgCount.toString(), type: 'set'}, nodes]
|
||||
return this.queryExpecting200(json, [WAMetric.group, WAFlag.ignore]) as Promise<{status: number}>
|
||||
}
|
||||
/** Query a string to check if it has a url, if it does, return required info */
|
||||
async urlQuery (text: string) {
|
||||
const query = ['query', {type: 'url', url: text, epoch: this.msgCount.toString()}, null]
|
||||
const response = await this.queryExpecting200 (query, [26, WAFlag.ignore])
|
||||
if (response[1]) {
|
||||
response[1].jpegThumbnail = response[2]
|
||||
}
|
||||
return response[1] as WAUrlInfo
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,13 @@ export interface WABroadcastListInfo {
|
||||
name: string
|
||||
recipients?: {id: string}[]
|
||||
}
|
||||
export interface WAUrlInfo {
|
||||
'canonical-url': string
|
||||
'matched-text': string
|
||||
title: string
|
||||
description: string
|
||||
jpegThumbnail?: Buffer
|
||||
}
|
||||
export interface MessageInfo {
|
||||
reads: {jid: string, t: string}[]
|
||||
deliveries: {jid: string, t: string}[]
|
||||
|
||||
@@ -110,6 +110,12 @@ WAClientTest('Misc', (client) => {
|
||||
it('should return the stories', async () => {
|
||||
await client.getStories()
|
||||
})
|
||||
it('should return a preview', async () => {
|
||||
const info = await client.urlQuery ('fren have you seen https://www.github.com/adiwajshing/Baileys')
|
||||
assert.equal (info["matched-text"], 'https://www.github.com/adiwajshing/Baileys')
|
||||
|
||||
await assert.rejects (() => client.urlQuery('oh hello there'))
|
||||
})
|
||||
it('should return the profile picture', async () => {
|
||||
const response = await client.getProfilePicture(testJid)
|
||||
assert.ok(response)
|
||||
|
||||
@@ -42,7 +42,7 @@ export default class WAConnectionConnector extends WAConnectionValidator {
|
||||
.then(user => {
|
||||
this.startKeepAliveRequest()
|
||||
|
||||
this.conn.on ('error', null)
|
||||
this.conn.removeAllListeners ('error')
|
||||
this.conn.on ('close', () => this.unexpectedDisconnect ('closed'))
|
||||
|
||||
resolve(user)
|
||||
|
||||
Reference in New Issue
Block a user