# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations import httpx from ...._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, 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 ...._base_client import make_request_options from ....types.whatsapp.business_accounts import setting_update_params from ....types.whatsapp.business_accounts.setting_update_response import SettingUpdateResponse from ....types.whatsapp.business_accounts.setting_retrieve_response import SettingRetrieveResponse __all__ = ["SettingsResource", "AsyncSettingsResource"] class SettingsResource(SyncAPIResource): """Manage Whatsapp business accounts""" @cached_property def with_raw_response(self) -> SettingsResourceWithRawResponse: """ 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 SettingsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> SettingsResourceWithStreamingResponse: """ 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 SettingsResourceWithStreamingResponse(self) def retrieve( self, id: str, *, # 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, ) -> SettingRetrieveResponse: """ Returns account-level settings for 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( path_template("/v2/whatsapp/business_accounts/{id}/settings", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SettingRetrieveResponse, ) def update( self, id: str, *, name: str | Omit = omit, timezone: str | Omit = omit, webhook_enabled: bool | Omit = omit, webhook_events: SequenceNotStr[str] | Omit = omit, webhook_failover_url: str | Omit = omit, webhook_url: str | 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, ) -> SettingUpdateResponse: """ Updates the supplied account-level settings for the specified WhatsApp Business Account. Args: timezone: IANA timezone identifier webhook_enabled: Enable/disable receiving Whatsapp events webhook_failover_url: Failover URL to send Whatsapp events webhook_url: URL to send Whatsapp events 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._patch( path_template("/v2/whatsapp/business_accounts/{id}/settings", id=id), body=maybe_transform( { "name": name, "timezone": timezone, "webhook_enabled": webhook_enabled, "webhook_events": webhook_events, "webhook_failover_url": webhook_failover_url, "webhook_url": webhook_url, }, setting_update_params.SettingUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SettingUpdateResponse, ) class AsyncSettingsResource(AsyncAPIResource): """Manage Whatsapp business accounts""" @cached_property def with_raw_response(self) -> AsyncSettingsResourceWithRawResponse: """ 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 AsyncSettingsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncSettingsResourceWithStreamingResponse: """ 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 AsyncSettingsResourceWithStreamingResponse(self) async def retrieve( self, id: str, *, # 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, ) -> SettingRetrieveResponse: """ Returns account-level settings for 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 await self._get( path_template("/v2/whatsapp/business_accounts/{id}/settings", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SettingRetrieveResponse, ) async def update( self, id: str, *, name: str | Omit = omit, timezone: str | Omit = omit, webhook_enabled: bool | Omit = omit, webhook_events: SequenceNotStr[str] | Omit = omit, webhook_failover_url: str | Omit = omit, webhook_url: str | 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, ) -> SettingUpdateResponse: """ Updates the supplied account-level settings for the specified WhatsApp Business Account. Args: timezone: IANA timezone identifier webhook_enabled: Enable/disable receiving Whatsapp events webhook_failover_url: Failover URL to send Whatsapp events webhook_url: URL to send Whatsapp events 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 await self._patch( path_template("/v2/whatsapp/business_accounts/{id}/settings", id=id), body=await async_maybe_transform( { "name": name, "timezone": timezone, "webhook_enabled": webhook_enabled, "webhook_events": webhook_events, "webhook_failover_url": webhook_failover_url, "webhook_url": webhook_url, }, setting_update_params.SettingUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SettingUpdateResponse, ) class SettingsResourceWithRawResponse: def __init__(self, settings: SettingsResource) -> None: self._settings = settings self.retrieve = to_raw_response_wrapper( settings.retrieve, ) self.update = to_raw_response_wrapper( settings.update, ) class AsyncSettingsResourceWithRawResponse: def __init__(self, settings: AsyncSettingsResource) -> None: self._settings = settings self.retrieve = async_to_raw_response_wrapper( settings.retrieve, ) self.update = async_to_raw_response_wrapper( settings.update, ) class SettingsResourceWithStreamingResponse: def __init__(self, settings: SettingsResource) -> None: self._settings = settings self.retrieve = to_streamed_response_wrapper( settings.retrieve, ) self.update = to_streamed_response_wrapper( settings.update, ) class AsyncSettingsResourceWithStreamingResponse: def __init__(self, settings: AsyncSettingsResource) -> None: self._settings = settings self.retrieve = async_to_streamed_response_wrapper( settings.retrieve, ) self.update = async_to_streamed_response_wrapper( settings.update, )