diff --git a/src/WAConnection/5.User.ts b/src/WAConnection/5.User.ts index f3412ff..fc47951 100644 --- a/src/WAConnection/5.User.ts +++ b/src/WAConnection/5.User.ts @@ -22,8 +22,8 @@ export class WAConnection extends Base { if (this.state !== 'open') { return this.isOnWhatsAppNoConn(str) } - const { status, jid } = await this.query({json: ['query', 'exist', str], requiresPhoneConnection: false}) - if (status === 200) return { exists: true, jid: whatsappID(jid) } + const { status, jid, biz } = await this.query({json: ['query', 'exist', str], requiresPhoneConnection: false}) + 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 @@ -211,4 +211,30 @@ export class WAConnection extends Base { 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), + } + } } diff --git a/src/WAConnection/8.Groups.ts b/src/WAConnection/8.Groups.ts index aced983..61cd065 100644 --- a/src/WAConnection/8.Groups.ts +++ b/src/WAConnection/8.Groups.ts @@ -171,20 +171,33 @@ export class WAConnection extends Base { const node: WANode = [ setting, {value: onlyAdmins ? 'true' : 'false'}, null ] 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) { const json = ['query', 'inviteCode', jid] const response = await this.query({json, expect200: true, requiresPhoneConnection: false}) return response.code as string } - /** Join group via invite code */ - async acceptInvite(jid) { - const response = await this.query({ json: ['action', 'invite', jid], expect200: true }) + /** + * Join group via invite code + * @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 } - /** Revokes the current invite link for a group chat */ - async revokeInvite(jid) { - const response = await this.query({ json: ['action', 'inviteReset', jid], expect200: true }) + /** + * Revokes the current invite link for a group chat + * @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 } }