-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@great-detail/whatsapp": patch | ||
--- | ||
|
||
Add Business Profile APIs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* WhatsApp NodeJS SDK. | ||
* | ||
* @author Great Detail Ltd <[email protected]> | ||
* @author Dom Webber <[email protected]> | ||
* @see https://greatdetail.com | ||
*/ | ||
|
||
import ky, { Options as KyOptions } from "ky"; | ||
import { PhoneNumberID } from "../types/PhoneNumber.js"; | ||
import { GetBusinessProfileFields, GetBusinessProfileOptions, GetBusinessProfilePayload, UpdateBusinessProfileOptions, UpdateBusinessProfilePayload } from "../types/BusinessProfile/index.js"; | ||
|
||
interface MethodOptions { | ||
request?: KyOptions; | ||
} | ||
|
||
export default class BusinessProfile { | ||
constructor(protected _request: KyOptions) {} | ||
|
||
protected getEndpoint(phoneNumberID: PhoneNumberID) { | ||
return encodeURIComponent(phoneNumberID) + "/whatsapp_business_profile"; | ||
} | ||
|
||
public getBusinessProfile<Fields extends GetBusinessProfileFields = {}>({ | ||
phoneNumberID, | ||
fields, | ||
request, | ||
}: MethodOptions & GetBusinessProfileOptions<Fields>) { | ||
return ky.create({ | ||
...this._request, | ||
method: "GET", | ||
searchParams: { | ||
fields: Object.entries(fields ?? {}).map(([key]) => key).join(","), | ||
}, | ||
})<GetBusinessProfilePayload<Fields>>( | ||
this.getEndpoint(phoneNumberID), | ||
request, | ||
); | ||
} | ||
|
||
public updateBusinessProfile({ | ||
phoneNumberID, | ||
request, | ||
...json | ||
}: MethodOptions & UpdateBusinessProfileOptions) { | ||
return ky.create({ | ||
...this._request, | ||
method: "POST", | ||
json: { | ||
messaging_product: "whatsapp", | ||
...json, | ||
}, | ||
})<UpdateBusinessProfilePayload>( | ||
this.getEndpoint(phoneNumberID), | ||
request, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* WhatsApp NodeJS SDK. | ||
* | ||
* @author Great Detail Ltd <[email protected]> | ||
* @author Dom Webber <[email protected]> | ||
* @see https://greatdetail.com | ||
*/ | ||
|
||
import { PhoneNumberID } from "../PhoneNumber.js" | ||
|
||
export type GetBusinessProfileFields = { | ||
about?: boolean; | ||
address?: boolean; | ||
description?: boolean; | ||
email?: boolean; | ||
profile_picture_url?: boolean; | ||
websites?: boolean; | ||
vertical?: boolean; | ||
}; | ||
|
||
export type GetBusinessProfileOptions<Fields extends GetBusinessProfileFields = {}> = { | ||
phoneNumberID: PhoneNumberID; | ||
fields?: Fields; | ||
} | ||
|
||
export type GetBusinessProfilePayload<Fields extends GetBusinessProfileFields = {}> = { | ||
data: [{ | ||
about: Fields extends { about: true } ? string : undefined; | ||
address: Fields extends { address: true } ? string : undefined; | ||
description: Fields extends { description: true } ? string : undefined; | ||
email: Fields extends { email: true } ? string : undefined; | ||
messaging_product: "whatsapp"; | ||
profile_picture_url: Fields extends { profile_picture_url: true } ? string : undefined; | ||
vertical: Fields extends { vertical: true } | ||
? ("" | (string & NonNullable<unknown>)) | ||
: undefined; | ||
websites: Fields extends { websites: true } ? ([string] | [string, string] | (string[] & NonNullable<unknown>)) : undefined; | ||
}]; | ||
}; | ||
|
||
export type UpdateBusinessProfileOptions = { | ||
phoneNumberID: PhoneNumberID; | ||
about?: string; | ||
address?: string; | ||
description?: string; | ||
email?: string; | ||
profile_picture_handle?: string; | ||
vertical?: ("" | (string & NonNullable<unknown>)); | ||
websites?: [string] | [string, string] | (string[] & NonNullable<unknown>); | ||
} | ||
|
||
export type UpdateBusinessProfilePayload = { | ||
success: boolean; | ||
} |