Edit Business Profile (#499)

*  Added updateBusinessProfile

* 🎨 parity of output between getBusinessProfile and updateBusinessProfile

* 🏷️ Added the Interfaces

* 🏷️ improved the type declarations

* 🥅 Fixed fatal error & Removed semicolon

* 🥅 Fixed one more error, and cleaned the code to be ready for release
This commit is contained in:
Rajeh Taher
2021-06-04 20:35:48 +03:00
committed by GitHub
parent 9897bacb64
commit ff69726ec4
2 changed files with 45 additions and 4 deletions

View File

@@ -80,6 +80,20 @@ export class WAConnection extends Base {
this.emit ('contact-update', { jid: this.user.jid, status }) this.emit ('contact-update', { jid: this.user.jid, status })
return response return response
} }
/** Updates business profile. */
async updateBusinessProfile(profile: WABusinessProfile) {
if (profile.business_hours?.config) {
profile.business_hours.business_config = profile.business_hours.config
delete profile.business_hours.config
}
const json = ['action', "editBusinessProfile", {...profile, v: 2}]
try {
const response = await this.query({ json, expect200: true, requiresPhoneConnection: true }).catch(_ => throw new Error(_))
} catch (_) {
return {status: 400}
}
return {status: response.status}
}
async updateProfileName (name: string) { async updateProfileName (name: string) {
const response = (await this.setQuery ( const response = (await this.setQuery (
[ [
@@ -214,7 +228,7 @@ export class WAConnection extends Base {
/** /**
* Query Business Profile (Useful for VCards) * Query Business Profile (Useful for VCards)
* @param jid Business Jid * @param jid Business Jid
* @returns profile object or undefined if not business account * @returns {WABusinessProfile} profile object or undefined if not business account
*/ */
async getBusinessProfile(jid: string) { async getBusinessProfile(jid: string) {
jid = whatsappID(jid) jid = whatsappID(jid)
@@ -233,8 +247,8 @@ export class WAConnection extends Base {
requiresPhoneConnection: false, requiresPhoneConnection: false,
}) })
return { return {
profile, ...profile,
jid: whatsappID(wid), wid: whatsappID(wid)
} }
} }
} }

View File

@@ -31,6 +31,33 @@ export type WAInitResponse = {
status: 200 status: 200
} }
export interface WABusinessProfile {
description: string
email: string
business_hours: WABusinessHours
website: string[]
categories: WABusinessCategories[]
wid?: string
}
export type WABusinessCategories = {
id: string
localized_display_name: string
}
export type WABusinessHours = {
timezone: string
config?: WABusinessHoursConfig[]
business_config?: WABusinessHoursConfig[]
}
export type WABusinessHoursConfig = {
day_of_week: string
mode: string
open_time?: number
close_time?: number
}
export interface WALocationMessage { export interface WALocationMessage {
degreesLatitude: number degreesLatitude: number
degreesLongitude: number degreesLongitude: number
@@ -472,4 +499,4 @@ export type BaileysEvent =
'group-update' | 'group-update' |
'received-pong' | 'received-pong' |
'blocklist-update' | 'blocklist-update' |
'contact-update' 'contact-update'