# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing_extensions import Literal import httpx from ...._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given from ...._utils import path_template, maybe_transform, async_maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ....pagination import SyncDefaultFlatPagination, AsyncDefaultFlatPagination from ...._base_client import AsyncPaginator, make_request_options from ....types.whatsapp.business_accounts import phone_number_list_params, phone_number_initialize_verification_params from ....types.whatsapp.whatsapp_phone_response import WhatsappPhoneResponse __all__ = ["PhoneNumbersResource", "AsyncPhoneNumbersResource"] class PhoneNumbersResource(SyncAPIResource): @cached_property def with_raw_response(self) -> PhoneNumbersResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return PhoneNumbersResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> PhoneNumbersResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return PhoneNumbersResourceWithStreamingResponse(self) def list( self, id: str, *, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncDefaultFlatPagination[WhatsappPhoneResponse]: """ Returns phone numbers registered under the specified WhatsApp Business Account. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get_api_list( path_template("/v2/whatsapp/business_accounts/{id}/phone_numbers", id=id), page=SyncDefaultFlatPagination[WhatsappPhoneResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "page_number": page_number, "page_size": page_size, }, phone_number_list_params.PhoneNumberListParams, ), ), model=WhatsappPhoneResponse, ) def initialize_verification( self, id: str, *, display_name: str, phone_number: str, language: str | Omit = omit, verification_method: Literal["sms", "voice"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Starts verification of a phone number for the specified WhatsApp Business Account using the requested verification method. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._post( path_template("/v2/whatsapp/business_accounts/{id}/phone_numbers", id=id), body=maybe_transform( { "display_name": display_name, "phone_number": phone_number, "language": language, "verification_method": verification_method, }, phone_number_initialize_verification_params.PhoneNumberInitializeVerificationParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class AsyncPhoneNumbersResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncPhoneNumbersResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return AsyncPhoneNumbersResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncPhoneNumbersResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return AsyncPhoneNumbersResourceWithStreamingResponse(self) def list( self, id: str, *, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[WhatsappPhoneResponse, AsyncDefaultFlatPagination[WhatsappPhoneResponse]]: """ Returns phone numbers registered under the specified WhatsApp Business Account. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") return self._get_api_list( path_template("/v2/whatsapp/business_accounts/{id}/phone_numbers", id=id), page=AsyncDefaultFlatPagination[WhatsappPhoneResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "page_number": page_number, "page_size": page_size, }, phone_number_list_params.PhoneNumberListParams, ), ), model=WhatsappPhoneResponse, ) async def initialize_verification( self, id: str, *, display_name: str, phone_number: str, language: str | Omit = omit, verification_method: Literal["sms", "voice"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Starts verification of a phone number for the specified WhatsApp Business Account using the requested verification method. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._post( path_template("/v2/whatsapp/business_accounts/{id}/phone_numbers", id=id), body=await async_maybe_transform( { "display_name": display_name, "phone_number": phone_number, "language": language, "verification_method": verification_method, }, phone_number_initialize_verification_params.PhoneNumberInitializeVerificationParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class PhoneNumbersResourceWithRawResponse: def __init__(self, phone_numbers: PhoneNumbersResource) -> None: self._phone_numbers = phone_numbers self.list = to_raw_response_wrapper( phone_numbers.list, ) self.initialize_verification = to_raw_response_wrapper( phone_numbers.initialize_verification, ) class AsyncPhoneNumbersResourceWithRawResponse: def __init__(self, phone_numbers: AsyncPhoneNumbersResource) -> None: self._phone_numbers = phone_numbers self.list = async_to_raw_response_wrapper( phone_numbers.list, ) self.initialize_verification = async_to_raw_response_wrapper( phone_numbers.initialize_verification, ) class PhoneNumbersResourceWithStreamingResponse: def __init__(self, phone_numbers: PhoneNumbersResource) -> None: self._phone_numbers = phone_numbers self.list = to_streamed_response_wrapper( phone_numbers.list, ) self.initialize_verification = to_streamed_response_wrapper( phone_numbers.initialize_verification, ) class AsyncPhoneNumbersResourceWithStreamingResponse: def __init__(self, phone_numbers: AsyncPhoneNumbersResource) -> None: self._phone_numbers = phone_numbers self.list = async_to_streamed_response_wrapper( phone_numbers.list, ) self.initialize_verification = async_to_streamed_response_wrapper( phone_numbers.initialize_verification, )