mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Merge branch 'master' into feat_pushname
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@adiwajshing/baileys",
|
||||
"version": "3.4.0",
|
||||
"version": "3.4.1",
|
||||
"description": "WhatsApp Web API",
|
||||
"homepage": "https://github.com/adiwajshing/Baileys",
|
||||
"main": "lib/index.js",
|
||||
|
||||
@@ -195,7 +195,7 @@ export class WAConnection extends EventEmitter {
|
||||
/** Generic function for action, set queries */
|
||||
async setQuery (nodes: WANode[], binaryTags: WATag = [WAMetric.group, WAFlag.ignore], tag?: string) {
|
||||
const json = ['action', {epoch: this.msgCount.toString(), type: 'set'}, nodes]
|
||||
const result = await this.query({ json, binaryTags, tag, expect200: true }) as Promise<{status: number}>
|
||||
const result = await this.query({ json, binaryTags, tag, expect200: true, requiresPhoneConnection: true }) as Promise<{status: number}>
|
||||
return result
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -215,7 +215,7 @@ export class WAConnection extends Base {
|
||||
|
||||
if (this.state === 'open' && json[0] === 'Pong') {
|
||||
if (!json[1]) {
|
||||
this.closeInternal(DisconnectReason.close)
|
||||
this.unexpectedDisconnect(DisconnectReason.close)
|
||||
this.logger.info('Connection terminated by phone, closing...')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -104,13 +104,13 @@ export class WAConnection extends Base {
|
||||
/** Get your contacts */
|
||||
async getContacts() {
|
||||
const json = ['query', { epoch: this.msgCount.toString(), type: 'contacts' }, null]
|
||||
const response = await this.query({ json, binaryTags: [6, WAFlag.ignore], expect200: true }) // this has to be an encrypted query
|
||||
const response = await this.query({ json, binaryTags: [WAMetric.queryContact, WAFlag.ignore], expect200: true, requiresPhoneConnection: true }) // this has to be an encrypted query
|
||||
return response
|
||||
}
|
||||
/** Get the stories of your contacts */
|
||||
async getStories() {
|
||||
const json = ['query', { epoch: this.msgCount.toString(), type: 'status' }, null]
|
||||
const response = await this.query({json, binaryTags: [30, WAFlag.ignore], expect200: true }) as WANode
|
||||
const response = await this.query({json, binaryTags: [WAMetric.queryStatus, WAFlag.ignore], expect200: true, requiresPhoneConnection: true }) as WANode
|
||||
if (Array.isArray(response[2])) {
|
||||
return response[2].map (row => (
|
||||
{
|
||||
@@ -128,7 +128,13 @@ export class WAConnection extends Base {
|
||||
return this.query({ json, binaryTags: [5, WAFlag.ignore], expect200: true }) // this has to be an encrypted query
|
||||
}
|
||||
/** Query broadcast list info */
|
||||
async getBroadcastListInfo(jid: string) { return this.query({json: ['query', 'contact', jid], expect200: true }) as Promise<WABroadcastListInfo> }
|
||||
async getBroadcastListInfo(jid: string) {
|
||||
return this.query({
|
||||
json: ['query', 'contact', jid],
|
||||
expect200: true,
|
||||
requiresPhoneConnection: true
|
||||
}) as Promise<WABroadcastListInfo>
|
||||
}
|
||||
/**
|
||||
* Load chats in a paginated manner + gets the profile picture
|
||||
* @param before chats before the given cursor
|
||||
@@ -187,9 +193,6 @@ export class WAConnection extends Base {
|
||||
*/
|
||||
@Mutex (jid => jid)
|
||||
async blockUser (jid: string, type: 'add' | 'remove' = 'add') {
|
||||
jid.replace('@s.whatsapp.net', '@c.us')
|
||||
|
||||
const tag = this.generateMessageTag()
|
||||
const json: WANode = [
|
||||
'block',
|
||||
{
|
||||
@@ -199,7 +202,7 @@ export class WAConnection extends Base {
|
||||
['user', { jid }, null]
|
||||
],
|
||||
]
|
||||
const result = await this.setQuery ([json], [WAMetric.block, WAFlag.ignore], tag)
|
||||
const result = await this.setQuery ([json], [WAMetric.block, WAFlag.ignore])
|
||||
|
||||
if (result.status === 200) {
|
||||
if (type === 'add') {
|
||||
|
||||
@@ -260,7 +260,7 @@ export class WAConnection extends Base {
|
||||
key: {
|
||||
remoteJid: id,
|
||||
fromMe: true,
|
||||
id: generateMessageID(),
|
||||
id: options?.messageId || generateMessageID(),
|
||||
},
|
||||
message: message,
|
||||
messageTimestamp: timestamp,
|
||||
@@ -280,7 +280,8 @@ export class WAConnection extends Base {
|
||||
json,
|
||||
binaryTags: [WAMetric.message, flag],
|
||||
tag: mID,
|
||||
expect200: true
|
||||
expect200: true,
|
||||
requiresPhoneConnection: true
|
||||
})
|
||||
.then(() => message.status = WA_MESSAGE_STATUS_TYPE.SERVER_ACK)
|
||||
|
||||
@@ -304,7 +305,12 @@ export class WAConnection extends Base {
|
||||
if (!content) throw new BaileysError (`given message ${message.key.id} is not a media message`, message)
|
||||
|
||||
const query = ['query',{type: 'media', index: message.key.id, owner: message.key.fromMe ? 'true' : 'false', jid: message.key.remoteJid, epoch: this.msgCount.toString()},null]
|
||||
const response = await this.query ({json: query, binaryTags: [WAMetric.queryMedia, WAFlag.ignore], expect200: true})
|
||||
const response = await this.query ({
|
||||
json: query,
|
||||
binaryTags: [WAMetric.queryMedia, WAFlag.ignore],
|
||||
expect200: true,
|
||||
requiresPhoneConnection: true
|
||||
})
|
||||
Object.keys (response[1]).forEach (key => content[key] = response[1][key]) // update message
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,12 @@ export class WAConnection extends Base {
|
||||
@Mutex ((jid, messageID) => jid+messageID)
|
||||
async messageInfo (jid: string, messageID: string) {
|
||||
const query = ['query', {type: 'message_info', index: messageID, jid: jid, epoch: this.msgCount.toString()}, null]
|
||||
const [,,response] = await this.query ({json: query, binaryTags: [WAMetric.queryRead, WAFlag.ignore], expect200: true})
|
||||
const [,,response] = await this.query ({
|
||||
json: query,
|
||||
binaryTags: [WAMetric.queryRead, WAFlag.ignore],
|
||||
expect200: true,
|
||||
requiresPhoneConnection: true
|
||||
})
|
||||
|
||||
const info: MessageInfo = {reads: [], deliveries: []}
|
||||
if (response) {
|
||||
@@ -87,7 +92,7 @@ export class WAConnection extends Base {
|
||||
},
|
||||
null,
|
||||
]
|
||||
const response = await this.query({json, binaryTags: [WAMetric.queryMessages, WAFlag.ignore], expect200: false})
|
||||
const response = await this.query({json, binaryTags: [WAMetric.queryMessages, WAFlag.ignore], expect200: false, requiresPhoneConnection: true})
|
||||
return (response[2] as WANode[])?.map(item => item[2] as WAMessage) || []
|
||||
}
|
||||
/**
|
||||
@@ -109,7 +114,7 @@ export class WAConnection extends Base {
|
||||
|
||||
const chat = this.chats.get (jid)
|
||||
const hasCursor = cursor?.id && typeof cursor?.fromMe !== 'undefined'
|
||||
const cursorValue = hasCursor && chat.messages.get (GET_MESSAGE_ID(cursor))
|
||||
const cursorValue = hasCursor && chat?.messages.get (GET_MESSAGE_ID(cursor))
|
||||
|
||||
let messages: WAMessage[]
|
||||
if (chat?.messages && mostRecentFirst && (!hasCursor || cursorValue)) {
|
||||
|
||||
@@ -378,6 +378,8 @@ export interface MessageOptions {
|
||||
/** Should it send as a disappearing messages.
|
||||
* By default 'chat' -- which follows the setting of the chat */
|
||||
sendEphemeral?: 'chat' | boolean
|
||||
/** Force message id */
|
||||
messageId?: string
|
||||
}
|
||||
export interface WABroadcastListInfo {
|
||||
status: number
|
||||
|
||||
Reference in New Issue
Block a user