mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
renamed user.id to user.jid
This commit is contained in:
@@ -29,7 +29,7 @@ async function example() {
|
|||||||
|
|
||||||
const unread = await conn.loadAllUnreadMessages ()
|
const unread = await conn.loadAllUnreadMessages ()
|
||||||
|
|
||||||
console.log('oh hello ' + conn.user.name + ' (' + conn.user.id + ')')
|
console.log('oh hello ' + conn.user.name + ' (' + conn.user.jid + ')')
|
||||||
console.log('you have ' + conn.chats.all().length + ' chats')
|
console.log('you have ' + conn.chats.all().length + ' chats')
|
||||||
console.log ('you have ' + unread.length + ' unread messages')
|
console.log ('you have ' + unread.length + ' unread messages')
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export class WAConnection extends Base {
|
|||||||
this.lastSeen = new Date() // set last seen to right now
|
this.lastSeen = new Date() // set last seen to right now
|
||||||
})
|
})
|
||||||
// load profile picture
|
// load profile picture
|
||||||
.then (() => this.query({ json: ['query', 'ProfilePicThumb', this.user.id], waitForOpen: false, expect200: false }))
|
.then (() => this.query({ json: ['query', 'ProfilePicThumb', this.user.jid], waitForOpen: false, expect200: false }))
|
||||||
.then (response => this.user.imgUrl = response?.eurl || '')
|
.then (response => this.user.imgUrl = response?.eurl || '')
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +92,7 @@ export class WAConnection extends Base {
|
|||||||
private validateNewConnection(json) {
|
private validateNewConnection(json) {
|
||||||
// set metadata: one's WhatsApp ID [cc][number]@s.whatsapp.net, name on WhatsApp, info about the phone
|
// set metadata: one's WhatsApp ID [cc][number]@s.whatsapp.net, name on WhatsApp, info about the phone
|
||||||
const onValidationSuccess = () => ({
|
const onValidationSuccess = () => ({
|
||||||
id: Utils.whatsappID(json.wid),
|
jid: Utils.whatsappID(json.wid),
|
||||||
name: json.pushname,
|
name: json.pushname,
|
||||||
phone: json.phone,
|
phone: json.phone,
|
||||||
imgUrl: null
|
imgUrl: null
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ export class WAConnection extends Base {
|
|||||||
await delay
|
await delay
|
||||||
try {
|
try {
|
||||||
const shouldUseReconnect = this.lastDisconnectReason !== DisconnectReason.replaced && this.lastDisconnectReason !== DisconnectReason.unknown && this.user
|
const shouldUseReconnect = this.lastDisconnectReason !== DisconnectReason.replaced && this.lastDisconnectReason !== DisconnectReason.unknown && this.user
|
||||||
const reconnectID = shouldUseReconnect ? this.user.id.replace ('@s.whatsapp.net', '@c.us') : null
|
const reconnectID = shouldUseReconnect ? this.user.jid.replace ('@s.whatsapp.net', '@c.us') : null
|
||||||
|
|
||||||
await this.connect ({ timeoutMs: 30000, retryOnNetworkErrors: true, reconnectID })
|
await this.connect ({ timeoutMs: 30000, retryOnNetworkErrors: true, reconnectID })
|
||||||
this.cancelReconnect = null
|
this.cancelReconnect = null
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export class WAConnection extends Base {
|
|||||||
}
|
}
|
||||||
/** Get the URL to download the profile picture of a person/group */
|
/** Get the URL to download the profile picture of a person/group */
|
||||||
async getProfilePicture(jid: string | null) {
|
async getProfilePicture(jid: string | null) {
|
||||||
const response = await this.query({ json: ['query', 'ProfilePicThumb', jid || this.user.id] })
|
const response = await this.query({ json: ['query', 'ProfilePicThumb', jid || this.user.jid] })
|
||||||
return response.eurl as string
|
return response.eurl as string
|
||||||
}
|
}
|
||||||
/** Set the callback for message status updates (when a message is delivered, read etc.) */
|
/** Set the callback for message status updates (when a message is delivered, read etc.) */
|
||||||
@@ -245,7 +245,7 @@ export class WAConnection extends Base {
|
|||||||
this.emit ('group-participants-remove', { jid, actor, participants})
|
this.emit ('group-participants-remove', { jid, actor, participants})
|
||||||
|
|
||||||
// mark the chat read only if you left the group
|
// mark the chat read only if you left the group
|
||||||
if (participants.includes(this.user.id)) {
|
if (participants.includes(this.user.jid)) {
|
||||||
chat.read_only = 'true'
|
chat.read_only = 'true'
|
||||||
this.emit ('chat-update', { jid, read_only: chat.read_only })
|
this.emit ('chat-update', { jid, read_only: chat.read_only })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class WAConnection extends Base {
|
|||||||
requestPresenceUpdate = async (jid: string) => this.query({json: ['action', 'presence', 'subscribe', jid]})
|
requestPresenceUpdate = async (jid: string) => this.query({json: ['action', 'presence', 'subscribe', jid]})
|
||||||
/** Query the status of the person (see groupMetadata() for groups) */
|
/** Query the status of the person (see groupMetadata() for groups) */
|
||||||
async getStatus (jid?: string) {
|
async getStatus (jid?: string) {
|
||||||
const status: { status: string } = await this.query({json: ['query', 'Status', jid || this.user.id]})
|
const status: { status: string } = await this.query({json: ['query', 'Status', jid || this.user.jid]})
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
async setStatus (status: string) {
|
async setStatus (status: string) {
|
||||||
@@ -47,7 +47,7 @@ export class WAConnection extends Base {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
this.emit ('user-status-update', { jid: this.user.id, status })
|
this.emit ('user-status-update', { jid: this.user.jid, status })
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
/** Get your contacts */
|
/** Get your contacts */
|
||||||
@@ -122,7 +122,7 @@ export class WAConnection extends Base {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
const response = await (this.setQuery ([query], [WAMetric.picture, 136], tag) as Promise<WAProfilePictureChange>)
|
const response = await (this.setQuery ([query], [WAMetric.picture, 136], tag) as Promise<WAProfilePictureChange>)
|
||||||
if (jid === this.user.id) this.user.imgUrl = response.eurl
|
if (jid === this.user.jid) this.user.imgUrl = response.eurl
|
||||||
else if (this.chats.get(jid)) {
|
else if (this.chats.get(jid)) {
|
||||||
this.chats.get(jid).imgUrl = response.eurl
|
this.chats.get(jid).imgUrl = response.eurl
|
||||||
this.emit ('chat-update', { jid, imgUrl: response.eurl })
|
this.emit ('chat-update', { jid, imgUrl: response.eurl })
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ export class WAConnection extends Base {
|
|||||||
if (options.contextInfo) message[key].contextInfo = options.contextInfo
|
if (options.contextInfo) message[key].contextInfo = options.contextInfo
|
||||||
|
|
||||||
if (quoted) {
|
if (quoted) {
|
||||||
const participant = quoted.key.fromMe ? this.user.id : (quoted.key.participant || quoted.key.remoteJid)
|
const participant = quoted.key.fromMe ? this.user.jid : (quoted.key.participant || quoted.key.remoteJid)
|
||||||
|
|
||||||
message[key].contextInfo = message[key].contextInfo || { }
|
message[key].contextInfo = message[key].contextInfo || { }
|
||||||
message[key].contextInfo.participant = participant
|
message[key].contextInfo.participant = participant
|
||||||
@@ -174,7 +174,7 @@ export class WAConnection extends Base {
|
|||||||
message: message,
|
message: message,
|
||||||
messageTimestamp: timestamp,
|
messageTimestamp: timestamp,
|
||||||
messageStubParameters: [],
|
messageStubParameters: [],
|
||||||
participant: id.includes('@g.us') ? this.user.id : null,
|
participant: id.includes('@g.us') ? this.user.jid : null,
|
||||||
status: WA_MESSAGE_STATUS_TYPE.PENDING
|
status: WA_MESSAGE_STATUS_TYPE.PENDING
|
||||||
}
|
}
|
||||||
return messageJSON as WAMessage
|
return messageJSON as WAMessage
|
||||||
@@ -182,7 +182,7 @@ export class WAConnection extends Base {
|
|||||||
/** Relay (send) a WAMessage; more advanced functionality to send a built WA Message, you may want to stick with sendMessage() */
|
/** Relay (send) a WAMessage; more advanced functionality to send a built WA Message, you may want to stick with sendMessage() */
|
||||||
async relayWAMessage(message: WAMessage) {
|
async relayWAMessage(message: WAMessage) {
|
||||||
const json = ['action', {epoch: this.msgCount.toString(), type: 'relay'}, [['message', null, message]]]
|
const json = ['action', {epoch: this.msgCount.toString(), type: 'relay'}, [['message', null, message]]]
|
||||||
const flag = message.key.remoteJid === this.user.id ? WAFlag.acknowledge : WAFlag.ignore // acknowledge when sending message to oneself
|
const flag = message.key.remoteJid === this.user.jid ? WAFlag.acknowledge : WAFlag.ignore // acknowledge when sending message to oneself
|
||||||
await this.query({json, binaryTags: [WAMetric.message, flag], tag: message.key.id})
|
await this.query({json, binaryTags: [WAMetric.message, flag], tag: message.key.id})
|
||||||
await this.chatAddMessageAppropriate (message)
|
await this.chatAddMessageAppropriate (message)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export class WAConnection extends Base {
|
|||||||
const json: WANode = [
|
const json: WANode = [
|
||||||
'group',
|
'group',
|
||||||
{
|
{
|
||||||
author: this.user.id,
|
author: this.user.jid,
|
||||||
id: tag,
|
id: tag,
|
||||||
type: type,
|
type: type,
|
||||||
jid: jid,
|
jid: jid,
|
||||||
|
|||||||
@@ -113,12 +113,6 @@ export interface AuthenticationCredentialsBrowser {
|
|||||||
WAToken2: string
|
WAToken2: string
|
||||||
}
|
}
|
||||||
export type AnyAuthenticationCredentials = AuthenticationCredentialsBrowser | AuthenticationCredentialsBase64 | AuthenticationCredentials
|
export type AnyAuthenticationCredentials = AuthenticationCredentialsBrowser | AuthenticationCredentialsBase64 | AuthenticationCredentials
|
||||||
export interface WAUser {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
phone: string
|
|
||||||
imgUrl: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WAGroupCreateResponse {
|
export interface WAGroupCreateResponse {
|
||||||
status: number
|
status: number
|
||||||
@@ -145,12 +139,21 @@ export interface WAGroupModification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WAContact {
|
export interface WAContact {
|
||||||
|
/** name of the contact, the contact has set on their own on WA */
|
||||||
notify?: string
|
notify?: string
|
||||||
jid: string
|
jid: string
|
||||||
|
/** I have no idea */
|
||||||
|
vname?: string
|
||||||
|
/** name of the contact, you have saved on your WA */
|
||||||
name?: string
|
name?: string
|
||||||
index?: string
|
index?: string
|
||||||
|
/** short name for the contact */
|
||||||
short?: string
|
short?: string
|
||||||
}
|
}
|
||||||
|
export interface WAUser extends WAContact {
|
||||||
|
phone: any
|
||||||
|
imgUrl?: string
|
||||||
|
}
|
||||||
export interface WAChat {
|
export interface WAChat {
|
||||||
jid: string
|
jid: string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user