|
16 | 16 | // - POST /{PHONE_NUMBER_ID}/official_business_account |
17 | 17 | // - GET /{PHONE_NUMBER_ID}/business_compliance_info |
18 | 18 | // - POST /{PHONE_NUMBER_ID}/business_compliance_info |
| 19 | +// - GET /{PHONE_NUMBER_ID}/username |
| 20 | +// - POST /{PHONE_NUMBER_ID}/username |
| 21 | +// - DELETE /{PHONE_NUMBER_ID}/username |
| 22 | +// - GET /{PHONE_NUMBER_ID}/username_suggestions |
19 | 23 |
|
20 | 24 | import { BaseAPI } from '../../types/base'; |
21 | 25 | import { HttpMethodsEnum, WabaConfigEnum } from '../../types/enums'; |
@@ -389,4 +393,80 @@ export default class PhoneNumberApi extends BaseAPI implements phoneNumber.Phone |
389 | 393 | JSON.stringify(params), |
390 | 394 | ); |
391 | 395 | } |
| 396 | + |
| 397 | + /** |
| 398 | + * Get the username currently associated with the business phone number. |
| 399 | + * |
| 400 | + * @returns A promise that resolves with the username and its status |
| 401 | + * (`'approved'` or `'reserved'`). |
| 402 | + * |
| 403 | + * @see {@link https://developers.facebook.com/documentation/business-messaging/whatsapp/business-phone-numbers/usernames/ | Usernames} |
| 404 | + */ |
| 405 | + async getUsername(): Promise<phoneNumber.UsernameResponse> { |
| 406 | + return this.sendJson( |
| 407 | + HttpMethodsEnum.Get, |
| 408 | + `${this.config[WabaConfigEnum.PhoneNumberId]}/username`, |
| 409 | + this.config[WabaConfigEnum.RequestTimeout], |
| 410 | + null, |
| 411 | + ); |
| 412 | + } |
| 413 | + |
| 414 | + /** |
| 415 | + * Adopt or change the username for the business phone number. |
| 416 | + * |
| 417 | + * If the desired username is already in use by another phone number in your |
| 418 | + * portfolio, the API responds with error code `147005`; retry with |
| 419 | + * `transfer_action: 'force_transfer'` to move the username to this number. |
| 420 | + * |
| 421 | + * @param params - The username request. |
| 422 | + * @param params.username - The desired username. |
| 423 | + * @param params.transfer_action - Optional. `'none'` (default) or `'force_transfer'`. |
| 424 | + * @returns A promise that resolves with a success indicator. |
| 425 | + * |
| 426 | + * @see {@link https://developers.facebook.com/documentation/business-messaging/whatsapp/business-phone-numbers/usernames/ | Usernames} |
| 427 | + * |
| 428 | + * @example |
| 429 | + * ```ts |
| 430 | + * await whatsappClient.phoneNumbers.updateUsername({ |
| 431 | + * username: 'jaspersmarket', |
| 432 | + * transfer_action: 'force_transfer', |
| 433 | + * }); |
| 434 | + * ``` |
| 435 | + */ |
| 436 | + async updateUsername(params: phoneNumber.UpdateUsernameRequest): Promise<ResponseSuccess> { |
| 437 | + return this.sendJson( |
| 438 | + HttpMethodsEnum.Post, |
| 439 | + `${this.config[WabaConfigEnum.PhoneNumberId]}/username`, |
| 440 | + this.config[WabaConfigEnum.RequestTimeout], |
| 441 | + JSON.stringify(params), |
| 442 | + ); |
| 443 | + } |
| 444 | + |
| 445 | + /** |
| 446 | + * Delete the username associated with the business phone number. |
| 447 | + * |
| 448 | + * @see {@link https://developers.facebook.com/documentation/business-messaging/whatsapp/business-phone-numbers/usernames/ | Usernames} |
| 449 | + */ |
| 450 | + async deleteUsername(): Promise<ResponseSuccess> { |
| 451 | + return this.sendJson( |
| 452 | + HttpMethodsEnum.Delete, |
| 453 | + `${this.config[WabaConfigEnum.PhoneNumberId]}/username`, |
| 454 | + this.config[WabaConfigEnum.RequestTimeout], |
| 455 | + null, |
| 456 | + ); |
| 457 | + } |
| 458 | + |
| 459 | + /** |
| 460 | + * Get username suggestions for the business phone number. |
| 461 | + * |
| 462 | + * @see {@link https://developers.facebook.com/documentation/business-messaging/whatsapp/business-phone-numbers/usernames/ | Usernames} |
| 463 | + */ |
| 464 | + async getUsernameSuggestions(): Promise<phoneNumber.UsernameSuggestionsResponse> { |
| 465 | + return this.sendJson( |
| 466 | + HttpMethodsEnum.Get, |
| 467 | + `${this.config[WabaConfigEnum.PhoneNumberId]}/username_suggestions`, |
| 468 | + this.config[WabaConfigEnum.RequestTimeout], |
| 469 | + null, |
| 470 | + ); |
| 471 | + } |
392 | 472 | } |
0 commit comments