-
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.
Merge pull request #265 from domwebber/main
Add Phone Numbers' APIs
- Loading branch information
Showing
6 changed files
with
154 additions
and
3 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 Phone Numbers' 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
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,70 @@ | ||
/** | ||
* 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 { BusinessAccountID } from "../types/BusinessAccount.js"; | ||
import { | ||
GetPhoneNumberFields, | ||
GetPhoneNumberOptions, | ||
GetPhoneNumberPayload, | ||
ListPhoneNumbersOptions, | ||
ListPhoneNumbersPaylod, | ||
} from "../types/PhoneNumbers/index.js"; | ||
|
||
interface MethodOptions { | ||
request?: KyOptions; | ||
} | ||
|
||
export default class PhoneNumbers { | ||
constructor(protected _request: KyOptions) {} | ||
|
||
public getEndpoint(businessAccountID: BusinessAccountID) { | ||
return encodeURIComponent(businessAccountID) + "/phone_numbers"; | ||
} | ||
|
||
public getPhoneNumber<Fields extends GetPhoneNumberFields = object>({ | ||
phoneNumberID, | ||
fields, | ||
request, | ||
}: MethodOptions & GetPhoneNumberOptions) { | ||
return ky.create({ | ||
...this._request, | ||
method: "GET", | ||
searchParams: { | ||
fields: Object.keys(fields ?? {}).join(","), | ||
}, | ||
})<GetPhoneNumberPayload<Fields>>( | ||
encodeURIComponent(phoneNumberID), | ||
request, | ||
); | ||
} | ||
|
||
public listPhoneNumbers({ | ||
businessAccountID, | ||
sort, | ||
filtering, | ||
request, | ||
}: MethodOptions & ListPhoneNumbersOptions) { | ||
return ky.create({ | ||
...this._request, | ||
method: "GET", | ||
searchParams: { | ||
...(sort | ||
? { | ||
sort, | ||
} | ||
: {}), | ||
...(filtering | ||
? { | ||
filtering, | ||
} | ||
: {}), | ||
}, | ||
})<ListPhoneNumbersPaylod>(this.getEndpoint(businessAccountID), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* WhatsApp NodeJS SDK. | ||
* | ||
* @author Great Detail Ltd <[email protected]> | ||
* @author Dom Webber <[email protected]> | ||
* @see https://greatdetail.com | ||
*/ | ||
|
||
import { BusinessAccountID } from "../BusinessAccount.js"; | ||
import { PhoneNumberID } from "../PhoneNumber.js"; | ||
|
||
export type ListPhoneNumbersOptions = { | ||
businessAccountID: BusinessAccountID; | ||
sort?: string; | ||
filtering?: string; | ||
}; | ||
|
||
export type ListPhoneNumbersPaylod = { | ||
data: { | ||
id: PhoneNumberID; | ||
verified_name: string; | ||
code_verification_status: "VERIFIED" | (string & NonNullable<unknown>); | ||
display_phone_number: string; | ||
quality_rating: string; | ||
platform_type: string; | ||
throughput: { | ||
level: string; | ||
}; | ||
last_onboarded_time?: string; | ||
webhook_configuration: { | ||
application?: string; | ||
}; | ||
}[]; | ||
}; | ||
|
||
export type GetPhoneNumberFields = { | ||
name_status?: boolean; | ||
}; | ||
|
||
export type GetPhoneNumberOptions< | ||
Fields extends GetPhoneNumberFields = object, | ||
> = { | ||
phoneNumberID: PhoneNumberID; | ||
fields?: Fields; | ||
}; | ||
|
||
export type GetPhoneNumberPayload< | ||
Fields extends GetPhoneNumberFields = object, | ||
> = { | ||
id: PhoneNumberID; | ||
verified_name: string; | ||
name_status: Fields extends { name_status: true } | ||
? | ||
| "APPROVED" | ||
| "AVAILABLE_WITHOUT_REVIEW" | ||
| "DECLINED" | ||
| "EXPIRED" | ||
| "PENDING_REVIEW" | ||
| "NONE" | ||
| (string & NonNullable<unknown>) | ||
: undefined; | ||
code_verification_status: "VERIFIED" | (string & NonNullable<unknown>); | ||
display_phone_number: string; | ||
quality_rating: string; | ||
platform_type: string; | ||
throughput: { | ||
level: string; | ||
}; | ||
last_onboarded_time?: string; | ||
webhook_configuration: { | ||
application?: string; | ||
}; | ||
}; |