Initial commit: Email alerts application
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from twilio.base.domain import Domain
|
||||
from twilio.rest import Client
|
||||
from twilio.rest.proxy.v1 import V1
|
||||
|
||||
|
||||
class ProxyBase(Domain):
|
||||
def __init__(self, twilio: Client):
|
||||
"""
|
||||
Initialize the Proxy Domain
|
||||
|
||||
:returns: Domain for Proxy
|
||||
"""
|
||||
super().__init__(twilio, "https://proxy.twilio.com")
|
||||
self._v1: Optional[V1] = None
|
||||
|
||||
@property
|
||||
def v1(self) -> V1:
|
||||
"""
|
||||
:returns: Versions v1 of Proxy
|
||||
"""
|
||||
if self._v1 is None:
|
||||
self._v1 = V1(self)
|
||||
return self._v1
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy>"
|
||||
@@ -0,0 +1,15 @@
|
||||
from warnings import warn
|
||||
|
||||
from twilio.rest.proxy.ProxyBase import ProxyBase
|
||||
from twilio.rest.proxy.v1.service import ServiceList
|
||||
|
||||
|
||||
class Proxy(ProxyBase):
|
||||
@property
|
||||
def services(self) -> ServiceList:
|
||||
warn(
|
||||
"services is deprecated. Use v1.services instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self.v1.services
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.domain import Domain
|
||||
from twilio.rest.proxy.v1.service import ServiceList
|
||||
|
||||
|
||||
class V1(Version):
|
||||
def __init__(self, domain: Domain):
|
||||
"""
|
||||
Initialize the V1 version of Proxy
|
||||
|
||||
:param domain: The Twilio.proxy domain
|
||||
"""
|
||||
super().__init__(domain, "v1")
|
||||
self._services: Optional[ServiceList] = None
|
||||
|
||||
@property
|
||||
def services(self) -> ServiceList:
|
||||
if self._services is None:
|
||||
self._services = ServiceList(self)
|
||||
return self._services
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1>"
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,809 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
|
||||
from twilio.base import deserialize, values
|
||||
from twilio.base.instance_context import InstanceContext
|
||||
from twilio.base.instance_resource import InstanceResource
|
||||
from twilio.base.list_resource import ListResource
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.page import Page
|
||||
from twilio.rest.proxy.v1.service.phone_number import PhoneNumberList
|
||||
from twilio.rest.proxy.v1.service.session import SessionList
|
||||
from twilio.rest.proxy.v1.service.short_code import ShortCodeList
|
||||
|
||||
|
||||
class ServiceInstance(InstanceResource):
|
||||
class GeoMatchLevel(object):
|
||||
AREA_CODE = "area-code"
|
||||
OVERLAY = "overlay"
|
||||
RADIUS = "radius"
|
||||
COUNTRY = "country"
|
||||
|
||||
class NumberSelectionBehavior(object):
|
||||
AVOID_STICKY = "avoid-sticky"
|
||||
PREFER_STICKY = "prefer-sticky"
|
||||
|
||||
"""
|
||||
:ivar sid: The unique string that we created to identify the Service resource.
|
||||
:ivar unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. Supports UTF-8 characters. **This value should not have PII.**
|
||||
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Service resource.
|
||||
:ivar chat_instance_sid: The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.
|
||||
:ivar callback_url: The URL we call when the interaction status changes.
|
||||
:ivar default_ttl: The default `ttl` value for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session's last create or last Interaction. The default value of `0` indicates an unlimited Session length. You can override a Session's default TTL value by setting its `ttl` value.
|
||||
:ivar number_selection_behavior:
|
||||
:ivar geo_match_level:
|
||||
:ivar intercept_callback_url: The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.
|
||||
:ivar out_of_session_callback_url: The URL we call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/en-us/serverless/functions)) responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.
|
||||
:ivar date_created: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was created.
|
||||
:ivar date_updated: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was last updated.
|
||||
:ivar url: The absolute URL of the Service resource.
|
||||
:ivar links: The URLs of resources related to the Service.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, version: Version, payload: Dict[str, Any], sid: Optional[str] = None
|
||||
):
|
||||
super().__init__(version)
|
||||
|
||||
self.sid: Optional[str] = payload.get("sid")
|
||||
self.unique_name: Optional[str] = payload.get("unique_name")
|
||||
self.account_sid: Optional[str] = payload.get("account_sid")
|
||||
self.chat_instance_sid: Optional[str] = payload.get("chat_instance_sid")
|
||||
self.callback_url: Optional[str] = payload.get("callback_url")
|
||||
self.default_ttl: Optional[int] = deserialize.integer(
|
||||
payload.get("default_ttl")
|
||||
)
|
||||
self.number_selection_behavior: Optional[
|
||||
"ServiceInstance.NumberSelectionBehavior"
|
||||
] = payload.get("number_selection_behavior")
|
||||
self.geo_match_level: Optional["ServiceInstance.GeoMatchLevel"] = payload.get(
|
||||
"geo_match_level"
|
||||
)
|
||||
self.intercept_callback_url: Optional[str] = payload.get(
|
||||
"intercept_callback_url"
|
||||
)
|
||||
self.out_of_session_callback_url: Optional[str] = payload.get(
|
||||
"out_of_session_callback_url"
|
||||
)
|
||||
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_created")
|
||||
)
|
||||
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_updated")
|
||||
)
|
||||
self.url: Optional[str] = payload.get("url")
|
||||
self.links: Optional[Dict[str, object]] = payload.get("links")
|
||||
|
||||
self._solution = {
|
||||
"sid": sid or self.sid,
|
||||
}
|
||||
self._context: Optional[ServiceContext] = None
|
||||
|
||||
@property
|
||||
def _proxy(self) -> "ServiceContext":
|
||||
"""
|
||||
Generate an instance context for the instance, the context is capable of
|
||||
performing various actions. All instance actions are proxied to the context
|
||||
|
||||
:returns: ServiceContext for this ServiceInstance
|
||||
"""
|
||||
if self._context is None:
|
||||
self._context = ServiceContext(
|
||||
self._version,
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
return self._context
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the ServiceInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._proxy.delete()
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the ServiceInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._proxy.delete_async()
|
||||
|
||||
def fetch(self) -> "ServiceInstance":
|
||||
"""
|
||||
Fetch the ServiceInstance
|
||||
|
||||
|
||||
:returns: The fetched ServiceInstance
|
||||
"""
|
||||
return self._proxy.fetch()
|
||||
|
||||
async def fetch_async(self) -> "ServiceInstance":
|
||||
"""
|
||||
Asynchronous coroutine to fetch the ServiceInstance
|
||||
|
||||
|
||||
:returns: The fetched ServiceInstance
|
||||
"""
|
||||
return await self._proxy.fetch_async()
|
||||
|
||||
def update(
|
||||
self,
|
||||
unique_name: Union[str, object] = values.unset,
|
||||
default_ttl: Union[int, object] = values.unset,
|
||||
callback_url: Union[str, object] = values.unset,
|
||||
geo_match_level: Union["ServiceInstance.GeoMatchLevel", object] = values.unset,
|
||||
number_selection_behavior: Union[
|
||||
"ServiceInstance.NumberSelectionBehavior", object
|
||||
] = values.unset,
|
||||
intercept_callback_url: Union[str, object] = values.unset,
|
||||
out_of_session_callback_url: Union[str, object] = values.unset,
|
||||
chat_instance_sid: Union[str, object] = values.unset,
|
||||
) -> "ServiceInstance":
|
||||
"""
|
||||
Update the ServiceInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param default_ttl: The default `ttl` value to set for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session's last create or last Interaction. The default value of `0` indicates an unlimited Session length. You can override a Session's default TTL value by setting its `ttl` value.
|
||||
:param callback_url: The URL we should call when the interaction status changes.
|
||||
:param geo_match_level:
|
||||
:param number_selection_behavior:
|
||||
:param intercept_callback_url: The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.
|
||||
:param out_of_session_callback_url: The URL we should call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/en-us/serverless/functions)) responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.
|
||||
:param chat_instance_sid: The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.
|
||||
|
||||
:returns: The updated ServiceInstance
|
||||
"""
|
||||
return self._proxy.update(
|
||||
unique_name=unique_name,
|
||||
default_ttl=default_ttl,
|
||||
callback_url=callback_url,
|
||||
geo_match_level=geo_match_level,
|
||||
number_selection_behavior=number_selection_behavior,
|
||||
intercept_callback_url=intercept_callback_url,
|
||||
out_of_session_callback_url=out_of_session_callback_url,
|
||||
chat_instance_sid=chat_instance_sid,
|
||||
)
|
||||
|
||||
async def update_async(
|
||||
self,
|
||||
unique_name: Union[str, object] = values.unset,
|
||||
default_ttl: Union[int, object] = values.unset,
|
||||
callback_url: Union[str, object] = values.unset,
|
||||
geo_match_level: Union["ServiceInstance.GeoMatchLevel", object] = values.unset,
|
||||
number_selection_behavior: Union[
|
||||
"ServiceInstance.NumberSelectionBehavior", object
|
||||
] = values.unset,
|
||||
intercept_callback_url: Union[str, object] = values.unset,
|
||||
out_of_session_callback_url: Union[str, object] = values.unset,
|
||||
chat_instance_sid: Union[str, object] = values.unset,
|
||||
) -> "ServiceInstance":
|
||||
"""
|
||||
Asynchronous coroutine to update the ServiceInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param default_ttl: The default `ttl` value to set for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session's last create or last Interaction. The default value of `0` indicates an unlimited Session length. You can override a Session's default TTL value by setting its `ttl` value.
|
||||
:param callback_url: The URL we should call when the interaction status changes.
|
||||
:param geo_match_level:
|
||||
:param number_selection_behavior:
|
||||
:param intercept_callback_url: The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.
|
||||
:param out_of_session_callback_url: The URL we should call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/en-us/serverless/functions)) responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.
|
||||
:param chat_instance_sid: The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.
|
||||
|
||||
:returns: The updated ServiceInstance
|
||||
"""
|
||||
return await self._proxy.update_async(
|
||||
unique_name=unique_name,
|
||||
default_ttl=default_ttl,
|
||||
callback_url=callback_url,
|
||||
geo_match_level=geo_match_level,
|
||||
number_selection_behavior=number_selection_behavior,
|
||||
intercept_callback_url=intercept_callback_url,
|
||||
out_of_session_callback_url=out_of_session_callback_url,
|
||||
chat_instance_sid=chat_instance_sid,
|
||||
)
|
||||
|
||||
@property
|
||||
def phone_numbers(self) -> PhoneNumberList:
|
||||
"""
|
||||
Access the phone_numbers
|
||||
"""
|
||||
return self._proxy.phone_numbers
|
||||
|
||||
@property
|
||||
def sessions(self) -> SessionList:
|
||||
"""
|
||||
Access the sessions
|
||||
"""
|
||||
return self._proxy.sessions
|
||||
|
||||
@property
|
||||
def short_codes(self) -> ShortCodeList:
|
||||
"""
|
||||
Access the short_codes
|
||||
"""
|
||||
return self._proxy.short_codes
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.ServiceInstance {}>".format(context)
|
||||
|
||||
|
||||
class ServiceContext(InstanceContext):
|
||||
def __init__(self, version: Version, sid: str):
|
||||
"""
|
||||
Initialize the ServiceContext
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Service resource to update.
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"sid": sid,
|
||||
}
|
||||
self._uri = "/Services/{sid}".format(**self._solution)
|
||||
|
||||
self._phone_numbers: Optional[PhoneNumberList] = None
|
||||
self._sessions: Optional[SessionList] = None
|
||||
self._short_codes: Optional[ShortCodeList] = None
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the ServiceInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._version.delete(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the ServiceInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._version.delete_async(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
def fetch(self) -> ServiceInstance:
|
||||
"""
|
||||
Fetch the ServiceInstance
|
||||
|
||||
|
||||
:returns: The fetched ServiceInstance
|
||||
"""
|
||||
|
||||
payload = self._version.fetch(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return ServiceInstance(
|
||||
self._version,
|
||||
payload,
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def fetch_async(self) -> ServiceInstance:
|
||||
"""
|
||||
Asynchronous coroutine to fetch the ServiceInstance
|
||||
|
||||
|
||||
:returns: The fetched ServiceInstance
|
||||
"""
|
||||
|
||||
payload = await self._version.fetch_async(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return ServiceInstance(
|
||||
self._version,
|
||||
payload,
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def update(
|
||||
self,
|
||||
unique_name: Union[str, object] = values.unset,
|
||||
default_ttl: Union[int, object] = values.unset,
|
||||
callback_url: Union[str, object] = values.unset,
|
||||
geo_match_level: Union["ServiceInstance.GeoMatchLevel", object] = values.unset,
|
||||
number_selection_behavior: Union[
|
||||
"ServiceInstance.NumberSelectionBehavior", object
|
||||
] = values.unset,
|
||||
intercept_callback_url: Union[str, object] = values.unset,
|
||||
out_of_session_callback_url: Union[str, object] = values.unset,
|
||||
chat_instance_sid: Union[str, object] = values.unset,
|
||||
) -> ServiceInstance:
|
||||
"""
|
||||
Update the ServiceInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param default_ttl: The default `ttl` value to set for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session's last create or last Interaction. The default value of `0` indicates an unlimited Session length. You can override a Session's default TTL value by setting its `ttl` value.
|
||||
:param callback_url: The URL we should call when the interaction status changes.
|
||||
:param geo_match_level:
|
||||
:param number_selection_behavior:
|
||||
:param intercept_callback_url: The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.
|
||||
:param out_of_session_callback_url: The URL we should call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/en-us/serverless/functions)) responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.
|
||||
:param chat_instance_sid: The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.
|
||||
|
||||
:returns: The updated ServiceInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"UniqueName": unique_name,
|
||||
"DefaultTtl": default_ttl,
|
||||
"CallbackUrl": callback_url,
|
||||
"GeoMatchLevel": geo_match_level,
|
||||
"NumberSelectionBehavior": number_selection_behavior,
|
||||
"InterceptCallbackUrl": intercept_callback_url,
|
||||
"OutOfSessionCallbackUrl": out_of_session_callback_url,
|
||||
"ChatInstanceSid": chat_instance_sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.update(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ServiceInstance(self._version, payload, sid=self._solution["sid"])
|
||||
|
||||
async def update_async(
|
||||
self,
|
||||
unique_name: Union[str, object] = values.unset,
|
||||
default_ttl: Union[int, object] = values.unset,
|
||||
callback_url: Union[str, object] = values.unset,
|
||||
geo_match_level: Union["ServiceInstance.GeoMatchLevel", object] = values.unset,
|
||||
number_selection_behavior: Union[
|
||||
"ServiceInstance.NumberSelectionBehavior", object
|
||||
] = values.unset,
|
||||
intercept_callback_url: Union[str, object] = values.unset,
|
||||
out_of_session_callback_url: Union[str, object] = values.unset,
|
||||
chat_instance_sid: Union[str, object] = values.unset,
|
||||
) -> ServiceInstance:
|
||||
"""
|
||||
Asynchronous coroutine to update the ServiceInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param default_ttl: The default `ttl` value to set for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session's last create or last Interaction. The default value of `0` indicates an unlimited Session length. You can override a Session's default TTL value by setting its `ttl` value.
|
||||
:param callback_url: The URL we should call when the interaction status changes.
|
||||
:param geo_match_level:
|
||||
:param number_selection_behavior:
|
||||
:param intercept_callback_url: The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.
|
||||
:param out_of_session_callback_url: The URL we should call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/en-us/serverless/functions)) responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.
|
||||
:param chat_instance_sid: The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.
|
||||
|
||||
:returns: The updated ServiceInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"UniqueName": unique_name,
|
||||
"DefaultTtl": default_ttl,
|
||||
"CallbackUrl": callback_url,
|
||||
"GeoMatchLevel": geo_match_level,
|
||||
"NumberSelectionBehavior": number_selection_behavior,
|
||||
"InterceptCallbackUrl": intercept_callback_url,
|
||||
"OutOfSessionCallbackUrl": out_of_session_callback_url,
|
||||
"ChatInstanceSid": chat_instance_sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.update_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ServiceInstance(self._version, payload, sid=self._solution["sid"])
|
||||
|
||||
@property
|
||||
def phone_numbers(self) -> PhoneNumberList:
|
||||
"""
|
||||
Access the phone_numbers
|
||||
"""
|
||||
if self._phone_numbers is None:
|
||||
self._phone_numbers = PhoneNumberList(
|
||||
self._version,
|
||||
self._solution["sid"],
|
||||
)
|
||||
return self._phone_numbers
|
||||
|
||||
@property
|
||||
def sessions(self) -> SessionList:
|
||||
"""
|
||||
Access the sessions
|
||||
"""
|
||||
if self._sessions is None:
|
||||
self._sessions = SessionList(
|
||||
self._version,
|
||||
self._solution["sid"],
|
||||
)
|
||||
return self._sessions
|
||||
|
||||
@property
|
||||
def short_codes(self) -> ShortCodeList:
|
||||
"""
|
||||
Access the short_codes
|
||||
"""
|
||||
if self._short_codes is None:
|
||||
self._short_codes = ShortCodeList(
|
||||
self._version,
|
||||
self._solution["sid"],
|
||||
)
|
||||
return self._short_codes
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.ServiceContext {}>".format(context)
|
||||
|
||||
|
||||
class ServicePage(Page):
|
||||
def get_instance(self, payload: Dict[str, Any]) -> ServiceInstance:
|
||||
"""
|
||||
Build an instance of ServiceInstance
|
||||
|
||||
:param payload: Payload response from the API
|
||||
"""
|
||||
return ServiceInstance(self._version, payload)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.ServicePage>"
|
||||
|
||||
|
||||
class ServiceList(ListResource):
|
||||
def __init__(self, version: Version):
|
||||
"""
|
||||
Initialize the ServiceList
|
||||
|
||||
:param version: Version that contains the resource
|
||||
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
self._uri = "/Services"
|
||||
|
||||
def create(
|
||||
self,
|
||||
unique_name: str,
|
||||
default_ttl: Union[int, object] = values.unset,
|
||||
callback_url: Union[str, object] = values.unset,
|
||||
geo_match_level: Union["ServiceInstance.GeoMatchLevel", object] = values.unset,
|
||||
number_selection_behavior: Union[
|
||||
"ServiceInstance.NumberSelectionBehavior", object
|
||||
] = values.unset,
|
||||
intercept_callback_url: Union[str, object] = values.unset,
|
||||
out_of_session_callback_url: Union[str, object] = values.unset,
|
||||
chat_instance_sid: Union[str, object] = values.unset,
|
||||
) -> ServiceInstance:
|
||||
"""
|
||||
Create the ServiceInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param default_ttl: The default `ttl` value to set for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session's last create or last Interaction. The default value of `0` indicates an unlimited Session length. You can override a Session's default TTL value by setting its `ttl` value.
|
||||
:param callback_url: The URL we should call when the interaction status changes.
|
||||
:param geo_match_level:
|
||||
:param number_selection_behavior:
|
||||
:param intercept_callback_url: The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.
|
||||
:param out_of_session_callback_url: The URL we should call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/en-us/serverless/functions)) responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.
|
||||
:param chat_instance_sid: The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.
|
||||
|
||||
:returns: The created ServiceInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"UniqueName": unique_name,
|
||||
"DefaultTtl": default_ttl,
|
||||
"CallbackUrl": callback_url,
|
||||
"GeoMatchLevel": geo_match_level,
|
||||
"NumberSelectionBehavior": number_selection_behavior,
|
||||
"InterceptCallbackUrl": intercept_callback_url,
|
||||
"OutOfSessionCallbackUrl": out_of_session_callback_url,
|
||||
"ChatInstanceSid": chat_instance_sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.create(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ServiceInstance(self._version, payload)
|
||||
|
||||
async def create_async(
|
||||
self,
|
||||
unique_name: str,
|
||||
default_ttl: Union[int, object] = values.unset,
|
||||
callback_url: Union[str, object] = values.unset,
|
||||
geo_match_level: Union["ServiceInstance.GeoMatchLevel", object] = values.unset,
|
||||
number_selection_behavior: Union[
|
||||
"ServiceInstance.NumberSelectionBehavior", object
|
||||
] = values.unset,
|
||||
intercept_callback_url: Union[str, object] = values.unset,
|
||||
out_of_session_callback_url: Union[str, object] = values.unset,
|
||||
chat_instance_sid: Union[str, object] = values.unset,
|
||||
) -> ServiceInstance:
|
||||
"""
|
||||
Asynchronously create the ServiceInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param default_ttl: The default `ttl` value to set for Sessions created in the Service. The TTL (time to live) is measured in seconds after the Session's last create or last Interaction. The default value of `0` indicates an unlimited Session length. You can override a Session's default TTL value by setting its `ttl` value.
|
||||
:param callback_url: The URL we should call when the interaction status changes.
|
||||
:param geo_match_level:
|
||||
:param number_selection_behavior:
|
||||
:param intercept_callback_url: The URL we call on each interaction. If we receive a 403 status, we block the interaction; otherwise the interaction continues.
|
||||
:param out_of_session_callback_url: The URL we should call when an inbound call or SMS action occurs on a closed or non-existent Session. If your server (or a Twilio [function](https://www.twilio.com/en-us/serverless/functions)) responds with valid [TwiML](https://www.twilio.com/docs/voice/twiml), we will process it. This means it is possible, for example, to play a message for a call, send an automated text message response, or redirect a call to another Phone Number. See [Out-of-Session Callback Response Guide](https://www.twilio.com/docs/proxy/out-session-callback-response-guide) for more information.
|
||||
:param chat_instance_sid: The SID of the Chat Service Instance managed by Proxy Service. The Chat Service enables Proxy to forward SMS and channel messages to this chat instance. This is a one-to-one relationship.
|
||||
|
||||
:returns: The created ServiceInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"UniqueName": unique_name,
|
||||
"DefaultTtl": default_ttl,
|
||||
"CallbackUrl": callback_url,
|
||||
"GeoMatchLevel": geo_match_level,
|
||||
"NumberSelectionBehavior": number_selection_behavior,
|
||||
"InterceptCallbackUrl": intercept_callback_url,
|
||||
"OutOfSessionCallbackUrl": out_of_session_callback_url,
|
||||
"ChatInstanceSid": chat_instance_sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.create_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ServiceInstance(self._version, payload)
|
||||
|
||||
def stream(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> Iterator[ServiceInstance]:
|
||||
"""
|
||||
Streams ServiceInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = self.page(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream(page, limits["limit"])
|
||||
|
||||
async def stream_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> AsyncIterator[ServiceInstance]:
|
||||
"""
|
||||
Asynchronously streams ServiceInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = await self.page_async(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream_async(page, limits["limit"])
|
||||
|
||||
def list(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[ServiceInstance]:
|
||||
"""
|
||||
Lists ServiceInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return list(
|
||||
self.stream(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
)
|
||||
|
||||
async def list_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[ServiceInstance]:
|
||||
"""
|
||||
Asynchronously lists ServiceInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return [
|
||||
record
|
||||
async for record in await self.stream_async(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
]
|
||||
|
||||
def page(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> ServicePage:
|
||||
"""
|
||||
Retrieve a single page of ServiceInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of ServiceInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = self._version.page(method="GET", uri=self._uri, params=data)
|
||||
return ServicePage(self._version, response)
|
||||
|
||||
async def page_async(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> ServicePage:
|
||||
"""
|
||||
Asynchronously retrieve a single page of ServiceInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of ServiceInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = await self._version.page_async(
|
||||
method="GET", uri=self._uri, params=data
|
||||
)
|
||||
return ServicePage(self._version, response)
|
||||
|
||||
def get_page(self, target_url: str) -> ServicePage:
|
||||
"""
|
||||
Retrieve a specific page of ServiceInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of ServiceInstance
|
||||
"""
|
||||
response = self._version.domain.twilio.request("GET", target_url)
|
||||
return ServicePage(self._version, response)
|
||||
|
||||
async def get_page_async(self, target_url: str) -> ServicePage:
|
||||
"""
|
||||
Asynchronously retrieve a specific page of ServiceInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of ServiceInstance
|
||||
"""
|
||||
response = await self._version.domain.twilio.request_async("GET", target_url)
|
||||
return ServicePage(self._version, response)
|
||||
|
||||
def get(self, sid: str) -> ServiceContext:
|
||||
"""
|
||||
Constructs a ServiceContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Service resource to update.
|
||||
"""
|
||||
return ServiceContext(self._version, sid=sid)
|
||||
|
||||
def __call__(self, sid: str) -> ServiceContext:
|
||||
"""
|
||||
Constructs a ServiceContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Service resource to update.
|
||||
"""
|
||||
return ServiceContext(self._version, sid=sid)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.ServiceList>"
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,629 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
|
||||
from twilio.base import deserialize, values
|
||||
from twilio.base.instance_context import InstanceContext
|
||||
from twilio.base.instance_resource import InstanceResource
|
||||
from twilio.base.list_resource import ListResource
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.page import Page
|
||||
|
||||
|
||||
class PhoneNumberInstance(InstanceResource):
|
||||
|
||||
"""
|
||||
:ivar sid: The unique string that we created to identify the PhoneNumber resource.
|
||||
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the PhoneNumber resource.
|
||||
:ivar service_sid: The SID of the PhoneNumber resource's parent [Service](https://www.twilio.com/docs/proxy/api/service) resource.
|
||||
:ivar date_created: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was created.
|
||||
:ivar date_updated: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was last updated.
|
||||
:ivar phone_number: The phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format, which consists of a + followed by the country code and subscriber number.
|
||||
:ivar friendly_name: The string that you assigned to describe the resource.
|
||||
:ivar iso_country: The ISO Country Code for the phone number.
|
||||
:ivar capabilities:
|
||||
:ivar url: The absolute URL of the PhoneNumber resource.
|
||||
:ivar is_reserved: Whether the phone number should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
:ivar in_use: The number of open session assigned to the number. See the [How many Phone Numbers do I need?](https://www.twilio.com/docs/proxy/phone-numbers-needed) guide for more information.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version: Version,
|
||||
payload: Dict[str, Any],
|
||||
service_sid: str,
|
||||
sid: Optional[str] = None,
|
||||
):
|
||||
super().__init__(version)
|
||||
|
||||
self.sid: Optional[str] = payload.get("sid")
|
||||
self.account_sid: Optional[str] = payload.get("account_sid")
|
||||
self.service_sid: Optional[str] = payload.get("service_sid")
|
||||
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_created")
|
||||
)
|
||||
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_updated")
|
||||
)
|
||||
self.phone_number: Optional[str] = payload.get("phone_number")
|
||||
self.friendly_name: Optional[str] = payload.get("friendly_name")
|
||||
self.iso_country: Optional[str] = payload.get("iso_country")
|
||||
self.capabilities: Optional[str] = payload.get("capabilities")
|
||||
self.url: Optional[str] = payload.get("url")
|
||||
self.is_reserved: Optional[bool] = payload.get("is_reserved")
|
||||
self.in_use: Optional[int] = deserialize.integer(payload.get("in_use"))
|
||||
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"sid": sid or self.sid,
|
||||
}
|
||||
self._context: Optional[PhoneNumberContext] = None
|
||||
|
||||
@property
|
||||
def _proxy(self) -> "PhoneNumberContext":
|
||||
"""
|
||||
Generate an instance context for the instance, the context is capable of
|
||||
performing various actions. All instance actions are proxied to the context
|
||||
|
||||
:returns: PhoneNumberContext for this PhoneNumberInstance
|
||||
"""
|
||||
if self._context is None:
|
||||
self._context = PhoneNumberContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
return self._context
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._proxy.delete()
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._proxy.delete_async()
|
||||
|
||||
def fetch(self) -> "PhoneNumberInstance":
|
||||
"""
|
||||
Fetch the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: The fetched PhoneNumberInstance
|
||||
"""
|
||||
return self._proxy.fetch()
|
||||
|
||||
async def fetch_async(self) -> "PhoneNumberInstance":
|
||||
"""
|
||||
Asynchronous coroutine to fetch the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: The fetched PhoneNumberInstance
|
||||
"""
|
||||
return await self._proxy.fetch_async()
|
||||
|
||||
def update(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> "PhoneNumberInstance":
|
||||
"""
|
||||
Update the PhoneNumberInstance
|
||||
|
||||
:param is_reserved: Whether the phone number should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated PhoneNumberInstance
|
||||
"""
|
||||
return self._proxy.update(
|
||||
is_reserved=is_reserved,
|
||||
)
|
||||
|
||||
async def update_async(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> "PhoneNumberInstance":
|
||||
"""
|
||||
Asynchronous coroutine to update the PhoneNumberInstance
|
||||
|
||||
:param is_reserved: Whether the phone number should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated PhoneNumberInstance
|
||||
"""
|
||||
return await self._proxy.update_async(
|
||||
is_reserved=is_reserved,
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.PhoneNumberInstance {}>".format(context)
|
||||
|
||||
|
||||
class PhoneNumberContext(InstanceContext):
|
||||
def __init__(self, version: Version, service_sid: str, sid: str):
|
||||
"""
|
||||
Initialize the PhoneNumberContext
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the PhoneNumber resource to update.
|
||||
:param sid: The Twilio-provided string that uniquely identifies the PhoneNumber resource to update.
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"sid": sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/PhoneNumbers/{sid}".format(
|
||||
**self._solution
|
||||
)
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._version.delete(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._version.delete_async(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
def fetch(self) -> PhoneNumberInstance:
|
||||
"""
|
||||
Fetch the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: The fetched PhoneNumberInstance
|
||||
"""
|
||||
|
||||
payload = self._version.fetch(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return PhoneNumberInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def fetch_async(self) -> PhoneNumberInstance:
|
||||
"""
|
||||
Asynchronous coroutine to fetch the PhoneNumberInstance
|
||||
|
||||
|
||||
:returns: The fetched PhoneNumberInstance
|
||||
"""
|
||||
|
||||
payload = await self._version.fetch_async(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return PhoneNumberInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def update(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> PhoneNumberInstance:
|
||||
"""
|
||||
Update the PhoneNumberInstance
|
||||
|
||||
:param is_reserved: Whether the phone number should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated PhoneNumberInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"IsReserved": is_reserved,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.update(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return PhoneNumberInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def update_async(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> PhoneNumberInstance:
|
||||
"""
|
||||
Asynchronous coroutine to update the PhoneNumberInstance
|
||||
|
||||
:param is_reserved: Whether the phone number should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated PhoneNumberInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"IsReserved": is_reserved,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.update_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return PhoneNumberInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.PhoneNumberContext {}>".format(context)
|
||||
|
||||
|
||||
class PhoneNumberPage(Page):
|
||||
def get_instance(self, payload: Dict[str, Any]) -> PhoneNumberInstance:
|
||||
"""
|
||||
Build an instance of PhoneNumberInstance
|
||||
|
||||
:param payload: Payload response from the API
|
||||
"""
|
||||
return PhoneNumberInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.PhoneNumberPage>"
|
||||
|
||||
|
||||
class PhoneNumberList(ListResource):
|
||||
def __init__(self, version: Version, service_sid: str):
|
||||
"""
|
||||
Initialize the PhoneNumberList
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the PhoneNumber resources to read.
|
||||
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/PhoneNumbers".format(**self._solution)
|
||||
|
||||
def create(
|
||||
self,
|
||||
sid: Union[str, object] = values.unset,
|
||||
phone_number: Union[str, object] = values.unset,
|
||||
is_reserved: Union[bool, object] = values.unset,
|
||||
) -> PhoneNumberInstance:
|
||||
"""
|
||||
Create the PhoneNumberInstance
|
||||
|
||||
:param sid: The SID of a Twilio [IncomingPhoneNumber](https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource) resource that represents the Twilio Number you would like to assign to your Proxy Service.
|
||||
:param phone_number: The phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format. E.164 phone numbers consist of a + followed by the country code and subscriber number without punctuation characters. For example, +14155551234.
|
||||
:param is_reserved: Whether the new phone number should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The created PhoneNumberInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Sid": sid,
|
||||
"PhoneNumber": phone_number,
|
||||
"IsReserved": is_reserved,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.create(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return PhoneNumberInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
async def create_async(
|
||||
self,
|
||||
sid: Union[str, object] = values.unset,
|
||||
phone_number: Union[str, object] = values.unset,
|
||||
is_reserved: Union[bool, object] = values.unset,
|
||||
) -> PhoneNumberInstance:
|
||||
"""
|
||||
Asynchronously create the PhoneNumberInstance
|
||||
|
||||
:param sid: The SID of a Twilio [IncomingPhoneNumber](https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource) resource that represents the Twilio Number you would like to assign to your Proxy Service.
|
||||
:param phone_number: The phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format. E.164 phone numbers consist of a + followed by the country code and subscriber number without punctuation characters. For example, +14155551234.
|
||||
:param is_reserved: Whether the new phone number should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The created PhoneNumberInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Sid": sid,
|
||||
"PhoneNumber": phone_number,
|
||||
"IsReserved": is_reserved,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.create_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return PhoneNumberInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
def stream(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> Iterator[PhoneNumberInstance]:
|
||||
"""
|
||||
Streams PhoneNumberInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = self.page(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream(page, limits["limit"])
|
||||
|
||||
async def stream_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> AsyncIterator[PhoneNumberInstance]:
|
||||
"""
|
||||
Asynchronously streams PhoneNumberInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = await self.page_async(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream_async(page, limits["limit"])
|
||||
|
||||
def list(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[PhoneNumberInstance]:
|
||||
"""
|
||||
Lists PhoneNumberInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return list(
|
||||
self.stream(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
)
|
||||
|
||||
async def list_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[PhoneNumberInstance]:
|
||||
"""
|
||||
Asynchronously lists PhoneNumberInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return [
|
||||
record
|
||||
async for record in await self.stream_async(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
]
|
||||
|
||||
def page(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> PhoneNumberPage:
|
||||
"""
|
||||
Retrieve a single page of PhoneNumberInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of PhoneNumberInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = self._version.page(method="GET", uri=self._uri, params=data)
|
||||
return PhoneNumberPage(self._version, response, self._solution)
|
||||
|
||||
async def page_async(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> PhoneNumberPage:
|
||||
"""
|
||||
Asynchronously retrieve a single page of PhoneNumberInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of PhoneNumberInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = await self._version.page_async(
|
||||
method="GET", uri=self._uri, params=data
|
||||
)
|
||||
return PhoneNumberPage(self._version, response, self._solution)
|
||||
|
||||
def get_page(self, target_url: str) -> PhoneNumberPage:
|
||||
"""
|
||||
Retrieve a specific page of PhoneNumberInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of PhoneNumberInstance
|
||||
"""
|
||||
response = self._version.domain.twilio.request("GET", target_url)
|
||||
return PhoneNumberPage(self._version, response, self._solution)
|
||||
|
||||
async def get_page_async(self, target_url: str) -> PhoneNumberPage:
|
||||
"""
|
||||
Asynchronously retrieve a specific page of PhoneNumberInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of PhoneNumberInstance
|
||||
"""
|
||||
response = await self._version.domain.twilio.request_async("GET", target_url)
|
||||
return PhoneNumberPage(self._version, response, self._solution)
|
||||
|
||||
def get(self, sid: str) -> PhoneNumberContext:
|
||||
"""
|
||||
Constructs a PhoneNumberContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the PhoneNumber resource to update.
|
||||
"""
|
||||
return PhoneNumberContext(
|
||||
self._version, service_sid=self._solution["service_sid"], sid=sid
|
||||
)
|
||||
|
||||
def __call__(self, sid: str) -> PhoneNumberContext:
|
||||
"""
|
||||
Constructs a PhoneNumberContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the PhoneNumber resource to update.
|
||||
"""
|
||||
return PhoneNumberContext(
|
||||
self._version, service_sid=self._solution["service_sid"], sid=sid
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.PhoneNumberList>"
|
||||
@@ -0,0 +1,749 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
|
||||
from twilio.base import deserialize, serialize, values
|
||||
from twilio.base.instance_context import InstanceContext
|
||||
from twilio.base.instance_resource import InstanceResource
|
||||
from twilio.base.list_resource import ListResource
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.page import Page
|
||||
from twilio.rest.proxy.v1.service.session.interaction import InteractionList
|
||||
from twilio.rest.proxy.v1.service.session.participant import ParticipantList
|
||||
|
||||
|
||||
class SessionInstance(InstanceResource):
|
||||
class Mode(object):
|
||||
MESSAGE_ONLY = "message-only"
|
||||
VOICE_ONLY = "voice-only"
|
||||
VOICE_AND_MESSAGE = "voice-and-message"
|
||||
|
||||
class Status(object):
|
||||
OPEN = "open"
|
||||
IN_PROGRESS = "in-progress"
|
||||
CLOSED = "closed"
|
||||
FAILED = "failed"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
"""
|
||||
:ivar sid: The unique string that we created to identify the Session resource.
|
||||
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/proxy/api/service) the session is associated with.
|
||||
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Session resource.
|
||||
:ivar date_started: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session started.
|
||||
:ivar date_ended: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session ended.
|
||||
:ivar date_last_interaction: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session last had an interaction.
|
||||
:ivar date_expiry: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the `ttl` value.
|
||||
:ivar unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. Supports UTF-8 characters. **This value should not have PII.**
|
||||
:ivar status:
|
||||
:ivar closed_reason: The reason the Session ended.
|
||||
:ivar ttl: The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.
|
||||
:ivar mode:
|
||||
:ivar date_created: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was created.
|
||||
:ivar date_updated: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was last updated.
|
||||
:ivar url: The absolute URL of the Session resource.
|
||||
:ivar links: The URLs of resources related to the Session.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version: Version,
|
||||
payload: Dict[str, Any],
|
||||
service_sid: str,
|
||||
sid: Optional[str] = None,
|
||||
):
|
||||
super().__init__(version)
|
||||
|
||||
self.sid: Optional[str] = payload.get("sid")
|
||||
self.service_sid: Optional[str] = payload.get("service_sid")
|
||||
self.account_sid: Optional[str] = payload.get("account_sid")
|
||||
self.date_started: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_started")
|
||||
)
|
||||
self.date_ended: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_ended")
|
||||
)
|
||||
self.date_last_interaction: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_last_interaction")
|
||||
)
|
||||
self.date_expiry: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_expiry")
|
||||
)
|
||||
self.unique_name: Optional[str] = payload.get("unique_name")
|
||||
self.status: Optional["SessionInstance.Status"] = payload.get("status")
|
||||
self.closed_reason: Optional[str] = payload.get("closed_reason")
|
||||
self.ttl: Optional[int] = deserialize.integer(payload.get("ttl"))
|
||||
self.mode: Optional["SessionInstance.Mode"] = payload.get("mode")
|
||||
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_created")
|
||||
)
|
||||
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_updated")
|
||||
)
|
||||
self.url: Optional[str] = payload.get("url")
|
||||
self.links: Optional[Dict[str, object]] = payload.get("links")
|
||||
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"sid": sid or self.sid,
|
||||
}
|
||||
self._context: Optional[SessionContext] = None
|
||||
|
||||
@property
|
||||
def _proxy(self) -> "SessionContext":
|
||||
"""
|
||||
Generate an instance context for the instance, the context is capable of
|
||||
performing various actions. All instance actions are proxied to the context
|
||||
|
||||
:returns: SessionContext for this SessionInstance
|
||||
"""
|
||||
if self._context is None:
|
||||
self._context = SessionContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
return self._context
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the SessionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._proxy.delete()
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the SessionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._proxy.delete_async()
|
||||
|
||||
def fetch(self) -> "SessionInstance":
|
||||
"""
|
||||
Fetch the SessionInstance
|
||||
|
||||
|
||||
:returns: The fetched SessionInstance
|
||||
"""
|
||||
return self._proxy.fetch()
|
||||
|
||||
async def fetch_async(self) -> "SessionInstance":
|
||||
"""
|
||||
Asynchronous coroutine to fetch the SessionInstance
|
||||
|
||||
|
||||
:returns: The fetched SessionInstance
|
||||
"""
|
||||
return await self._proxy.fetch_async()
|
||||
|
||||
def update(
|
||||
self,
|
||||
date_expiry: Union[datetime, object] = values.unset,
|
||||
ttl: Union[int, object] = values.unset,
|
||||
status: Union["SessionInstance.Status", object] = values.unset,
|
||||
) -> "SessionInstance":
|
||||
"""
|
||||
Update the SessionInstance
|
||||
|
||||
:param date_expiry: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the `ttl` value.
|
||||
:param ttl: The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.
|
||||
:param status:
|
||||
|
||||
:returns: The updated SessionInstance
|
||||
"""
|
||||
return self._proxy.update(
|
||||
date_expiry=date_expiry,
|
||||
ttl=ttl,
|
||||
status=status,
|
||||
)
|
||||
|
||||
async def update_async(
|
||||
self,
|
||||
date_expiry: Union[datetime, object] = values.unset,
|
||||
ttl: Union[int, object] = values.unset,
|
||||
status: Union["SessionInstance.Status", object] = values.unset,
|
||||
) -> "SessionInstance":
|
||||
"""
|
||||
Asynchronous coroutine to update the SessionInstance
|
||||
|
||||
:param date_expiry: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the `ttl` value.
|
||||
:param ttl: The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.
|
||||
:param status:
|
||||
|
||||
:returns: The updated SessionInstance
|
||||
"""
|
||||
return await self._proxy.update_async(
|
||||
date_expiry=date_expiry,
|
||||
ttl=ttl,
|
||||
status=status,
|
||||
)
|
||||
|
||||
@property
|
||||
def interactions(self) -> InteractionList:
|
||||
"""
|
||||
Access the interactions
|
||||
"""
|
||||
return self._proxy.interactions
|
||||
|
||||
@property
|
||||
def participants(self) -> ParticipantList:
|
||||
"""
|
||||
Access the participants
|
||||
"""
|
||||
return self._proxy.participants
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.SessionInstance {}>".format(context)
|
||||
|
||||
|
||||
class SessionContext(InstanceContext):
|
||||
def __init__(self, version: Version, service_sid: str, sid: str):
|
||||
"""
|
||||
Initialize the SessionContext
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the resource to update.
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Session resource to update.
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"sid": sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/Sessions/{sid}".format(**self._solution)
|
||||
|
||||
self._interactions: Optional[InteractionList] = None
|
||||
self._participants: Optional[ParticipantList] = None
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the SessionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._version.delete(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the SessionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._version.delete_async(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
def fetch(self) -> SessionInstance:
|
||||
"""
|
||||
Fetch the SessionInstance
|
||||
|
||||
|
||||
:returns: The fetched SessionInstance
|
||||
"""
|
||||
|
||||
payload = self._version.fetch(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return SessionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def fetch_async(self) -> SessionInstance:
|
||||
"""
|
||||
Asynchronous coroutine to fetch the SessionInstance
|
||||
|
||||
|
||||
:returns: The fetched SessionInstance
|
||||
"""
|
||||
|
||||
payload = await self._version.fetch_async(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return SessionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def update(
|
||||
self,
|
||||
date_expiry: Union[datetime, object] = values.unset,
|
||||
ttl: Union[int, object] = values.unset,
|
||||
status: Union["SessionInstance.Status", object] = values.unset,
|
||||
) -> SessionInstance:
|
||||
"""
|
||||
Update the SessionInstance
|
||||
|
||||
:param date_expiry: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the `ttl` value.
|
||||
:param ttl: The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.
|
||||
:param status:
|
||||
|
||||
:returns: The updated SessionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"DateExpiry": serialize.iso8601_datetime(date_expiry),
|
||||
"Ttl": ttl,
|
||||
"Status": status,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.update(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return SessionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def update_async(
|
||||
self,
|
||||
date_expiry: Union[datetime, object] = values.unset,
|
||||
ttl: Union[int, object] = values.unset,
|
||||
status: Union["SessionInstance.Status", object] = values.unset,
|
||||
) -> SessionInstance:
|
||||
"""
|
||||
Asynchronous coroutine to update the SessionInstance
|
||||
|
||||
:param date_expiry: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the `ttl` value.
|
||||
:param ttl: The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.
|
||||
:param status:
|
||||
|
||||
:returns: The updated SessionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"DateExpiry": serialize.iso8601_datetime(date_expiry),
|
||||
"Ttl": ttl,
|
||||
"Status": status,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.update_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return SessionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
@property
|
||||
def interactions(self) -> InteractionList:
|
||||
"""
|
||||
Access the interactions
|
||||
"""
|
||||
if self._interactions is None:
|
||||
self._interactions = InteractionList(
|
||||
self._version,
|
||||
self._solution["service_sid"],
|
||||
self._solution["sid"],
|
||||
)
|
||||
return self._interactions
|
||||
|
||||
@property
|
||||
def participants(self) -> ParticipantList:
|
||||
"""
|
||||
Access the participants
|
||||
"""
|
||||
if self._participants is None:
|
||||
self._participants = ParticipantList(
|
||||
self._version,
|
||||
self._solution["service_sid"],
|
||||
self._solution["sid"],
|
||||
)
|
||||
return self._participants
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.SessionContext {}>".format(context)
|
||||
|
||||
|
||||
class SessionPage(Page):
|
||||
def get_instance(self, payload: Dict[str, Any]) -> SessionInstance:
|
||||
"""
|
||||
Build an instance of SessionInstance
|
||||
|
||||
:param payload: Payload response from the API
|
||||
"""
|
||||
return SessionInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.SessionPage>"
|
||||
|
||||
|
||||
class SessionList(ListResource):
|
||||
def __init__(self, version: Version, service_sid: str):
|
||||
"""
|
||||
Initialize the SessionList
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the resource to read.
|
||||
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/Sessions".format(**self._solution)
|
||||
|
||||
def create(
|
||||
self,
|
||||
unique_name: Union[str, object] = values.unset,
|
||||
date_expiry: Union[datetime, object] = values.unset,
|
||||
ttl: Union[int, object] = values.unset,
|
||||
mode: Union["SessionInstance.Mode", object] = values.unset,
|
||||
status: Union["SessionInstance.Status", object] = values.unset,
|
||||
participants: Union[List[object], object] = values.unset,
|
||||
) -> SessionInstance:
|
||||
"""
|
||||
Create the SessionInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param date_expiry: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the `ttl` value.
|
||||
:param ttl: The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.
|
||||
:param mode:
|
||||
:param status:
|
||||
:param participants: The Participant objects to include in the new session.
|
||||
|
||||
:returns: The created SessionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"UniqueName": unique_name,
|
||||
"DateExpiry": serialize.iso8601_datetime(date_expiry),
|
||||
"Ttl": ttl,
|
||||
"Mode": mode,
|
||||
"Status": status,
|
||||
"Participants": serialize.map(
|
||||
participants, lambda e: serialize.object(e)
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.create(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return SessionInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
async def create_async(
|
||||
self,
|
||||
unique_name: Union[str, object] = values.unset,
|
||||
date_expiry: Union[datetime, object] = values.unset,
|
||||
ttl: Union[int, object] = values.unset,
|
||||
mode: Union["SessionInstance.Mode", object] = values.unset,
|
||||
status: Union["SessionInstance.Status", object] = values.unset,
|
||||
participants: Union[List[object], object] = values.unset,
|
||||
) -> SessionInstance:
|
||||
"""
|
||||
Asynchronously create the SessionInstance
|
||||
|
||||
:param unique_name: An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. **This value should not have PII.**
|
||||
:param date_expiry: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Session should expire. If this is value is present, it overrides the `ttl` value.
|
||||
:param ttl: The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.
|
||||
:param mode:
|
||||
:param status:
|
||||
:param participants: The Participant objects to include in the new session.
|
||||
|
||||
:returns: The created SessionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"UniqueName": unique_name,
|
||||
"DateExpiry": serialize.iso8601_datetime(date_expiry),
|
||||
"Ttl": ttl,
|
||||
"Mode": mode,
|
||||
"Status": status,
|
||||
"Participants": serialize.map(
|
||||
participants, lambda e: serialize.object(e)
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.create_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return SessionInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
def stream(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> Iterator[SessionInstance]:
|
||||
"""
|
||||
Streams SessionInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = self.page(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream(page, limits["limit"])
|
||||
|
||||
async def stream_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> AsyncIterator[SessionInstance]:
|
||||
"""
|
||||
Asynchronously streams SessionInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = await self.page_async(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream_async(page, limits["limit"])
|
||||
|
||||
def list(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[SessionInstance]:
|
||||
"""
|
||||
Lists SessionInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return list(
|
||||
self.stream(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
)
|
||||
|
||||
async def list_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[SessionInstance]:
|
||||
"""
|
||||
Asynchronously lists SessionInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return [
|
||||
record
|
||||
async for record in await self.stream_async(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
]
|
||||
|
||||
def page(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> SessionPage:
|
||||
"""
|
||||
Retrieve a single page of SessionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of SessionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = self._version.page(method="GET", uri=self._uri, params=data)
|
||||
return SessionPage(self._version, response, self._solution)
|
||||
|
||||
async def page_async(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> SessionPage:
|
||||
"""
|
||||
Asynchronously retrieve a single page of SessionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of SessionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = await self._version.page_async(
|
||||
method="GET", uri=self._uri, params=data
|
||||
)
|
||||
return SessionPage(self._version, response, self._solution)
|
||||
|
||||
def get_page(self, target_url: str) -> SessionPage:
|
||||
"""
|
||||
Retrieve a specific page of SessionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of SessionInstance
|
||||
"""
|
||||
response = self._version.domain.twilio.request("GET", target_url)
|
||||
return SessionPage(self._version, response, self._solution)
|
||||
|
||||
async def get_page_async(self, target_url: str) -> SessionPage:
|
||||
"""
|
||||
Asynchronously retrieve a specific page of SessionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of SessionInstance
|
||||
"""
|
||||
response = await self._version.domain.twilio.request_async("GET", target_url)
|
||||
return SessionPage(self._version, response, self._solution)
|
||||
|
||||
def get(self, sid: str) -> SessionContext:
|
||||
"""
|
||||
Constructs a SessionContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Session resource to update.
|
||||
"""
|
||||
return SessionContext(
|
||||
self._version, service_sid=self._solution["service_sid"], sid=sid
|
||||
)
|
||||
|
||||
def __call__(self, sid: str) -> SessionContext:
|
||||
"""
|
||||
Constructs a SessionContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Session resource to update.
|
||||
"""
|
||||
return SessionContext(
|
||||
self._version, service_sid=self._solution["service_sid"], sid=sid
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.SessionList>"
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+552
@@ -0,0 +1,552 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
|
||||
from twilio.base import deserialize, values
|
||||
from twilio.base.instance_context import InstanceContext
|
||||
from twilio.base.instance_resource import InstanceResource
|
||||
from twilio.base.list_resource import ListResource
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.page import Page
|
||||
|
||||
|
||||
class InteractionInstance(InstanceResource):
|
||||
class ResourceStatus(object):
|
||||
ACCEPTED = "accepted"
|
||||
ANSWERED = "answered"
|
||||
BUSY = "busy"
|
||||
CANCELED = "canceled"
|
||||
COMPLETED = "completed"
|
||||
DELETED = "deleted"
|
||||
DELIVERED = "delivered"
|
||||
DELIVERY_UNKNOWN = "delivery-unknown"
|
||||
FAILED = "failed"
|
||||
IN_PROGRESS = "in-progress"
|
||||
INITIATED = "initiated"
|
||||
NO_ANSWER = "no-answer"
|
||||
QUEUED = "queued"
|
||||
RECEIVED = "received"
|
||||
RECEIVING = "receiving"
|
||||
RINGING = "ringing"
|
||||
SCHEDULED = "scheduled"
|
||||
SENDING = "sending"
|
||||
SENT = "sent"
|
||||
UNDELIVERED = "undelivered"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
class Type(object):
|
||||
MESSAGE = "message"
|
||||
VOICE = "voice"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
"""
|
||||
:ivar sid: The unique string that we created to identify the Interaction resource.
|
||||
:ivar session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) resource.
|
||||
:ivar service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) resource.
|
||||
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Interaction resource.
|
||||
:ivar data: A JSON string that includes the message body of message interactions (e.g. `{\"body\": \"hello\"}`) or the call duration (when available) of a call (e.g. `{\"duration\": \"5\"}`).
|
||||
:ivar type:
|
||||
:ivar inbound_participant_sid: The SID of the inbound [Participant](https://www.twilio.com/docs/proxy/api/participant) resource.
|
||||
:ivar inbound_resource_sid: The SID of the inbound resource; either the [Call](https://www.twilio.com/docs/voice/api/call-resource) or [Message](https://www.twilio.com/docs/sms/api/message.
|
||||
:ivar inbound_resource_status:
|
||||
:ivar inbound_resource_type: The inbound resource type. Can be [Call](https://www.twilio.com/docs/voice/api/call-resource) or [Message](https://www.twilio.com/docs/sms/api/message-resource).
|
||||
:ivar inbound_resource_url: The URL of the Twilio inbound resource
|
||||
:ivar outbound_participant_sid: The SID of the outbound [Participant](https://www.twilio.com/docs/proxy/api/participant)).
|
||||
:ivar outbound_resource_sid: The SID of the outbound resource; either the [Call](https://www.twilio.com/docs/voice/api/call-resource) or [Message](https://www.twilio.com/docs/sms/api/message-resource).
|
||||
:ivar outbound_resource_status:
|
||||
:ivar outbound_resource_type: The outbound resource type. Can be: [Call](https://www.twilio.com/docs/voice/api/call-resource) or [Message](https://www.twilio.com/docs/sms/api/message-resource).
|
||||
:ivar outbound_resource_url: The URL of the Twilio outbound resource.
|
||||
:ivar date_created: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the Interaction was created.
|
||||
:ivar date_updated: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was last updated.
|
||||
:ivar url: The absolute URL of the Interaction resource.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version: Version,
|
||||
payload: Dict[str, Any],
|
||||
service_sid: str,
|
||||
session_sid: str,
|
||||
sid: Optional[str] = None,
|
||||
):
|
||||
super().__init__(version)
|
||||
|
||||
self.sid: Optional[str] = payload.get("sid")
|
||||
self.session_sid: Optional[str] = payload.get("session_sid")
|
||||
self.service_sid: Optional[str] = payload.get("service_sid")
|
||||
self.account_sid: Optional[str] = payload.get("account_sid")
|
||||
self.data: Optional[str] = payload.get("data")
|
||||
self.type: Optional["InteractionInstance.Type"] = payload.get("type")
|
||||
self.inbound_participant_sid: Optional[str] = payload.get(
|
||||
"inbound_participant_sid"
|
||||
)
|
||||
self.inbound_resource_sid: Optional[str] = payload.get("inbound_resource_sid")
|
||||
self.inbound_resource_status: Optional[
|
||||
"InteractionInstance.ResourceStatus"
|
||||
] = payload.get("inbound_resource_status")
|
||||
self.inbound_resource_type: Optional[str] = payload.get("inbound_resource_type")
|
||||
self.inbound_resource_url: Optional[str] = payload.get("inbound_resource_url")
|
||||
self.outbound_participant_sid: Optional[str] = payload.get(
|
||||
"outbound_participant_sid"
|
||||
)
|
||||
self.outbound_resource_sid: Optional[str] = payload.get("outbound_resource_sid")
|
||||
self.outbound_resource_status: Optional[
|
||||
"InteractionInstance.ResourceStatus"
|
||||
] = payload.get("outbound_resource_status")
|
||||
self.outbound_resource_type: Optional[str] = payload.get(
|
||||
"outbound_resource_type"
|
||||
)
|
||||
self.outbound_resource_url: Optional[str] = payload.get("outbound_resource_url")
|
||||
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_created")
|
||||
)
|
||||
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_updated")
|
||||
)
|
||||
self.url: Optional[str] = payload.get("url")
|
||||
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
"sid": sid or self.sid,
|
||||
}
|
||||
self._context: Optional[InteractionContext] = None
|
||||
|
||||
@property
|
||||
def _proxy(self) -> "InteractionContext":
|
||||
"""
|
||||
Generate an instance context for the instance, the context is capable of
|
||||
performing various actions. All instance actions are proxied to the context
|
||||
|
||||
:returns: InteractionContext for this InteractionInstance
|
||||
"""
|
||||
if self._context is None:
|
||||
self._context = InteractionContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
return self._context
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the InteractionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._proxy.delete()
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the InteractionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._proxy.delete_async()
|
||||
|
||||
def fetch(self) -> "InteractionInstance":
|
||||
"""
|
||||
Fetch the InteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched InteractionInstance
|
||||
"""
|
||||
return self._proxy.fetch()
|
||||
|
||||
async def fetch_async(self) -> "InteractionInstance":
|
||||
"""
|
||||
Asynchronous coroutine to fetch the InteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched InteractionInstance
|
||||
"""
|
||||
return await self._proxy.fetch_async()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.InteractionInstance {}>".format(context)
|
||||
|
||||
|
||||
class InteractionContext(InstanceContext):
|
||||
def __init__(self, version: Version, service_sid: str, session_sid: str, sid: str):
|
||||
"""
|
||||
Initialize the InteractionContext
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the resource to fetch.
|
||||
:param session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) of the resource to fetch.
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Interaction resource to fetch.
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
"sid": sid,
|
||||
}
|
||||
self._uri = (
|
||||
"/Services/{service_sid}/Sessions/{session_sid}/Interactions/{sid}".format(
|
||||
**self._solution
|
||||
)
|
||||
)
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the InteractionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._version.delete(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the InteractionInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._version.delete_async(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
def fetch(self) -> InteractionInstance:
|
||||
"""
|
||||
Fetch the InteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched InteractionInstance
|
||||
"""
|
||||
|
||||
payload = self._version.fetch(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return InteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def fetch_async(self) -> InteractionInstance:
|
||||
"""
|
||||
Asynchronous coroutine to fetch the InteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched InteractionInstance
|
||||
"""
|
||||
|
||||
payload = await self._version.fetch_async(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return InteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.InteractionContext {}>".format(context)
|
||||
|
||||
|
||||
class InteractionPage(Page):
|
||||
def get_instance(self, payload: Dict[str, Any]) -> InteractionInstance:
|
||||
"""
|
||||
Build an instance of InteractionInstance
|
||||
|
||||
:param payload: Payload response from the API
|
||||
"""
|
||||
return InteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.InteractionPage>"
|
||||
|
||||
|
||||
class InteractionList(ListResource):
|
||||
def __init__(self, version: Version, service_sid: str, session_sid: str):
|
||||
"""
|
||||
Initialize the InteractionList
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) to read the resources from.
|
||||
:param session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) to read the resources from.
|
||||
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
}
|
||||
self._uri = (
|
||||
"/Services/{service_sid}/Sessions/{session_sid}/Interactions".format(
|
||||
**self._solution
|
||||
)
|
||||
)
|
||||
|
||||
def stream(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> Iterator[InteractionInstance]:
|
||||
"""
|
||||
Streams InteractionInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = self.page(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream(page, limits["limit"])
|
||||
|
||||
async def stream_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> AsyncIterator[InteractionInstance]:
|
||||
"""
|
||||
Asynchronously streams InteractionInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = await self.page_async(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream_async(page, limits["limit"])
|
||||
|
||||
def list(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[InteractionInstance]:
|
||||
"""
|
||||
Lists InteractionInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return list(
|
||||
self.stream(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
)
|
||||
|
||||
async def list_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[InteractionInstance]:
|
||||
"""
|
||||
Asynchronously lists InteractionInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return [
|
||||
record
|
||||
async for record in await self.stream_async(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
]
|
||||
|
||||
def page(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> InteractionPage:
|
||||
"""
|
||||
Retrieve a single page of InteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of InteractionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = self._version.page(method="GET", uri=self._uri, params=data)
|
||||
return InteractionPage(self._version, response, self._solution)
|
||||
|
||||
async def page_async(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> InteractionPage:
|
||||
"""
|
||||
Asynchronously retrieve a single page of InteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of InteractionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = await self._version.page_async(
|
||||
method="GET", uri=self._uri, params=data
|
||||
)
|
||||
return InteractionPage(self._version, response, self._solution)
|
||||
|
||||
def get_page(self, target_url: str) -> InteractionPage:
|
||||
"""
|
||||
Retrieve a specific page of InteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of InteractionInstance
|
||||
"""
|
||||
response = self._version.domain.twilio.request("GET", target_url)
|
||||
return InteractionPage(self._version, response, self._solution)
|
||||
|
||||
async def get_page_async(self, target_url: str) -> InteractionPage:
|
||||
"""
|
||||
Asynchronously retrieve a specific page of InteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of InteractionInstance
|
||||
"""
|
||||
response = await self._version.domain.twilio.request_async("GET", target_url)
|
||||
return InteractionPage(self._version, response, self._solution)
|
||||
|
||||
def get(self, sid: str) -> InteractionContext:
|
||||
"""
|
||||
Constructs a InteractionContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Interaction resource to fetch.
|
||||
"""
|
||||
return InteractionContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=sid,
|
||||
)
|
||||
|
||||
def __call__(self, sid: str) -> InteractionContext:
|
||||
"""
|
||||
Constructs a InteractionContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Interaction resource to fetch.
|
||||
"""
|
||||
return InteractionContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=sid,
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.InteractionList>"
|
||||
+609
@@ -0,0 +1,609 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
|
||||
from twilio.base import deserialize, values
|
||||
from twilio.base.instance_context import InstanceContext
|
||||
from twilio.base.instance_resource import InstanceResource
|
||||
from twilio.base.list_resource import ListResource
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.page import Page
|
||||
from twilio.rest.proxy.v1.service.session.participant.message_interaction import (
|
||||
MessageInteractionList,
|
||||
)
|
||||
|
||||
|
||||
class ParticipantInstance(InstanceResource):
|
||||
|
||||
"""
|
||||
:ivar sid: The unique string that we created to identify the Participant resource.
|
||||
:ivar session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) resource.
|
||||
:ivar service_sid: The SID of the resource's parent [Service](https://www.twilio.com/docs/proxy/api/service) resource.
|
||||
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Participant resource.
|
||||
:ivar friendly_name: The string that you assigned to describe the participant. This value must be 255 characters or fewer. Supports UTF-8 characters. **This value should not have PII.**
|
||||
:ivar identifier: The phone number or channel identifier of the Participant. This value must be 191 characters or fewer. Supports UTF-8 characters.
|
||||
:ivar proxy_identifier: The phone number or short code (masked number) of the participant's partner. The participant will call or message the partner participant at this number.
|
||||
:ivar proxy_identifier_sid: The SID of the Proxy Identifier assigned to the Participant.
|
||||
:ivar date_deleted: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date when the Participant was removed from the session.
|
||||
:ivar date_created: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was created.
|
||||
:ivar date_updated: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was last updated.
|
||||
:ivar url: The absolute URL of the Participant resource.
|
||||
:ivar links: The URLs to resources related the participant.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version: Version,
|
||||
payload: Dict[str, Any],
|
||||
service_sid: str,
|
||||
session_sid: str,
|
||||
sid: Optional[str] = None,
|
||||
):
|
||||
super().__init__(version)
|
||||
|
||||
self.sid: Optional[str] = payload.get("sid")
|
||||
self.session_sid: Optional[str] = payload.get("session_sid")
|
||||
self.service_sid: Optional[str] = payload.get("service_sid")
|
||||
self.account_sid: Optional[str] = payload.get("account_sid")
|
||||
self.friendly_name: Optional[str] = payload.get("friendly_name")
|
||||
self.identifier: Optional[str] = payload.get("identifier")
|
||||
self.proxy_identifier: Optional[str] = payload.get("proxy_identifier")
|
||||
self.proxy_identifier_sid: Optional[str] = payload.get("proxy_identifier_sid")
|
||||
self.date_deleted: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_deleted")
|
||||
)
|
||||
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_created")
|
||||
)
|
||||
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_updated")
|
||||
)
|
||||
self.url: Optional[str] = payload.get("url")
|
||||
self.links: Optional[Dict[str, object]] = payload.get("links")
|
||||
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
"sid": sid or self.sid,
|
||||
}
|
||||
self._context: Optional[ParticipantContext] = None
|
||||
|
||||
@property
|
||||
def _proxy(self) -> "ParticipantContext":
|
||||
"""
|
||||
Generate an instance context for the instance, the context is capable of
|
||||
performing various actions. All instance actions are proxied to the context
|
||||
|
||||
:returns: ParticipantContext for this ParticipantInstance
|
||||
"""
|
||||
if self._context is None:
|
||||
self._context = ParticipantContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
return self._context
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the ParticipantInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._proxy.delete()
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the ParticipantInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._proxy.delete_async()
|
||||
|
||||
def fetch(self) -> "ParticipantInstance":
|
||||
"""
|
||||
Fetch the ParticipantInstance
|
||||
|
||||
|
||||
:returns: The fetched ParticipantInstance
|
||||
"""
|
||||
return self._proxy.fetch()
|
||||
|
||||
async def fetch_async(self) -> "ParticipantInstance":
|
||||
"""
|
||||
Asynchronous coroutine to fetch the ParticipantInstance
|
||||
|
||||
|
||||
:returns: The fetched ParticipantInstance
|
||||
"""
|
||||
return await self._proxy.fetch_async()
|
||||
|
||||
@property
|
||||
def message_interactions(self) -> MessageInteractionList:
|
||||
"""
|
||||
Access the message_interactions
|
||||
"""
|
||||
return self._proxy.message_interactions
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.ParticipantInstance {}>".format(context)
|
||||
|
||||
|
||||
class ParticipantContext(InstanceContext):
|
||||
def __init__(self, version: Version, service_sid: str, session_sid: str, sid: str):
|
||||
"""
|
||||
Initialize the ParticipantContext
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the resource to fetch.
|
||||
:param session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) of the resource to fetch.
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Participant resource to fetch.
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
"sid": sid,
|
||||
}
|
||||
self._uri = (
|
||||
"/Services/{service_sid}/Sessions/{session_sid}/Participants/{sid}".format(
|
||||
**self._solution
|
||||
)
|
||||
)
|
||||
|
||||
self._message_interactions: Optional[MessageInteractionList] = None
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the ParticipantInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._version.delete(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the ParticipantInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._version.delete_async(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
def fetch(self) -> ParticipantInstance:
|
||||
"""
|
||||
Fetch the ParticipantInstance
|
||||
|
||||
|
||||
:returns: The fetched ParticipantInstance
|
||||
"""
|
||||
|
||||
payload = self._version.fetch(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return ParticipantInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def fetch_async(self) -> ParticipantInstance:
|
||||
"""
|
||||
Asynchronous coroutine to fetch the ParticipantInstance
|
||||
|
||||
|
||||
:returns: The fetched ParticipantInstance
|
||||
"""
|
||||
|
||||
payload = await self._version.fetch_async(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return ParticipantInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
@property
|
||||
def message_interactions(self) -> MessageInteractionList:
|
||||
"""
|
||||
Access the message_interactions
|
||||
"""
|
||||
if self._message_interactions is None:
|
||||
self._message_interactions = MessageInteractionList(
|
||||
self._version,
|
||||
self._solution["service_sid"],
|
||||
self._solution["session_sid"],
|
||||
self._solution["sid"],
|
||||
)
|
||||
return self._message_interactions
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.ParticipantContext {}>".format(context)
|
||||
|
||||
|
||||
class ParticipantPage(Page):
|
||||
def get_instance(self, payload: Dict[str, Any]) -> ParticipantInstance:
|
||||
"""
|
||||
Build an instance of ParticipantInstance
|
||||
|
||||
:param payload: Payload response from the API
|
||||
"""
|
||||
return ParticipantInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.ParticipantPage>"
|
||||
|
||||
|
||||
class ParticipantList(ListResource):
|
||||
def __init__(self, version: Version, service_sid: str, session_sid: str):
|
||||
"""
|
||||
Initialize the ParticipantList
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the resources to read.
|
||||
:param session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) of the resources to read.
|
||||
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
}
|
||||
self._uri = (
|
||||
"/Services/{service_sid}/Sessions/{session_sid}/Participants".format(
|
||||
**self._solution
|
||||
)
|
||||
)
|
||||
|
||||
def create(
|
||||
self,
|
||||
identifier: str,
|
||||
friendly_name: Union[str, object] = values.unset,
|
||||
proxy_identifier: Union[str, object] = values.unset,
|
||||
proxy_identifier_sid: Union[str, object] = values.unset,
|
||||
) -> ParticipantInstance:
|
||||
"""
|
||||
Create the ParticipantInstance
|
||||
|
||||
:param identifier: The phone number of the Participant.
|
||||
:param friendly_name: The string that you assigned to describe the participant. This value must be 255 characters or fewer. **This value should not have PII.**
|
||||
:param proxy_identifier: The proxy phone number to use for the Participant. If not specified, Proxy will select a number from the pool.
|
||||
:param proxy_identifier_sid: The SID of the Proxy Identifier to assign to the Participant.
|
||||
|
||||
:returns: The created ParticipantInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Identifier": identifier,
|
||||
"FriendlyName": friendly_name,
|
||||
"ProxyIdentifier": proxy_identifier,
|
||||
"ProxyIdentifierSid": proxy_identifier_sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.create(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ParticipantInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
)
|
||||
|
||||
async def create_async(
|
||||
self,
|
||||
identifier: str,
|
||||
friendly_name: Union[str, object] = values.unset,
|
||||
proxy_identifier: Union[str, object] = values.unset,
|
||||
proxy_identifier_sid: Union[str, object] = values.unset,
|
||||
) -> ParticipantInstance:
|
||||
"""
|
||||
Asynchronously create the ParticipantInstance
|
||||
|
||||
:param identifier: The phone number of the Participant.
|
||||
:param friendly_name: The string that you assigned to describe the participant. This value must be 255 characters or fewer. **This value should not have PII.**
|
||||
:param proxy_identifier: The proxy phone number to use for the Participant. If not specified, Proxy will select a number from the pool.
|
||||
:param proxy_identifier_sid: The SID of the Proxy Identifier to assign to the Participant.
|
||||
|
||||
:returns: The created ParticipantInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Identifier": identifier,
|
||||
"FriendlyName": friendly_name,
|
||||
"ProxyIdentifier": proxy_identifier,
|
||||
"ProxyIdentifierSid": proxy_identifier_sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.create_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ParticipantInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
)
|
||||
|
||||
def stream(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> Iterator[ParticipantInstance]:
|
||||
"""
|
||||
Streams ParticipantInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = self.page(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream(page, limits["limit"])
|
||||
|
||||
async def stream_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> AsyncIterator[ParticipantInstance]:
|
||||
"""
|
||||
Asynchronously streams ParticipantInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = await self.page_async(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream_async(page, limits["limit"])
|
||||
|
||||
def list(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[ParticipantInstance]:
|
||||
"""
|
||||
Lists ParticipantInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return list(
|
||||
self.stream(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
)
|
||||
|
||||
async def list_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[ParticipantInstance]:
|
||||
"""
|
||||
Asynchronously lists ParticipantInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return [
|
||||
record
|
||||
async for record in await self.stream_async(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
]
|
||||
|
||||
def page(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> ParticipantPage:
|
||||
"""
|
||||
Retrieve a single page of ParticipantInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of ParticipantInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = self._version.page(method="GET", uri=self._uri, params=data)
|
||||
return ParticipantPage(self._version, response, self._solution)
|
||||
|
||||
async def page_async(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> ParticipantPage:
|
||||
"""
|
||||
Asynchronously retrieve a single page of ParticipantInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of ParticipantInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = await self._version.page_async(
|
||||
method="GET", uri=self._uri, params=data
|
||||
)
|
||||
return ParticipantPage(self._version, response, self._solution)
|
||||
|
||||
def get_page(self, target_url: str) -> ParticipantPage:
|
||||
"""
|
||||
Retrieve a specific page of ParticipantInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of ParticipantInstance
|
||||
"""
|
||||
response = self._version.domain.twilio.request("GET", target_url)
|
||||
return ParticipantPage(self._version, response, self._solution)
|
||||
|
||||
async def get_page_async(self, target_url: str) -> ParticipantPage:
|
||||
"""
|
||||
Asynchronously retrieve a specific page of ParticipantInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of ParticipantInstance
|
||||
"""
|
||||
response = await self._version.domain.twilio.request_async("GET", target_url)
|
||||
return ParticipantPage(self._version, response, self._solution)
|
||||
|
||||
def get(self, sid: str) -> ParticipantContext:
|
||||
"""
|
||||
Constructs a ParticipantContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Participant resource to fetch.
|
||||
"""
|
||||
return ParticipantContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=sid,
|
||||
)
|
||||
|
||||
def __call__(self, sid: str) -> ParticipantContext:
|
||||
"""
|
||||
Constructs a ParticipantContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the Participant resource to fetch.
|
||||
"""
|
||||
return ParticipantContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
sid=sid,
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.ParticipantList>"
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+597
@@ -0,0 +1,597 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
|
||||
from twilio.base import deserialize, serialize, values
|
||||
from twilio.base.instance_context import InstanceContext
|
||||
from twilio.base.instance_resource import InstanceResource
|
||||
from twilio.base.list_resource import ListResource
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.page import Page
|
||||
|
||||
|
||||
class MessageInteractionInstance(InstanceResource):
|
||||
class ResourceStatus(object):
|
||||
ACCEPTED = "accepted"
|
||||
ANSWERED = "answered"
|
||||
BUSY = "busy"
|
||||
CANCELED = "canceled"
|
||||
COMPLETED = "completed"
|
||||
DELETED = "deleted"
|
||||
DELIVERED = "delivered"
|
||||
DELIVERY_UNKNOWN = "delivery-unknown"
|
||||
FAILED = "failed"
|
||||
IN_PROGRESS = "in-progress"
|
||||
INITIATED = "initiated"
|
||||
NO_ANSWER = "no-answer"
|
||||
QUEUED = "queued"
|
||||
RECEIVED = "received"
|
||||
RECEIVING = "receiving"
|
||||
RINGING = "ringing"
|
||||
SCHEDULED = "scheduled"
|
||||
SENDING = "sending"
|
||||
SENT = "sent"
|
||||
UNDELIVERED = "undelivered"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
class Type(object):
|
||||
MESSAGE = "message"
|
||||
VOICE = "voice"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
"""
|
||||
:ivar sid: The unique string that we created to identify the MessageInteraction resource.
|
||||
:ivar session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) resource.
|
||||
:ivar service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) resource.
|
||||
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the MessageInteraction resource.
|
||||
:ivar data: A JSON string that includes the message body sent to the participant. (e.g. `{\"body\": \"hello\"}`)
|
||||
:ivar type:
|
||||
:ivar participant_sid: The SID of the [Participant](https://www.twilio.com/docs/proxy/api/participant) resource.
|
||||
:ivar inbound_participant_sid: Always empty for created Message Interactions.
|
||||
:ivar inbound_resource_sid: Always empty for created Message Interactions.
|
||||
:ivar inbound_resource_status:
|
||||
:ivar inbound_resource_type: Always empty for created Message Interactions.
|
||||
:ivar inbound_resource_url: Always empty for created Message Interactions.
|
||||
:ivar outbound_participant_sid: The SID of the outbound [Participant](https://www.twilio.com/docs/proxy/api/participant) resource.
|
||||
:ivar outbound_resource_sid: The SID of the outbound [Message](https://www.twilio.com/docs/sms/api/message-resource) resource.
|
||||
:ivar outbound_resource_status:
|
||||
:ivar outbound_resource_type: The outbound resource type. This value is always `Message`.
|
||||
:ivar outbound_resource_url: The URL of the Twilio message resource.
|
||||
:ivar date_created: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was created.
|
||||
:ivar date_updated: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was last updated.
|
||||
:ivar url: The absolute URL of the MessageInteraction resource.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version: Version,
|
||||
payload: Dict[str, Any],
|
||||
service_sid: str,
|
||||
session_sid: str,
|
||||
participant_sid: str,
|
||||
sid: Optional[str] = None,
|
||||
):
|
||||
super().__init__(version)
|
||||
|
||||
self.sid: Optional[str] = payload.get("sid")
|
||||
self.session_sid: Optional[str] = payload.get("session_sid")
|
||||
self.service_sid: Optional[str] = payload.get("service_sid")
|
||||
self.account_sid: Optional[str] = payload.get("account_sid")
|
||||
self.data: Optional[str] = payload.get("data")
|
||||
self.type: Optional["MessageInteractionInstance.Type"] = payload.get("type")
|
||||
self.participant_sid: Optional[str] = payload.get("participant_sid")
|
||||
self.inbound_participant_sid: Optional[str] = payload.get(
|
||||
"inbound_participant_sid"
|
||||
)
|
||||
self.inbound_resource_sid: Optional[str] = payload.get("inbound_resource_sid")
|
||||
self.inbound_resource_status: Optional[
|
||||
"MessageInteractionInstance.ResourceStatus"
|
||||
] = payload.get("inbound_resource_status")
|
||||
self.inbound_resource_type: Optional[str] = payload.get("inbound_resource_type")
|
||||
self.inbound_resource_url: Optional[str] = payload.get("inbound_resource_url")
|
||||
self.outbound_participant_sid: Optional[str] = payload.get(
|
||||
"outbound_participant_sid"
|
||||
)
|
||||
self.outbound_resource_sid: Optional[str] = payload.get("outbound_resource_sid")
|
||||
self.outbound_resource_status: Optional[
|
||||
"MessageInteractionInstance.ResourceStatus"
|
||||
] = payload.get("outbound_resource_status")
|
||||
self.outbound_resource_type: Optional[str] = payload.get(
|
||||
"outbound_resource_type"
|
||||
)
|
||||
self.outbound_resource_url: Optional[str] = payload.get("outbound_resource_url")
|
||||
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_created")
|
||||
)
|
||||
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_updated")
|
||||
)
|
||||
self.url: Optional[str] = payload.get("url")
|
||||
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
"participant_sid": participant_sid,
|
||||
"sid": sid or self.sid,
|
||||
}
|
||||
self._context: Optional[MessageInteractionContext] = None
|
||||
|
||||
@property
|
||||
def _proxy(self) -> "MessageInteractionContext":
|
||||
"""
|
||||
Generate an instance context for the instance, the context is capable of
|
||||
performing various actions. All instance actions are proxied to the context
|
||||
|
||||
:returns: MessageInteractionContext for this MessageInteractionInstance
|
||||
"""
|
||||
if self._context is None:
|
||||
self._context = MessageInteractionContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
return self._context
|
||||
|
||||
def fetch(self) -> "MessageInteractionInstance":
|
||||
"""
|
||||
Fetch the MessageInteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched MessageInteractionInstance
|
||||
"""
|
||||
return self._proxy.fetch()
|
||||
|
||||
async def fetch_async(self) -> "MessageInteractionInstance":
|
||||
"""
|
||||
Asynchronous coroutine to fetch the MessageInteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched MessageInteractionInstance
|
||||
"""
|
||||
return await self._proxy.fetch_async()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.MessageInteractionInstance {}>".format(context)
|
||||
|
||||
|
||||
class MessageInteractionContext(InstanceContext):
|
||||
def __init__(
|
||||
self,
|
||||
version: Version,
|
||||
service_sid: str,
|
||||
session_sid: str,
|
||||
participant_sid: str,
|
||||
sid: str,
|
||||
):
|
||||
"""
|
||||
Initialize the MessageInteractionContext
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the resource to fetch.
|
||||
:param session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) of the resource to fetch.
|
||||
:param participant_sid: The SID of the [Participant](https://www.twilio.com/docs/proxy/api/participant) resource.
|
||||
:param sid: The Twilio-provided string that uniquely identifies the MessageInteraction resource to fetch.
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
"participant_sid": participant_sid,
|
||||
"sid": sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/Sessions/{session_sid}/Participants/{participant_sid}/MessageInteractions/{sid}".format(
|
||||
**self._solution
|
||||
)
|
||||
|
||||
def fetch(self) -> MessageInteractionInstance:
|
||||
"""
|
||||
Fetch the MessageInteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched MessageInteractionInstance
|
||||
"""
|
||||
|
||||
payload = self._version.fetch(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return MessageInteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def fetch_async(self) -> MessageInteractionInstance:
|
||||
"""
|
||||
Asynchronous coroutine to fetch the MessageInteractionInstance
|
||||
|
||||
|
||||
:returns: The fetched MessageInteractionInstance
|
||||
"""
|
||||
|
||||
payload = await self._version.fetch_async(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return MessageInteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.MessageInteractionContext {}>".format(context)
|
||||
|
||||
|
||||
class MessageInteractionPage(Page):
|
||||
def get_instance(self, payload: Dict[str, Any]) -> MessageInteractionInstance:
|
||||
"""
|
||||
Build an instance of MessageInteractionInstance
|
||||
|
||||
:param payload: Payload response from the API
|
||||
"""
|
||||
return MessageInteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.MessageInteractionPage>"
|
||||
|
||||
|
||||
class MessageInteractionList(ListResource):
|
||||
def __init__(
|
||||
self, version: Version, service_sid: str, session_sid: str, participant_sid: str
|
||||
):
|
||||
"""
|
||||
Initialize the MessageInteractionList
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) to read the resources from.
|
||||
:param session_sid: The SID of the parent [Session](https://www.twilio.com/docs/proxy/api/session) to read the resources from.
|
||||
:param participant_sid: The SID of the [Participant](https://www.twilio.com/docs/proxy/api/participant) to read the resources from.
|
||||
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"session_sid": session_sid,
|
||||
"participant_sid": participant_sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/Sessions/{session_sid}/Participants/{participant_sid}/MessageInteractions".format(
|
||||
**self._solution
|
||||
)
|
||||
|
||||
def create(
|
||||
self,
|
||||
body: Union[str, object] = values.unset,
|
||||
media_url: Union[List[str], object] = values.unset,
|
||||
) -> MessageInteractionInstance:
|
||||
"""
|
||||
Create the MessageInteractionInstance
|
||||
|
||||
:param body: The message to send to the participant
|
||||
:param media_url: Reserved. Not currently supported.
|
||||
|
||||
:returns: The created MessageInteractionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Body": body,
|
||||
"MediaUrl": serialize.map(media_url, lambda e: e),
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.create(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return MessageInteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
)
|
||||
|
||||
async def create_async(
|
||||
self,
|
||||
body: Union[str, object] = values.unset,
|
||||
media_url: Union[List[str], object] = values.unset,
|
||||
) -> MessageInteractionInstance:
|
||||
"""
|
||||
Asynchronously create the MessageInteractionInstance
|
||||
|
||||
:param body: The message to send to the participant
|
||||
:param media_url: Reserved. Not currently supported.
|
||||
|
||||
:returns: The created MessageInteractionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Body": body,
|
||||
"MediaUrl": serialize.map(media_url, lambda e: e),
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.create_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return MessageInteractionInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
)
|
||||
|
||||
def stream(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> Iterator[MessageInteractionInstance]:
|
||||
"""
|
||||
Streams MessageInteractionInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = self.page(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream(page, limits["limit"])
|
||||
|
||||
async def stream_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> AsyncIterator[MessageInteractionInstance]:
|
||||
"""
|
||||
Asynchronously streams MessageInteractionInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = await self.page_async(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream_async(page, limits["limit"])
|
||||
|
||||
def list(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[MessageInteractionInstance]:
|
||||
"""
|
||||
Lists MessageInteractionInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return list(
|
||||
self.stream(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
)
|
||||
|
||||
async def list_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[MessageInteractionInstance]:
|
||||
"""
|
||||
Asynchronously lists MessageInteractionInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return [
|
||||
record
|
||||
async for record in await self.stream_async(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
]
|
||||
|
||||
def page(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> MessageInteractionPage:
|
||||
"""
|
||||
Retrieve a single page of MessageInteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of MessageInteractionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = self._version.page(method="GET", uri=self._uri, params=data)
|
||||
return MessageInteractionPage(self._version, response, self._solution)
|
||||
|
||||
async def page_async(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> MessageInteractionPage:
|
||||
"""
|
||||
Asynchronously retrieve a single page of MessageInteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of MessageInteractionInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = await self._version.page_async(
|
||||
method="GET", uri=self._uri, params=data
|
||||
)
|
||||
return MessageInteractionPage(self._version, response, self._solution)
|
||||
|
||||
def get_page(self, target_url: str) -> MessageInteractionPage:
|
||||
"""
|
||||
Retrieve a specific page of MessageInteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of MessageInteractionInstance
|
||||
"""
|
||||
response = self._version.domain.twilio.request("GET", target_url)
|
||||
return MessageInteractionPage(self._version, response, self._solution)
|
||||
|
||||
async def get_page_async(self, target_url: str) -> MessageInteractionPage:
|
||||
"""
|
||||
Asynchronously retrieve a specific page of MessageInteractionInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of MessageInteractionInstance
|
||||
"""
|
||||
response = await self._version.domain.twilio.request_async("GET", target_url)
|
||||
return MessageInteractionPage(self._version, response, self._solution)
|
||||
|
||||
def get(self, sid: str) -> MessageInteractionContext:
|
||||
"""
|
||||
Constructs a MessageInteractionContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the MessageInteraction resource to fetch.
|
||||
"""
|
||||
return MessageInteractionContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
sid=sid,
|
||||
)
|
||||
|
||||
def __call__(self, sid: str) -> MessageInteractionContext:
|
||||
"""
|
||||
Constructs a MessageInteractionContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the MessageInteraction resource to fetch.
|
||||
"""
|
||||
return MessageInteractionContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
session_sid=self._solution["session_sid"],
|
||||
participant_sid=self._solution["participant_sid"],
|
||||
sid=sid,
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.MessageInteractionList>"
|
||||
@@ -0,0 +1,605 @@
|
||||
r"""
|
||||
This code was generated by
|
||||
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
|
||||
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
|
||||
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
|
||||
|
||||
Twilio - Proxy
|
||||
This is the public Twilio REST API.
|
||||
|
||||
NOTE: This class is auto generated by OpenAPI Generator.
|
||||
https://openapi-generator.tech
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator
|
||||
from twilio.base import deserialize, values
|
||||
from twilio.base.instance_context import InstanceContext
|
||||
from twilio.base.instance_resource import InstanceResource
|
||||
from twilio.base.list_resource import ListResource
|
||||
from twilio.base.version import Version
|
||||
from twilio.base.page import Page
|
||||
|
||||
|
||||
class ShortCodeInstance(InstanceResource):
|
||||
|
||||
"""
|
||||
:ivar sid: The unique string that we created to identify the ShortCode resource.
|
||||
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the ShortCode resource.
|
||||
:ivar service_sid: The SID of the ShortCode resource's parent [Service](https://www.twilio.com/docs/proxy/api/service) resource.
|
||||
:ivar date_created: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was created.
|
||||
:ivar date_updated: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time in GMT when the resource was last updated.
|
||||
:ivar short_code: The short code's number.
|
||||
:ivar iso_country: The ISO Country Code for the short code.
|
||||
:ivar capabilities:
|
||||
:ivar url: The absolute URL of the ShortCode resource.
|
||||
:ivar is_reserved: Whether the short code should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
version: Version,
|
||||
payload: Dict[str, Any],
|
||||
service_sid: str,
|
||||
sid: Optional[str] = None,
|
||||
):
|
||||
super().__init__(version)
|
||||
|
||||
self.sid: Optional[str] = payload.get("sid")
|
||||
self.account_sid: Optional[str] = payload.get("account_sid")
|
||||
self.service_sid: Optional[str] = payload.get("service_sid")
|
||||
self.date_created: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_created")
|
||||
)
|
||||
self.date_updated: Optional[datetime] = deserialize.iso8601_datetime(
|
||||
payload.get("date_updated")
|
||||
)
|
||||
self.short_code: Optional[str] = payload.get("short_code")
|
||||
self.iso_country: Optional[str] = payload.get("iso_country")
|
||||
self.capabilities: Optional[str] = payload.get("capabilities")
|
||||
self.url: Optional[str] = payload.get("url")
|
||||
self.is_reserved: Optional[bool] = payload.get("is_reserved")
|
||||
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"sid": sid or self.sid,
|
||||
}
|
||||
self._context: Optional[ShortCodeContext] = None
|
||||
|
||||
@property
|
||||
def _proxy(self) -> "ShortCodeContext":
|
||||
"""
|
||||
Generate an instance context for the instance, the context is capable of
|
||||
performing various actions. All instance actions are proxied to the context
|
||||
|
||||
:returns: ShortCodeContext for this ShortCodeInstance
|
||||
"""
|
||||
if self._context is None:
|
||||
self._context = ShortCodeContext(
|
||||
self._version,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
return self._context
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._proxy.delete()
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._proxy.delete_async()
|
||||
|
||||
def fetch(self) -> "ShortCodeInstance":
|
||||
"""
|
||||
Fetch the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: The fetched ShortCodeInstance
|
||||
"""
|
||||
return self._proxy.fetch()
|
||||
|
||||
async def fetch_async(self) -> "ShortCodeInstance":
|
||||
"""
|
||||
Asynchronous coroutine to fetch the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: The fetched ShortCodeInstance
|
||||
"""
|
||||
return await self._proxy.fetch_async()
|
||||
|
||||
def update(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> "ShortCodeInstance":
|
||||
"""
|
||||
Update the ShortCodeInstance
|
||||
|
||||
:param is_reserved: Whether the short code should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated ShortCodeInstance
|
||||
"""
|
||||
return self._proxy.update(
|
||||
is_reserved=is_reserved,
|
||||
)
|
||||
|
||||
async def update_async(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> "ShortCodeInstance":
|
||||
"""
|
||||
Asynchronous coroutine to update the ShortCodeInstance
|
||||
|
||||
:param is_reserved: Whether the short code should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated ShortCodeInstance
|
||||
"""
|
||||
return await self._proxy.update_async(
|
||||
is_reserved=is_reserved,
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.ShortCodeInstance {}>".format(context)
|
||||
|
||||
|
||||
class ShortCodeContext(InstanceContext):
|
||||
def __init__(self, version: Version, service_sid: str, sid: str):
|
||||
"""
|
||||
Initialize the ShortCodeContext
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) of the resource to update.
|
||||
:param sid: The Twilio-provided string that uniquely identifies the ShortCode resource to update.
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
"sid": sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/ShortCodes/{sid}".format(**self._solution)
|
||||
|
||||
def delete(self) -> bool:
|
||||
"""
|
||||
Deletes the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return self._version.delete(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
async def delete_async(self) -> bool:
|
||||
"""
|
||||
Asynchronous coroutine that deletes the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: True if delete succeeds, False otherwise
|
||||
"""
|
||||
return await self._version.delete_async(
|
||||
method="DELETE",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
def fetch(self) -> ShortCodeInstance:
|
||||
"""
|
||||
Fetch the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: The fetched ShortCodeInstance
|
||||
"""
|
||||
|
||||
payload = self._version.fetch(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return ShortCodeInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def fetch_async(self) -> ShortCodeInstance:
|
||||
"""
|
||||
Asynchronous coroutine to fetch the ShortCodeInstance
|
||||
|
||||
|
||||
:returns: The fetched ShortCodeInstance
|
||||
"""
|
||||
|
||||
payload = await self._version.fetch_async(
|
||||
method="GET",
|
||||
uri=self._uri,
|
||||
)
|
||||
|
||||
return ShortCodeInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def update(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> ShortCodeInstance:
|
||||
"""
|
||||
Update the ShortCodeInstance
|
||||
|
||||
:param is_reserved: Whether the short code should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated ShortCodeInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"IsReserved": is_reserved,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.update(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ShortCodeInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
async def update_async(
|
||||
self, is_reserved: Union[bool, object] = values.unset
|
||||
) -> ShortCodeInstance:
|
||||
"""
|
||||
Asynchronous coroutine to update the ShortCodeInstance
|
||||
|
||||
:param is_reserved: Whether the short code should be reserved and not be assigned to a participant using proxy pool logic. See [Reserved Phone Numbers](https://www.twilio.com/docs/proxy/reserved-phone-numbers) for more information.
|
||||
|
||||
:returns: The updated ShortCodeInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"IsReserved": is_reserved,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.update_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ShortCodeInstance(
|
||||
self._version,
|
||||
payload,
|
||||
service_sid=self._solution["service_sid"],
|
||||
sid=self._solution["sid"],
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
context = " ".join("{}={}".format(k, v) for k, v in self._solution.items())
|
||||
return "<Twilio.Proxy.V1.ShortCodeContext {}>".format(context)
|
||||
|
||||
|
||||
class ShortCodePage(Page):
|
||||
def get_instance(self, payload: Dict[str, Any]) -> ShortCodeInstance:
|
||||
"""
|
||||
Build an instance of ShortCodeInstance
|
||||
|
||||
:param payload: Payload response from the API
|
||||
"""
|
||||
return ShortCodeInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.ShortCodePage>"
|
||||
|
||||
|
||||
class ShortCodeList(ListResource):
|
||||
def __init__(self, version: Version, service_sid: str):
|
||||
"""
|
||||
Initialize the ShortCodeList
|
||||
|
||||
:param version: Version that contains the resource
|
||||
:param service_sid: The SID of the parent [Service](https://www.twilio.com/docs/proxy/api/service) to read the resources from.
|
||||
|
||||
"""
|
||||
super().__init__(version)
|
||||
|
||||
# Path Solution
|
||||
self._solution = {
|
||||
"service_sid": service_sid,
|
||||
}
|
||||
self._uri = "/Services/{service_sid}/ShortCodes".format(**self._solution)
|
||||
|
||||
def create(self, sid: str) -> ShortCodeInstance:
|
||||
"""
|
||||
Create the ShortCodeInstance
|
||||
|
||||
:param sid: The SID of a Twilio [ShortCode](https://www.twilio.com/docs/sms/api/short-code) resource that represents the short code you would like to assign to your Proxy Service.
|
||||
|
||||
:returns: The created ShortCodeInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Sid": sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = self._version.create(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ShortCodeInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
async def create_async(self, sid: str) -> ShortCodeInstance:
|
||||
"""
|
||||
Asynchronously create the ShortCodeInstance
|
||||
|
||||
:param sid: The SID of a Twilio [ShortCode](https://www.twilio.com/docs/sms/api/short-code) resource that represents the short code you would like to assign to your Proxy Service.
|
||||
|
||||
:returns: The created ShortCodeInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"Sid": sid,
|
||||
}
|
||||
)
|
||||
|
||||
payload = await self._version.create_async(
|
||||
method="POST",
|
||||
uri=self._uri,
|
||||
data=data,
|
||||
)
|
||||
|
||||
return ShortCodeInstance(
|
||||
self._version, payload, service_sid=self._solution["service_sid"]
|
||||
)
|
||||
|
||||
def stream(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> Iterator[ShortCodeInstance]:
|
||||
"""
|
||||
Streams ShortCodeInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = self.page(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream(page, limits["limit"])
|
||||
|
||||
async def stream_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> AsyncIterator[ShortCodeInstance]:
|
||||
"""
|
||||
Asynchronously streams ShortCodeInstance records from the API as a generator stream.
|
||||
This operation lazily loads records as efficiently as possible until the limit
|
||||
is reached.
|
||||
The results are returned as a generator, so this operation is memory efficient.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. stream()
|
||||
guarantees to never return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, stream() will attempt to read the
|
||||
limit with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: Generator that will yield up to limit results
|
||||
"""
|
||||
limits = self._version.read_limits(limit, page_size)
|
||||
page = await self.page_async(page_size=limits["page_size"])
|
||||
|
||||
return self._version.stream_async(page, limits["limit"])
|
||||
|
||||
def list(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[ShortCodeInstance]:
|
||||
"""
|
||||
Lists ShortCodeInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return list(
|
||||
self.stream(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
)
|
||||
|
||||
async def list_async(
|
||||
self,
|
||||
limit: Optional[int] = None,
|
||||
page_size: Optional[int] = None,
|
||||
) -> List[ShortCodeInstance]:
|
||||
"""
|
||||
Asynchronously lists ShortCodeInstance records from the API as a list.
|
||||
Unlike stream(), this operation is eager and will load `limit` records into
|
||||
memory before returning.
|
||||
|
||||
:param limit: Upper limit for the number of records to return. list() guarantees
|
||||
never to return more than limit. Default is no limit
|
||||
:param page_size: Number of records to fetch per request, when not set will use
|
||||
the default value of 50 records. If no page_size is defined
|
||||
but a limit is defined, list() will attempt to read the limit
|
||||
with the most efficient page size, i.e. min(limit, 1000)
|
||||
|
||||
:returns: list that will contain up to limit results
|
||||
"""
|
||||
return [
|
||||
record
|
||||
async for record in await self.stream_async(
|
||||
limit=limit,
|
||||
page_size=page_size,
|
||||
)
|
||||
]
|
||||
|
||||
def page(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> ShortCodePage:
|
||||
"""
|
||||
Retrieve a single page of ShortCodeInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of ShortCodeInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = self._version.page(method="GET", uri=self._uri, params=data)
|
||||
return ShortCodePage(self._version, response, self._solution)
|
||||
|
||||
async def page_async(
|
||||
self,
|
||||
page_token: Union[str, object] = values.unset,
|
||||
page_number: Union[int, object] = values.unset,
|
||||
page_size: Union[int, object] = values.unset,
|
||||
) -> ShortCodePage:
|
||||
"""
|
||||
Asynchronously retrieve a single page of ShortCodeInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param page_token: PageToken provided by the API
|
||||
:param page_number: Page Number, this value is simply for client state
|
||||
:param page_size: Number of records to return, defaults to 50
|
||||
|
||||
:returns: Page of ShortCodeInstance
|
||||
"""
|
||||
data = values.of(
|
||||
{
|
||||
"PageToken": page_token,
|
||||
"Page": page_number,
|
||||
"PageSize": page_size,
|
||||
}
|
||||
)
|
||||
|
||||
response = await self._version.page_async(
|
||||
method="GET", uri=self._uri, params=data
|
||||
)
|
||||
return ShortCodePage(self._version, response, self._solution)
|
||||
|
||||
def get_page(self, target_url: str) -> ShortCodePage:
|
||||
"""
|
||||
Retrieve a specific page of ShortCodeInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of ShortCodeInstance
|
||||
"""
|
||||
response = self._version.domain.twilio.request("GET", target_url)
|
||||
return ShortCodePage(self._version, response, self._solution)
|
||||
|
||||
async def get_page_async(self, target_url: str) -> ShortCodePage:
|
||||
"""
|
||||
Asynchronously retrieve a specific page of ShortCodeInstance records from the API.
|
||||
Request is executed immediately
|
||||
|
||||
:param target_url: API-generated URL for the requested results page
|
||||
|
||||
:returns: Page of ShortCodeInstance
|
||||
"""
|
||||
response = await self._version.domain.twilio.request_async("GET", target_url)
|
||||
return ShortCodePage(self._version, response, self._solution)
|
||||
|
||||
def get(self, sid: str) -> ShortCodeContext:
|
||||
"""
|
||||
Constructs a ShortCodeContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the ShortCode resource to update.
|
||||
"""
|
||||
return ShortCodeContext(
|
||||
self._version, service_sid=self._solution["service_sid"], sid=sid
|
||||
)
|
||||
|
||||
def __call__(self, sid: str) -> ShortCodeContext:
|
||||
"""
|
||||
Constructs a ShortCodeContext
|
||||
|
||||
:param sid: The Twilio-provided string that uniquely identifies the ShortCode resource to update.
|
||||
"""
|
||||
return ShortCodeContext(
|
||||
self._version, service_sid=self._solution["service_sid"], sid=sid
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Provide a friendly representation
|
||||
|
||||
:returns: Machine friendly representation
|
||||
"""
|
||||
return "<Twilio.Proxy.V1.ShortCodeList>"
|
||||
Reference in New Issue
Block a user