mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
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:
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user