getBusinessProfile() (#425)

* JSDoc for acceptInvite and revokeInvite

* added isBusiness in isOnWhatsApp

* create getBusinessProfile

* removed unnecessary query
This commit is contained in:
Nurutomo
2021-03-30 21:48:21 +07:00
committed by GitHub
parent f20d36fe9b
commit 3575150df1
2 changed files with 48 additions and 9 deletions

View File

@@ -22,8 +22,8 @@ export class WAConnection extends Base {
if (this.state !== 'open') { if (this.state !== 'open') {
return this.isOnWhatsAppNoConn(str) return this.isOnWhatsAppNoConn(str)
} }
const { status, jid } = await this.query({json: ['query', 'exist', str], requiresPhoneConnection: false}) const { status, jid, biz } = await this.query({json: ['query', 'exist', str], requiresPhoneConnection: false})
if (status === 200) return { exists: true, jid: whatsappID(jid) } if (status === 200) return { exists: true, jid: whatsappID(jid), isBusiness: biz as boolean}
} }
/** /**
* Query whether a given number is registered on WhatsApp, without needing to open a WS connection * Query whether a given number is registered on WhatsApp, without needing to open a WS connection
@@ -211,4 +211,30 @@ export class WAConnection extends Base {
return result return result
} }
/**
* Query Business Profile (Useful for VCards)
* @param jid Business Jid
* @returns profile object or undefined if not business account
*/
async getBusinessProfile(jid: string) {
jid = whatsappID(jid)
const {
profiles: [{
profile,
wid
}]
} = await this.query({
json: ["query", "businessProfile", [
{
"wid": jid.replace('@s.whatsapp.net', '@c.us')
}
], 84],
expect200: true,
requiresPhoneConnection: false,
})
return {
profile,
jid: whatsappID(wid),
}
}
} }

View File

@@ -171,20 +171,33 @@ export class WAConnection extends Base {
const node: WANode = [ setting, {value: onlyAdmins ? 'true' : 'false'}, null ] const node: WANode = [ setting, {value: onlyAdmins ? 'true' : 'false'}, null ]
return this.groupQuery('prop', jid, null, null, [node]) as Promise<{status: number}> return this.groupQuery('prop', jid, null, null, [node]) as Promise<{status: number}>
} }
/** Get the invite link of the given group */ /**
* Get the invite link of the given group
* @param jid the ID of the group
* @returns invite code
*/
async groupInviteCode(jid: string) { async groupInviteCode(jid: string) {
const json = ['query', 'inviteCode', jid] const json = ['query', 'inviteCode', jid]
const response = await this.query({json, expect200: true, requiresPhoneConnection: false}) const response = await this.query({json, expect200: true, requiresPhoneConnection: false})
return response.code as string return response.code as string
} }
/** Join group via invite code */ /**
async acceptInvite(jid) { * Join group via invite code
const response = await this.query({ json: ['action', 'invite', jid], expect200: true }) * @param code the invite code
* @returns Object containing gid
*/
async acceptInvite(code: string) {
const json = ['action', 'invite', code]
const response = await this.query({json, expect200: true})
return response return response
} }
/** Revokes the current invite link for a group chat */ /**
async revokeInvite(jid) { * Revokes the current invite link for a group chat
const response = await this.query({ json: ['action', 'inviteReset', jid], expect200: true }) * @param jid the ID of the group
*/
async revokeInvite(jid: string) {
const json = ['action', 'inviteReset', jid]
const response = await this.query({json, expect200: true})
return response return response
} }
} }