Initial commit: Email alerts application

This commit is contained in:
Iyeoluwa Akinrinola
2025-07-25 11:31:36 +01:00
commit adfb625ae9
6322 changed files with 2882826 additions and 0 deletions
@@ -0,0 +1,50 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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.chat.v2.credential import CredentialList
from twilio.rest.chat.v2.service import ServiceList
class V2(Version):
def __init__(self, domain: Domain):
"""
Initialize the V2 version of Chat
:param domain: The Twilio.chat domain
"""
super().__init__(domain, "v2")
self._credentials: Optional[CredentialList] = None
self._services: Optional[ServiceList] = None
@property
def credentials(self) -> CredentialList:
if self._credentials is None:
self._credentials = CredentialList(self)
return self._credentials
@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.Chat.V2>"
@@ -0,0 +1,676 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 CredentialInstance(InstanceResource):
class PushService(object):
GCM = "gcm"
APN = "apn"
FCM = "fcm"
"""
:ivar sid: The unique string that we created to identify the Credential resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Credential resource.
:ivar friendly_name: The string that you assigned to describe the resource.
:ivar type:
:ivar sandbox: [APN only] Whether to send the credential to sandbox APNs. Can be `true` to send to sandbox APNs or `false` to send to production.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar url: The absolute URL of the Credential resource.
"""
def __init__(
self, version: Version, payload: Dict[str, Any], sid: Optional[str] = None
):
super().__init__(version)
self.sid: Optional[str] = payload.get("sid")
self.account_sid: Optional[str] = payload.get("account_sid")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.type: Optional["CredentialInstance.PushService"] = payload.get("type")
self.sandbox: Optional[str] = payload.get("sandbox")
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 = {
"sid": sid or self.sid,
}
self._context: Optional[CredentialContext] = None
@property
def _proxy(self) -> "CredentialContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: CredentialContext for this CredentialInstance
"""
if self._context is None:
self._context = CredentialContext(
self._version,
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "CredentialInstance":
"""
Fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "CredentialInstance":
"""
Asynchronous coroutine to fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
return await self._proxy.fetch_async()
def update(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> "CredentialInstance":
"""
Update the CredentialInstance
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 64 characters long.
:param certificate: [APN only] The URL encoded representation of the certificate. For example, `-----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEF.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fG... -----END RSA PRIVATE KEY-----`
:param sandbox: [APN only] Whether to send the credential to sandbox APNs. Can be `true` to send to sandbox APNs or `false` to send to production.
:param api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.
:param secret: [FCM only] The **Server key** of your project from the Firebase console, found under Settings / Cloud messaging.
:returns: The updated CredentialInstance
"""
return self._proxy.update(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
)
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> "CredentialInstance":
"""
Asynchronous coroutine to update the CredentialInstance
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 64 characters long.
:param certificate: [APN only] The URL encoded representation of the certificate. For example, `-----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEF.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fG... -----END RSA PRIVATE KEY-----`
:param sandbox: [APN only] Whether to send the credential to sandbox APNs. Can be `true` to send to sandbox APNs or `false` to send to production.
:param api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.
:param secret: [FCM only] The **Server key** of your project from the Firebase console, found under Settings / Cloud messaging.
:returns: The updated CredentialInstance
"""
return await self._proxy.update_async(
friendly_name=friendly_name,
certificate=certificate,
private_key=private_key,
sandbox=sandbox,
api_key=api_key,
secret=secret,
)
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.Chat.V2.CredentialInstance {}>".format(context)
class CredentialContext(InstanceContext):
def __init__(self, version: Version, sid: str):
"""
Initialize the CredentialContext
:param version: Version that contains the resource
:param sid: The SID of the Credential resource to update.
"""
super().__init__(version)
# Path Solution
self._solution = {
"sid": sid,
}
self._uri = "/Credentials/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the CredentialInstance
: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 CredentialInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> CredentialInstance:
"""
Fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return CredentialInstance(
self._version,
payload,
sid=self._solution["sid"],
)
async def fetch_async(self) -> CredentialInstance:
"""
Asynchronous coroutine to fetch the CredentialInstance
:returns: The fetched CredentialInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return CredentialInstance(
self._version,
payload,
sid=self._solution["sid"],
)
def update(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Update the CredentialInstance
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 64 characters long.
:param certificate: [APN only] The URL encoded representation of the certificate. For example, `-----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEF.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fG... -----END RSA PRIVATE KEY-----`
:param sandbox: [APN only] Whether to send the credential to sandbox APNs. Can be `true` to send to sandbox APNs or `false` to send to production.
:param api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.
:param secret: [FCM only] The **Server key** of your project from the Firebase console, found under Settings / Cloud messaging.
:returns: The updated CredentialInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload, sid=self._solution["sid"])
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Asynchronous coroutine to update the CredentialInstance
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 64 characters long.
:param certificate: [APN only] The URL encoded representation of the certificate. For example, `-----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEF.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fG... -----END RSA PRIVATE KEY-----`
:param sandbox: [APN only] Whether to send the credential to sandbox APNs. Can be `true` to send to sandbox APNs or `false` to send to production.
:param api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.
:param secret: [FCM only] The **Server key** of your project from the Firebase console, found under Settings / Cloud messaging.
:returns: The updated CredentialInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload, 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.Chat.V2.CredentialContext {}>".format(context)
class CredentialPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> CredentialInstance:
"""
Build an instance of CredentialInstance
:param payload: Payload response from the API
"""
return CredentialInstance(self._version, payload)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.CredentialPage>"
class CredentialList(ListResource):
def __init__(self, version: Version):
"""
Initialize the CredentialList
:param version: Version that contains the resource
"""
super().__init__(version)
self._uri = "/Credentials"
def create(
self,
type: "CredentialInstance.PushService",
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Create the CredentialInstance
:param type:
:param friendly_name: A descriptive string that you create to describe the new resource. It can be up to 64 characters long.
:param certificate: [APN only] The URL encoded representation of the certificate. For example, `-----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEF.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fG... -----END RSA PRIVATE KEY-----`
:param sandbox: [APN only] Whether to send the credential to sandbox APNs. Can be `true` to send to sandbox APNs or `false` to send to production.
:param api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.
:param secret: [FCM only] The **Server key** of your project from the Firebase console, found under Settings / Cloud messaging.
:returns: The created CredentialInstance
"""
data = values.of(
{
"Type": type,
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload)
async def create_async(
self,
type: "CredentialInstance.PushService",
friendly_name: Union[str, object] = values.unset,
certificate: Union[str, object] = values.unset,
private_key: Union[str, object] = values.unset,
sandbox: Union[bool, object] = values.unset,
api_key: Union[str, object] = values.unset,
secret: Union[str, object] = values.unset,
) -> CredentialInstance:
"""
Asynchronously create the CredentialInstance
:param type:
:param friendly_name: A descriptive string that you create to describe the new resource. It can be up to 64 characters long.
:param certificate: [APN only] The URL encoded representation of the certificate. For example, `-----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEF.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fG... -----END RSA PRIVATE KEY-----`
:param sandbox: [APN only] Whether to send the credential to sandbox APNs. Can be `true` to send to sandbox APNs or `false` to send to production.
:param api_key: [GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.
:param secret: [FCM only] The **Server key** of your project from the Firebase console, found under Settings / Cloud messaging.
:returns: The created CredentialInstance
"""
data = values.of(
{
"Type": type,
"FriendlyName": friendly_name,
"Certificate": certificate,
"PrivateKey": private_key,
"Sandbox": sandbox,
"ApiKey": api_key,
"Secret": secret,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return CredentialInstance(self._version, payload)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[CredentialInstance]:
"""
Streams CredentialInstance 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[CredentialInstance]:
"""
Asynchronously streams CredentialInstance 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[CredentialInstance]:
"""
Lists CredentialInstance 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[CredentialInstance]:
"""
Asynchronously lists CredentialInstance 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,
) -> CredentialPage:
"""
Retrieve a single page of CredentialInstance 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 CredentialInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return CredentialPage(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,
) -> CredentialPage:
"""
Asynchronously retrieve a single page of CredentialInstance 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 CredentialInstance
"""
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 CredentialPage(self._version, response)
def get_page(self, target_url: str) -> CredentialPage:
"""
Retrieve a specific page of CredentialInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of CredentialInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return CredentialPage(self._version, response)
async def get_page_async(self, target_url: str) -> CredentialPage:
"""
Asynchronously retrieve a specific page of CredentialInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of CredentialInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return CredentialPage(self._version, response)
def get(self, sid: str) -> CredentialContext:
"""
Constructs a CredentialContext
:param sid: The SID of the Credential resource to update.
"""
return CredentialContext(self._version, sid=sid)
def __call__(self, sid: str) -> CredentialContext:
"""
Constructs a CredentialContext
:param sid: The SID of the Credential resource to update.
"""
return CredentialContext(self._version, sid=sid)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.CredentialList>"
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,517 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 BindingInstance(InstanceResource):
class BindingType(object):
GCM = "gcm"
APN = "apn"
FCM = "fcm"
"""
:ivar sid: The unique string that we created to identify the Binding resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Binding resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the Binding resource is associated with.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar endpoint: The unique endpoint identifier for the Binding. The format of this value depends on the `binding_type`.
:ivar identity: The application-defined string that uniquely identifies the resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:ivar credential_sid: The SID of the [Credential](https://www.twilio.com/docs/chat/rest/credential-resource) for the binding. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:ivar binding_type:
:ivar message_types: The [Programmable Chat message types](https://www.twilio.com/docs/chat/push-notification-configuration#push-types) the binding is subscribed to.
:ivar url: The absolute URL of the Binding resource.
:ivar links: The absolute URLs of the Binding's [User](https://www.twilio.com/docs/chat/rest/user-resource).
"""
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.endpoint: Optional[str] = payload.get("endpoint")
self.identity: Optional[str] = payload.get("identity")
self.credential_sid: Optional[str] = payload.get("credential_sid")
self.binding_type: Optional["BindingInstance.BindingType"] = payload.get(
"binding_type"
)
self.message_types: Optional[List[str]] = payload.get("message_types")
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[BindingContext] = None
@property
def _proxy(self) -> "BindingContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: BindingContext for this BindingInstance
"""
if self._context is None:
self._context = BindingContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the BindingInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the BindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "BindingInstance":
"""
Fetch the BindingInstance
:returns: The fetched BindingInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "BindingInstance":
"""
Asynchronous coroutine to fetch the BindingInstance
:returns: The fetched BindingInstance
"""
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.Chat.V2.BindingInstance {}>".format(context)
class BindingContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the BindingContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to fetch the Binding resource from.
:param sid: The SID of the Binding resource to fetch.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Bindings/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the BindingInstance
: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 BindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> BindingInstance:
"""
Fetch the BindingInstance
:returns: The fetched BindingInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return BindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> BindingInstance:
"""
Asynchronous coroutine to fetch the BindingInstance
:returns: The fetched BindingInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return BindingInstance(
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.Chat.V2.BindingContext {}>".format(context)
class BindingPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> BindingInstance:
"""
Build an instance of BindingInstance
:param payload: Payload response from the API
"""
return BindingInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.BindingPage>"
class BindingList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the BindingList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the Binding resources from.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Bindings".format(**self._solution)
def stream(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[BindingInstance]:
"""
Streams BindingInstance 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 List[&quot;BindingInstance.BindingType&quot;] binding_type: The push technology used by the Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
binding_type=binding_type, identity=identity, page_size=limits["page_size"]
)
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[BindingInstance]:
"""
Asynchronously streams BindingInstance 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 List[&quot;BindingInstance.BindingType&quot;] binding_type: The push technology used by the Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
binding_type=binding_type, identity=identity, page_size=limits["page_size"]
)
return self._version.stream_async(page, limits["limit"])
def list(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[BindingInstance]:
"""
Lists BindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;BindingInstance.BindingType&quot;] binding_type: The push technology used by the Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
binding_type=binding_type,
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[BindingInstance]:
"""
Asynchronously lists BindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;BindingInstance.BindingType&quot;] binding_type: The push technology used by the Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
binding_type=binding_type,
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> BindingPage:
"""
Retrieve a single page of BindingInstance records from the API.
Request is executed immediately
:param binding_type: The push technology used by the Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:param identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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 BindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return BindingPage(self._version, response, self._solution)
async def page_async(
self,
binding_type: Union[List["BindingInstance.BindingType"], object] = values.unset,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> BindingPage:
"""
Asynchronously retrieve a single page of BindingInstance records from the API.
Request is executed immediately
:param binding_type: The push technology used by the Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:param identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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 BindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return BindingPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> BindingPage:
"""
Retrieve a specific page of BindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of BindingInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return BindingPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> BindingPage:
"""
Asynchronously retrieve a specific page of BindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of BindingInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return BindingPage(self._version, response, self._solution)
def get(self, sid: str) -> BindingContext:
"""
Constructs a BindingContext
:param sid: The SID of the Binding resource to fetch.
"""
return BindingContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> BindingContext:
"""
Constructs a BindingContext
:param sid: The SID of the Binding resource to fetch.
"""
return BindingContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.BindingList>"
@@ -0,0 +1,907 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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.chat.v2.service.channel.invite import InviteList
from twilio.rest.chat.v2.service.channel.member import MemberList
from twilio.rest.chat.v2.service.channel.message import MessageList
from twilio.rest.chat.v2.service.channel.webhook import WebhookList
class ChannelInstance(InstanceResource):
class ChannelType(object):
PUBLIC = "public"
PRIVATE = "private"
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid: The unique string that we created to identify the Channel resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Channel resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the Channel resource is associated with.
:ivar friendly_name: The string that you assigned to describe the resource.
:ivar unique_name: An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL.
:ivar attributes: The JSON string that stores application-specific data. If attributes have not been set, `{}` is returned.
:ivar type:
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar created_by: The `identity` of the User that created the channel. If the Channel was created by using the API, the value is `system`.
:ivar members_count: The number of Members in the Channel.
:ivar messages_count: The number of Messages that have been passed in the Channel.
:ivar url: The absolute URL of the Channel resource.
:ivar links: The absolute URLs of the [Members](https://www.twilio.com/docs/chat/rest/member-resource), [Messages](https://www.twilio.com/docs/chat/rest/message-resource), [Invites](https://www.twilio.com/docs/chat/rest/invite-resource), Webhooks and, if it exists, the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) for the Channel.
"""
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.friendly_name: Optional[str] = payload.get("friendly_name")
self.unique_name: Optional[str] = payload.get("unique_name")
self.attributes: Optional[str] = payload.get("attributes")
self.type: Optional["ChannelInstance.ChannelType"] = payload.get("type")
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.created_by: Optional[str] = payload.get("created_by")
self.members_count: Optional[int] = deserialize.integer(
payload.get("members_count")
)
self.messages_count: Optional[int] = deserialize.integer(
payload.get("messages_count")
)
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[ChannelContext] = None
@property
def _proxy(self) -> "ChannelContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: ChannelContext for this ChannelInstance
"""
if self._context is None:
self._context = ChannelContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
def fetch(self) -> "ChannelInstance":
"""
Fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "ChannelInstance":
"""
Asynchronous coroutine to fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 256 characters long.
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. This value must be 256 characters or less in length and unique within the Service.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param created_by: The `identity` of the User that created the channel. Default is: `system`.
:returns: The updated ChannelInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
created_by=created_by,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Asynchronous coroutine to update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 256 characters long.
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. This value must be 256 characters or less in length and unique within the Service.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param created_by: The `identity` of the User that created the channel. Default is: `system`.
:returns: The updated ChannelInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
created_by=created_by,
)
@property
def invites(self) -> InviteList:
"""
Access the invites
"""
return self._proxy.invites
@property
def members(self) -> MemberList:
"""
Access the members
"""
return self._proxy.members
@property
def messages(self) -> MessageList:
"""
Access the messages
"""
return self._proxy.messages
@property
def webhooks(self) -> WebhookList:
"""
Access the webhooks
"""
return self._proxy.webhooks
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.Chat.V2.ChannelInstance {}>".format(context)
class ChannelContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the ChannelContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to update the Channel resource in.
:param sid: The SID of the Channel resource to update. This value can be either the `sid` or the `unique_name` of the Channel resource to update.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Channels/{sid}".format(**self._solution)
self._invites: Optional[InviteList] = None
self._members: Optional[MemberList] = None
self._messages: Optional[MessageList] = None
self._webhooks: Optional[WebhookList] = None
def delete(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> ChannelInstance:
"""
Fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> ChannelInstance:
"""
Asynchronous coroutine to fetch the ChannelInstance
:returns: The fetched ChannelInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 256 characters long.
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. This value must be 256 characters or less in length and unique within the Service.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param created_by: The `identity` of the User that created the channel. Default is: `system`.
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Asynchronous coroutine to update the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name: A descriptive string that you create to describe the resource. It can be up to 256 characters long.
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL. This value must be 256 characters or less in length and unique within the Service.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param created_by: The `identity` of the User that created the channel. Default is: `system`.
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def invites(self) -> InviteList:
"""
Access the invites
"""
if self._invites is None:
self._invites = InviteList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._invites
@property
def members(self) -> MemberList:
"""
Access the members
"""
if self._members is None:
self._members = MemberList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._members
@property
def messages(self) -> MessageList:
"""
Access the messages
"""
if self._messages is None:
self._messages = MessageList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._messages
@property
def webhooks(self) -> WebhookList:
"""
Access the webhooks
"""
if self._webhooks is None:
self._webhooks = WebhookList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._webhooks
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.Chat.V2.ChannelContext {}>".format(context)
class ChannelPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> ChannelInstance:
"""
Build an instance of ChannelInstance
:param payload: Payload response from the API
"""
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.ChannelPage>"
class ChannelList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the ChannelList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the Channel resources from.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Channels".format(**self._solution)
def create(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
type: Union["ChannelInstance.ChannelType", object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Create the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name: A descriptive string that you create to describe the new resource. It can be up to 64 characters long.
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the Channel resource's `sid` in the URL. This value must be 64 characters or less in length and be unique within the Service.
:param attributes: A valid JSON string that contains application-specific data.
:param type:
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated. The default value is `null`. Note that this parameter should only be used in cases where a Channel is being recreated from a backup/separate source and where a Message was previously updated.
:param created_by: The `identity` of the User that created the channel. Default is: `system`.
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
x_twilio_webhook_enabled: Union[
"ChannelInstance.WebhookEnabledType", object
] = values.unset,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
type: Union["ChannelInstance.ChannelType", object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
created_by: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Asynchronously create the ChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param friendly_name: A descriptive string that you create to describe the new resource. It can be up to 64 characters long.
:param unique_name: An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the Channel resource's `sid` in the URL. This value must be 64 characters or less in length and be unique within the Service.
:param attributes: A valid JSON string that contains application-specific data.
:param type:
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this should only be used in cases where a Channel is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated. The default value is `null`. Note that this parameter should only be used in cases where a Channel is being recreated from a backup/separate source and where a Message was previously updated.
:param created_by: The `identity` of the User that created the channel. Default is: `system`.
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"CreatedBy": created_by,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[ChannelInstance]:
"""
Streams ChannelInstance 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 List[&quot;ChannelInstance.ChannelType&quot;] type: The visibility of the Channels to read. Can be: `public` or `private` and defaults to `public`.
: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(type=type, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[ChannelInstance]:
"""
Asynchronously streams ChannelInstance 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 List[&quot;ChannelInstance.ChannelType&quot;] type: The visibility of the Channels to read. Can be: `public` or `private` and defaults to `public`.
: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(type=type, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ChannelInstance]:
"""
Lists ChannelInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;ChannelInstance.ChannelType&quot;] type: The visibility of the Channels to read. Can be: `public` or `private` and defaults to `public`.
: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(
type=type,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[ChannelInstance]:
"""
Asynchronously lists ChannelInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;ChannelInstance.ChannelType&quot;] type: The visibility of the Channels to read. Can be: `public` or `private` and defaults to `public`.
: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(
type=type,
limit=limit,
page_size=page_size,
)
]
def page(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> ChannelPage:
"""
Retrieve a single page of ChannelInstance records from the API.
Request is executed immediately
:param type: The visibility of the Channels to read. Can be: `public` or `private` and defaults to `public`.
: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 ChannelInstance
"""
data = values.of(
{
"Type": serialize.map(type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return ChannelPage(self._version, response, self._solution)
async def page_async(
self,
type: Union[List["ChannelInstance.ChannelType"], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> ChannelPage:
"""
Asynchronously retrieve a single page of ChannelInstance records from the API.
Request is executed immediately
:param type: The visibility of the Channels to read. Can be: `public` or `private` and defaults to `public`.
: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 ChannelInstance
"""
data = values.of(
{
"Type": serialize.map(type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return ChannelPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> ChannelPage:
"""
Retrieve a specific page of ChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ChannelInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return ChannelPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> ChannelPage:
"""
Asynchronously retrieve a specific page of ChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of ChannelInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return ChannelPage(self._version, response, self._solution)
def get(self, sid: str) -> ChannelContext:
"""
Constructs a ChannelContext
:param sid: The SID of the Channel resource to update. This value can be either the `sid` or the `unique_name` of the Channel resource to update.
"""
return ChannelContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> ChannelContext:
"""
Constructs a ChannelContext
:param sid: The SID of the Channel resource to update. This value can be either the `sid` or the `unique_name` of the Channel resource to update.
"""
return ChannelContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.ChannelList>"
@@ -0,0 +1,573 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 InviteInstance(InstanceResource):
"""
:ivar sid: The unique string that we created to identify the Invite resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Invite resource.
:ivar channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Invite resource belongs to.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the Invite resource is associated with.
:ivar identity: The application-defined string that uniquely identifies the resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) assigned to the resource.
:ivar created_by: The `identity` of the User that created the invite.
:ivar url: The absolute URL of the Invite resource.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_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.channel_sid: Optional[str] = payload.get("channel_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.identity: Optional[str] = payload.get("identity")
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.role_sid: Optional[str] = payload.get("role_sid")
self.created_by: Optional[str] = payload.get("created_by")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[InviteContext] = None
@property
def _proxy(self) -> "InviteContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: InviteContext for this InviteInstance
"""
if self._context is None:
self._context = InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "InviteInstance":
"""
Fetch the InviteInstance
:returns: The fetched InviteInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "InviteInstance":
"""
Asynchronous coroutine to fetch the InviteInstance
:returns: The fetched InviteInstance
"""
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.Chat.V2.InviteInstance {}>".format(context)
class InviteContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the InviteContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to fetch the Invite resource from.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Invite resource to fetch belongs to. This value can be the Channel resource's `sid` or `unique_name`.
:param sid: The SID of the Invite resource to fetch.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Invites/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the InviteInstance
: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 InviteInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> InviteInstance:
"""
Fetch the InviteInstance
:returns: The fetched InviteInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> InviteInstance:
"""
Asynchronous coroutine to fetch the InviteInstance
:returns: The fetched InviteInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_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.Chat.V2.InviteContext {}>".format(context)
class InvitePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> InviteInstance:
"""
Build an instance of InviteInstance
:param payload: Payload response from the API
"""
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.InvitePage>"
class InviteList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the InviteList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the Invite resources from.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Invite resources to read belong to. This value can be the Channel resource's `sid` or `unique_name`.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Invites".format(
**self._solution
)
def create(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> InviteInstance:
"""
Create the InviteInstance
:param identity: The `identity` value that uniquely identifies the new resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) assigned to the new member.
:returns: The created InviteInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self, identity: str, role_sid: Union[str, object] = values.unset
) -> InviteInstance:
"""
Asynchronously create the InviteInstance
:param identity: The `identity` value that uniquely identifies the new resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) assigned to the new member.
:returns: The created InviteInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return InviteInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[InviteInstance]:
"""
Streams InviteInstance 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 List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[InviteInstance]:
"""
Asynchronously streams InviteInstance 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 List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[InviteInstance]:
"""
Lists InviteInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[InviteInstance]:
"""
Asynchronously lists InviteInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> InvitePage:
"""
Retrieve a single page of InviteInstance records from the API.
Request is executed immediately
:param identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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 InviteInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return InvitePage(self._version, response, self._solution)
async def page_async(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> InvitePage:
"""
Asynchronously retrieve a single page of InviteInstance records from the API.
Request is executed immediately
:param identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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 InviteInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return InvitePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> InvitePage:
"""
Retrieve a specific page of InviteInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of InviteInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return InvitePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> InvitePage:
"""
Asynchronously retrieve a specific page of InviteInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of InviteInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return InvitePage(self._version, response, self._solution)
def get(self, sid: str) -> InviteContext:
"""
Constructs a InviteContext
:param sid: The SID of the Invite resource to fetch.
"""
return InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> InviteContext:
"""
Constructs a InviteContext
:param sid: The SID of the Invite resource to fetch.
"""
return InviteContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.InviteList>"
@@ -0,0 +1,850 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 MemberInstance(InstanceResource):
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid: The unique string that we created to identify the Member resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Member resource.
:ivar channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Member resource belongs to.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the Member resource is associated with.
:ivar identity: The application-defined string that uniquely identifies the resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) assigned to the member.
:ivar last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read.
:ivar last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:ivar url: The absolute URL of the Member resource.
:ivar attributes: The JSON string that stores application-specific data. If attributes have not been set, `{}` is returned.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_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.channel_sid: Optional[str] = payload.get("channel_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.identity: Optional[str] = payload.get("identity")
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.role_sid: Optional[str] = payload.get("role_sid")
self.last_consumed_message_index: Optional[int] = deserialize.integer(
payload.get("last_consumed_message_index")
)
self.last_consumption_timestamp: Optional[
datetime
] = deserialize.iso8601_datetime(payload.get("last_consumption_timestamp"))
self.url: Optional[str] = payload.get("url")
self.attributes: Optional[str] = payload.get("attributes")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[MemberContext] = None
@property
def _proxy(self) -> "MemberContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: MemberContext for this MemberInstance
"""
if self._context is None:
self._context = MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
def fetch(self) -> "MemberInstance":
"""
Fetch the MemberInstance
:returns: The fetched MemberInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "MemberInstance":
"""
Asynchronous coroutine to fetch the MemberInstance
:returns: The fetched MemberInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MemberInstance":
"""
Update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/rest/service-resource).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) that the Member has read within the [Channel](https://www.twilio.com/docs/chat/channels).
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this parameter should only be used when a Member is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The updated MemberInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
date_created=date_created,
date_updated=date_updated,
attributes=attributes,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MemberInstance":
"""
Asynchronous coroutine to update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/rest/service-resource).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) that the Member has read within the [Channel](https://www.twilio.com/docs/chat/channels).
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this parameter should only be used when a Member is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The updated MemberInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
date_created=date_created,
date_updated=date_updated,
attributes=attributes,
)
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.Chat.V2.MemberInstance {}>".format(context)
class MemberContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the MemberContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to update the Member resource in.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Member resource to update belongs to. This value can be the Channel resource's `sid` or `unique_name`.
:param sid: The SID of the Member resource to update. This value can be either the Member's `sid` or its `identity` value.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Members/{sid}".format(
**self._solution
)
)
def delete(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> MemberInstance:
"""
Fetch the MemberInstance
:returns: The fetched MemberInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> MemberInstance:
"""
Asynchronous coroutine to fetch the MemberInstance
:returns: The fetched MemberInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/rest/service-resource).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) that the Member has read within the [Channel](https://www.twilio.com/docs/chat/channels).
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this parameter should only be used when a Member is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Asynchronous coroutine to update the MemberInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/rest/service-resource).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) that the Member has read within the [Channel](https://www.twilio.com/docs/chat/channels).
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this parameter should only be used when a Member is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_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.Chat.V2.MemberContext {}>".format(context)
class MemberPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> MemberInstance:
"""
Build an instance of MemberInstance
:param payload: Payload response from the API
"""
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.MemberPage>"
class MemberList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the MemberList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the Member resources from.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Member resources to read belong to. This value can be the Channel resource's `sid` or `unique_name`.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Members".format(
**self._solution
)
def create(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Create the MemberInstance
:param identity: The `identity` value that uniquely identifies the new resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/rest/service-resource).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read. This parameter should only be used when recreating a Member from a backup/separate source.
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this parameter should only be used when a Member is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated. The default value is `null`. Note that this parameter should only be used when a Member is being recreated from a backup/separate source and where a Member was previously updated.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"MemberInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MemberInstance:
"""
Asynchronously create the MemberInstance
:param identity: The `identity` value that uniquely identifies the new resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/rest/service-resource).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read. This parameter should only be used when recreating a Member from a backup/separate source.
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. Note that this parameter should only be used when a Member is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated. The default value is `null`. Note that this parameter should only be used when a Member is being recreated from a backup/separate source and where a Member was previously updated.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"Attributes": attributes,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MemberInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[MemberInstance]:
"""
Streams MemberInstance 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 List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the Member resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[MemberInstance]:
"""
Asynchronously streams MemberInstance 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 List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the Member resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(identity=identity, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MemberInstance]:
"""
Lists MemberInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the Member resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
identity: Union[List[str], object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MemberInstance]:
"""
Asynchronously lists MemberInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[str] identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the Member resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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(
identity=identity,
limit=limit,
page_size=page_size,
)
]
def page(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MemberPage:
"""
Retrieve a single page of MemberInstance records from the API.
Request is executed immediately
:param identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the Member resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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 MemberInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return MemberPage(self._version, response, self._solution)
async def page_async(
self,
identity: Union[List[str], object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MemberPage:
"""
Asynchronously retrieve a single page of MemberInstance records from the API.
Request is executed immediately
:param identity: The [User](https://www.twilio.com/docs/chat/rest/user-resource)'s `identity` value of the Member resources to read. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more details.
: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 MemberInstance
"""
data = values.of(
{
"Identity": serialize.map(identity, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return MemberPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> MemberPage:
"""
Retrieve a specific page of MemberInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MemberInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return MemberPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> MemberPage:
"""
Asynchronously retrieve a specific page of MemberInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MemberInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return MemberPage(self._version, response, self._solution)
def get(self, sid: str) -> MemberContext:
"""
Constructs a MemberContext
:param sid: The SID of the Member resource to update. This value can be either the Member's `sid` or its `identity` value.
"""
return MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> MemberContext:
"""
Constructs a MemberContext
:param sid: The SID of the Member resource to update. This value can be either the Member's `sid` or its `identity` value.
"""
return MemberContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.MemberList>"
@@ -0,0 +1,850 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 MessageInstance(InstanceResource):
class OrderType(object):
ASC = "asc"
DESC = "desc"
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid: The unique string that we created to identify the Message resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Message resource.
:ivar attributes: The JSON string that stores application-specific data. If attributes have not been set, `{}` is returned.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the Message resource is associated with.
:ivar to: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) that the message was sent to.
:ivar channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Message resource belongs to.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar last_updated_by: The [Identity](https://www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.
:ivar was_edited: Whether the message has been edited since it was created.
:ivar _from: The [Identity](https://www.twilio.com/docs/chat/identity) of the message's author. The default value is `system`.
:ivar body: The content of the message.
:ivar index: The index of the message within the [Channel](https://www.twilio.com/docs/chat/channels). Indices may skip numbers, but will always be in order of when the message was received.
:ivar type: The Message type. Can be: `text` or `media`.
:ivar media: An object that describes the Message's media, if the message contains media. The object contains these fields: `content_type` with the MIME type of the media, `filename` with the name of the media, `sid` with the SID of the Media resource, and `size` with the media object's file size in bytes. If the Message has no media, this value is `null`.
:ivar url: The absolute URL of the Message resource.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_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.attributes: Optional[str] = payload.get("attributes")
self.service_sid: Optional[str] = payload.get("service_sid")
self.to: Optional[str] = payload.get("to")
self.channel_sid: Optional[str] = payload.get("channel_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.last_updated_by: Optional[str] = payload.get("last_updated_by")
self.was_edited: Optional[bool] = payload.get("was_edited")
self._from: Optional[str] = payload.get("from")
self.body: Optional[str] = payload.get("body")
self.index: Optional[int] = deserialize.integer(payload.get("index"))
self.type: Optional[str] = payload.get("type")
self.media: Optional[Dict[str, object]] = payload.get("media")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[MessageContext] = None
@property
def _proxy(self) -> "MessageContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: MessageContext for this MessageInstance
"""
if self._context is None:
self._context = MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
def fetch(self) -> "MessageInstance":
"""
Fetch the MessageInstance
:returns: The fetched MessageInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "MessageInstance":
"""
Asynchronous coroutine to fetch the MessageInstance
:returns: The fetched MessageInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body: The message to send to the channel. Can be an empty string or `null`, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param last_updated_by: The [Identity](https://www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.
:param from_: The [Identity](https://www.twilio.com/docs/chat/identity) of the message's author.
:returns: The updated MessageInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
body=body,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
last_updated_by=last_updated_by,
from_=from_,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Asynchronous coroutine to update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body: The message to send to the channel. Can be an empty string or `null`, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param last_updated_by: The [Identity](https://www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.
:param from_: The [Identity](https://www.twilio.com/docs/chat/identity) of the message's author.
:returns: The updated MessageInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
body=body,
attributes=attributes,
date_created=date_created,
date_updated=date_updated,
last_updated_by=last_updated_by,
from_=from_,
)
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.Chat.V2.MessageInstance {}>".format(context)
class MessageContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the MessageContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to update the Message resource in.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Message resource to update belongs to. This value can be the Channel resource's `sid` or `unique_name`.
:param sid: The SID of the Message resource to update.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Messages/{sid}".format(
**self._solution
)
)
def delete(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> MessageInstance:
"""
Fetch the MessageInstance
:returns: The fetched MessageInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> MessageInstance:
"""
Asynchronous coroutine to fetch the MessageInstance
:returns: The fetched MessageInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body: The message to send to the channel. Can be an empty string or `null`, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param last_updated_by: The [Identity](https://www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.
:param from_: The [Identity](https://www.twilio.com/docs/chat/identity) of the message's author.
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"From": from_,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
from_: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronous coroutine to update the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param body: The message to send to the channel. Can be an empty string or `null`, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param last_updated_by: The [Identity](https://www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.
:param from_: The [Identity](https://www.twilio.com/docs/chat/identity) of the message's author.
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"From": from_,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_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.Chat.V2.MessageContext {}>".format(context)
class MessagePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> MessageInstance:
"""
Build an instance of MessageInstance
:param payload: Payload response from the API
"""
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.MessagePage>"
class MessageList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the MessageList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the Message resources from.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Message resource to read belongs to. This value can be the Channel resource's `sid` or `unique_name`.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Messages".format(
**self._solution
)
def create(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
body: Union[str, object] = values.unset,
media_sid: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Create the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param from_: The [Identity](https://www.twilio.com/docs/chat/identity) of the new message's author. The default value is `system`.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param last_updated_by: The [Identity](https://www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.
:param body: The message to send to the channel. Can be an empty string or `null`, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
:param media_sid: The SID of the [Media](https://www.twilio.com/docs/chat/rest/media) to attach to the new Message.
:returns: The created MessageInstance
"""
data = values.of(
{
"From": from_,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"Body": body,
"MediaSid": media_sid,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
x_twilio_webhook_enabled: Union[
"MessageInstance.WebhookEnabledType", object
] = values.unset,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
date_created: Union[datetime, object] = values.unset,
date_updated: Union[datetime, object] = values.unset,
last_updated_by: Union[str, object] = values.unset,
body: Union[str, object] = values.unset,
media_sid: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronously create the MessageInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param from_: The [Identity](https://www.twilio.com/docs/chat/identity) of the new message's author. The default value is `system`.
:param attributes: A valid JSON string that contains application-specific data.
:param date_created: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was created. The default value is the current time set by the Chat service. This parameter should only be used when a Chat's history is being recreated from a backup/separate source.
:param date_updated: The date, specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, to assign to the resource as the date it was last updated.
:param last_updated_by: The [Identity](https://www.twilio.com/docs/chat/identity) of the User who last updated the Message, if applicable.
:param body: The message to send to the channel. Can be an empty string or `null`, which sets the value as an empty string. You can send structured data in the body by serializing it as a string.
:param media_sid: The SID of the [Media](https://www.twilio.com/docs/chat/rest/media) to attach to the new Message.
:returns: The created MessageInstance
"""
data = values.of(
{
"From": from_,
"Attributes": attributes,
"DateCreated": serialize.iso8601_datetime(date_created),
"DateUpdated": serialize.iso8601_datetime(date_updated),
"LastUpdatedBy": last_updated_by,
"Body": body,
"MediaSid": media_sid,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[MessageInstance]:
"""
Streams MessageInstance 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 &quot;MessageInstance.OrderType&quot; order: The sort order of the returned messages. Can be: `asc` (ascending) or `desc` (descending) with `asc` as the default.
: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(order=order, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[MessageInstance]:
"""
Asynchronously streams MessageInstance 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 &quot;MessageInstance.OrderType&quot; order: The sort order of the returned messages. Can be: `asc` (ascending) or `desc` (descending) with `asc` as the default.
: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(order=order, page_size=limits["page_size"])
return self._version.stream_async(page, limits["limit"])
def list(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MessageInstance]:
"""
Lists MessageInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;MessageInstance.OrderType&quot; order: The sort order of the returned messages. Can be: `asc` (ascending) or `desc` (descending) with `asc` as the default.
: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(
order=order,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[MessageInstance]:
"""
Asynchronously lists MessageInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param &quot;MessageInstance.OrderType&quot; order: The sort order of the returned messages. Can be: `asc` (ascending) or `desc` (descending) with `asc` as the default.
: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(
order=order,
limit=limit,
page_size=page_size,
)
]
def page(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MessagePage:
"""
Retrieve a single page of MessageInstance records from the API.
Request is executed immediately
:param order: The sort order of the returned messages. Can be: `asc` (ascending) or `desc` (descending) with `asc` as the default.
: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 MessageInstance
"""
data = values.of(
{
"Order": order,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return MessagePage(self._version, response, self._solution)
async def page_async(
self,
order: Union["MessageInstance.OrderType", object] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> MessagePage:
"""
Asynchronously retrieve a single page of MessageInstance records from the API.
Request is executed immediately
:param order: The sort order of the returned messages. Can be: `asc` (ascending) or `desc` (descending) with `asc` as the default.
: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 MessageInstance
"""
data = values.of(
{
"Order": order,
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return MessagePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> MessagePage:
"""
Retrieve a specific page of MessageInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MessageInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return MessagePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> MessagePage:
"""
Asynchronously retrieve a specific page of MessageInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of MessageInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return MessagePage(self._version, response, self._solution)
def get(self, sid: str) -> MessageContext:
"""
Constructs a MessageContext
:param sid: The SID of the Message resource to update.
"""
return MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> MessageContext:
"""
Constructs a MessageContext
:param sid: The SID of the Message resource to update.
"""
return MessageContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.MessageList>"
@@ -0,0 +1,765 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 WebhookInstance(InstanceResource):
class Method(object):
GET = "GET"
POST = "POST"
class Type(object):
WEBHOOK = "webhook"
TRIGGER = "trigger"
STUDIO = "studio"
"""
:ivar sid: The unique string that we created to identify the Channel Webhook resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Channel Webhook resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the Channel Webhook resource is associated with.
:ivar channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Channel Webhook resource belongs to.
:ivar type: The type of webhook. Can be: `webhook`, `studio`, or `trigger`.
:ivar url: The absolute URL of the Channel Webhook resource.
:ivar configuration: The JSON string that describes how the channel webhook is configured. The configuration object contains the `url`, `method`, `filters`, and `retry_count` values that are configured by the create and update actions.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
channel_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.channel_sid: Optional[str] = payload.get("channel_sid")
self.type: Optional[str] = payload.get("type")
self.url: Optional[str] = payload.get("url")
self.configuration: Optional[Dict[str, object]] = payload.get("configuration")
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._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid or self.sid,
}
self._context: Optional[WebhookContext] = None
@property
def _proxy(self) -> "WebhookContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: WebhookContext for this WebhookInstance
"""
if self._context is None:
self._context = WebhookContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the WebhookInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the WebhookInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "WebhookInstance":
"""
Fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "WebhookInstance":
"""
Asynchronous coroutine to fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
return await self._proxy.fetch_async()
def update(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> "WebhookInstance":
"""
Update the WebhookInstance
:param configuration_url: The URL of the webhook to call using the `configuration.method`.
:param configuration_method:
:param configuration_filters: The events that cause us to call the Channel Webhook. Used when `type` is `webhook`. This parameter takes only one event. To specify more than one event, repeat this parameter for each event. For the list of possible events, see [Webhook Event Triggers](https://www.twilio.com/docs/chat/webhook-events#webhook-event-trigger).
:param configuration_triggers: A string that will cause us to call the webhook when it is present in a message body. This parameter takes only one trigger string. To specify more than one, repeat this parameter for each trigger string up to a total of 5 trigger strings. Used only when `type` = `trigger`.
:param configuration_flow_sid: The SID of the Studio [Flow](https://www.twilio.com/docs/studio/rest-api/flow) to call when an event in `configuration.filters` occurs. Used only when `type` = `studio`.
:param configuration_retry_count: The number of times to retry the webhook if the first attempt fails. Can be an integer between 0 and 3, inclusive, and the default is 0.
:returns: The updated WebhookInstance
"""
return self._proxy.update(
configuration_url=configuration_url,
configuration_method=configuration_method,
configuration_filters=configuration_filters,
configuration_triggers=configuration_triggers,
configuration_flow_sid=configuration_flow_sid,
configuration_retry_count=configuration_retry_count,
)
async def update_async(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> "WebhookInstance":
"""
Asynchronous coroutine to update the WebhookInstance
:param configuration_url: The URL of the webhook to call using the `configuration.method`.
:param configuration_method:
:param configuration_filters: The events that cause us to call the Channel Webhook. Used when `type` is `webhook`. This parameter takes only one event. To specify more than one event, repeat this parameter for each event. For the list of possible events, see [Webhook Event Triggers](https://www.twilio.com/docs/chat/webhook-events#webhook-event-trigger).
:param configuration_triggers: A string that will cause us to call the webhook when it is present in a message body. This parameter takes only one trigger string. To specify more than one, repeat this parameter for each trigger string up to a total of 5 trigger strings. Used only when `type` = `trigger`.
:param configuration_flow_sid: The SID of the Studio [Flow](https://www.twilio.com/docs/studio/rest-api/flow) to call when an event in `configuration.filters` occurs. Used only when `type` = `studio`.
:param configuration_retry_count: The number of times to retry the webhook if the first attempt fails. Can be an integer between 0 and 3, inclusive, and the default is 0.
:returns: The updated WebhookInstance
"""
return await self._proxy.update_async(
configuration_url=configuration_url,
configuration_method=configuration_method,
configuration_filters=configuration_filters,
configuration_triggers=configuration_triggers,
configuration_flow_sid=configuration_flow_sid,
configuration_retry_count=configuration_retry_count,
)
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.Chat.V2.WebhookInstance {}>".format(context)
class WebhookContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, channel_sid: str, sid: str):
"""
Initialize the WebhookContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) with the Channel that has the Webhook resource to update.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Channel Webhook resource to update belongs to. This value can be the Channel resource's `sid` or `unique_name`.
:param sid: The SID of the Channel Webhook resource to update.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
"sid": sid,
}
self._uri = (
"/Services/{service_sid}/Channels/{channel_sid}/Webhooks/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the WebhookInstance
: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 WebhookInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> WebhookInstance:
"""
Fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> WebhookInstance:
"""
Asynchronous coroutine to fetch the WebhookInstance
:returns: The fetched WebhookInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
def update(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Update the WebhookInstance
:param configuration_url: The URL of the webhook to call using the `configuration.method`.
:param configuration_method:
:param configuration_filters: The events that cause us to call the Channel Webhook. Used when `type` is `webhook`. This parameter takes only one event. To specify more than one event, repeat this parameter for each event. For the list of possible events, see [Webhook Event Triggers](https://www.twilio.com/docs/chat/webhook-events#webhook-event-trigger).
:param configuration_triggers: A string that will cause us to call the webhook when it is present in a message body. This parameter takes only one trigger string. To specify more than one, repeat this parameter for each trigger string up to a total of 5 trigger strings. Used only when `type` = `trigger`.
:param configuration_flow_sid: The SID of the Studio [Flow](https://www.twilio.com/docs/studio/rest-api/flow) to call when an event in `configuration.filters` occurs. Used only when `type` = `studio`.
:param configuration_retry_count: The number of times to retry the webhook if the first attempt fails. Can be an integer between 0 and 3, inclusive, and the default is 0.
:returns: The updated WebhookInstance
"""
data = values.of(
{
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Asynchronous coroutine to update the WebhookInstance
:param configuration_url: The URL of the webhook to call using the `configuration.method`.
:param configuration_method:
:param configuration_filters: The events that cause us to call the Channel Webhook. Used when `type` is `webhook`. This parameter takes only one event. To specify more than one event, repeat this parameter for each event. For the list of possible events, see [Webhook Event Triggers](https://www.twilio.com/docs/chat/webhook-events#webhook-event-trigger).
:param configuration_triggers: A string that will cause us to call the webhook when it is present in a message body. This parameter takes only one trigger string. To specify more than one, repeat this parameter for each trigger string up to a total of 5 trigger strings. Used only when `type` = `trigger`.
:param configuration_flow_sid: The SID of the Studio [Flow](https://www.twilio.com/docs/studio/rest-api/flow) to call when an event in `configuration.filters` occurs. Used only when `type` = `studio`.
:param configuration_retry_count: The number of times to retry the webhook if the first attempt fails. Can be an integer between 0 and 3, inclusive, and the default is 0.
:returns: The updated WebhookInstance
"""
data = values.of(
{
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_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.Chat.V2.WebhookContext {}>".format(context)
class WebhookPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> WebhookInstance:
"""
Build an instance of WebhookInstance
:param payload: Payload response from the API
"""
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.WebhookPage>"
class WebhookList(ListResource):
def __init__(self, version: Version, service_sid: str, channel_sid: str):
"""
Initialize the WebhookList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) with the Channel to read the resources from.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the Channel Webhook resources to read belong to. This value can be the Channel resource's `sid` or `unique_name`.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"channel_sid": channel_sid,
}
self._uri = "/Services/{service_sid}/Channels/{channel_sid}/Webhooks".format(
**self._solution
)
def create(
self,
type: "WebhookInstance.Type",
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Create the WebhookInstance
:param type:
:param configuration_url: The URL of the webhook to call using the `configuration.method`.
:param configuration_method:
:param configuration_filters: The events that cause us to call the Channel Webhook. Used when `type` is `webhook`. This parameter takes only one event. To specify more than one event, repeat this parameter for each event. For the list of possible events, see [Webhook Event Triggers](https://www.twilio.com/docs/chat/webhook-events#webhook-event-trigger).
:param configuration_triggers: A string that will cause us to call the webhook when it is present in a message body. This parameter takes only one trigger string. To specify more than one, repeat this parameter for each trigger string up to a total of 5 trigger strings. Used only when `type` = `trigger`.
:param configuration_flow_sid: The SID of the Studio [Flow](https://www.twilio.com/docs/studio/rest-api/flow) to call when an event in `configuration.filters` occurs. Used only when `type` is `studio`.
:param configuration_retry_count: The number of times to retry the webhook if the first attempt fails. Can be an integer between 0 and 3, inclusive, and the default is 0.
:returns: The created WebhookInstance
"""
data = values.of(
{
"Type": type,
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
type: "WebhookInstance.Type",
configuration_url: Union[str, object] = values.unset,
configuration_method: Union["WebhookInstance.Method", object] = values.unset,
configuration_filters: Union[List[str], object] = values.unset,
configuration_triggers: Union[List[str], object] = values.unset,
configuration_flow_sid: Union[str, object] = values.unset,
configuration_retry_count: Union[int, object] = values.unset,
) -> WebhookInstance:
"""
Asynchronously create the WebhookInstance
:param type:
:param configuration_url: The URL of the webhook to call using the `configuration.method`.
:param configuration_method:
:param configuration_filters: The events that cause us to call the Channel Webhook. Used when `type` is `webhook`. This parameter takes only one event. To specify more than one event, repeat this parameter for each event. For the list of possible events, see [Webhook Event Triggers](https://www.twilio.com/docs/chat/webhook-events#webhook-event-trigger).
:param configuration_triggers: A string that will cause us to call the webhook when it is present in a message body. This parameter takes only one trigger string. To specify more than one, repeat this parameter for each trigger string up to a total of 5 trigger strings. Used only when `type` = `trigger`.
:param configuration_flow_sid: The SID of the Studio [Flow](https://www.twilio.com/docs/studio/rest-api/flow) to call when an event in `configuration.filters` occurs. Used only when `type` is `studio`.
:param configuration_retry_count: The number of times to retry the webhook if the first attempt fails. Can be an integer between 0 and 3, inclusive, and the default is 0.
:returns: The created WebhookInstance
"""
data = values.of(
{
"Type": type,
"Configuration.Url": configuration_url,
"Configuration.Method": configuration_method,
"Configuration.Filters": serialize.map(
configuration_filters, lambda e: e
),
"Configuration.Triggers": serialize.map(
configuration_triggers, lambda e: e
),
"Configuration.FlowSid": configuration_flow_sid,
"Configuration.RetryCount": configuration_retry_count,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return WebhookInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[WebhookInstance]:
"""
Streams WebhookInstance 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[WebhookInstance]:
"""
Asynchronously streams WebhookInstance 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[WebhookInstance]:
"""
Lists WebhookInstance 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[WebhookInstance]:
"""
Asynchronously lists WebhookInstance 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,
) -> WebhookPage:
"""
Retrieve a single page of WebhookInstance 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 WebhookInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return WebhookPage(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,
) -> WebhookPage:
"""
Asynchronously retrieve a single page of WebhookInstance 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 WebhookInstance
"""
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 WebhookPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> WebhookPage:
"""
Retrieve a specific page of WebhookInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of WebhookInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return WebhookPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> WebhookPage:
"""
Asynchronously retrieve a specific page of WebhookInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of WebhookInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return WebhookPage(self._version, response, self._solution)
def get(self, sid: str) -> WebhookContext:
"""
Constructs a WebhookContext
:param sid: The SID of the Channel Webhook resource to update.
"""
return WebhookContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __call__(self, sid: str) -> WebhookContext:
"""
Constructs a WebhookContext
:param sid: The SID of the Channel Webhook resource to update.
"""
return WebhookContext(
self._version,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.WebhookList>"
@@ -0,0 +1,610 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 RoleInstance(InstanceResource):
class RoleType(object):
CHANNEL = "channel"
DEPLOYMENT = "deployment"
"""
:ivar sid: The unique string that we created to identify the Role resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Role resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the Role resource is associated with.
:ivar friendly_name: The string that you assigned to describe the resource.
:ivar type:
:ivar permissions: An array of the permissions the role has been granted.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar url: The absolute URL of the Role resource.
"""
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.friendly_name: Optional[str] = payload.get("friendly_name")
self.type: Optional["RoleInstance.RoleType"] = payload.get("type")
self.permissions: Optional[List[str]] = payload.get("permissions")
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,
"sid": sid or self.sid,
}
self._context: Optional[RoleContext] = None
@property
def _proxy(self) -> "RoleContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: RoleContext for this RoleInstance
"""
if self._context is None:
self._context = RoleContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "RoleInstance":
"""
Fetch the RoleInstance
:returns: The fetched RoleInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "RoleInstance":
"""
Asynchronous coroutine to fetch the RoleInstance
:returns: The fetched RoleInstance
"""
return await self._proxy.fetch_async()
def update(self, permission: List[str]) -> "RoleInstance":
"""
Update the RoleInstance
:param permission: A permission that you grant to the role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. Note that the update action replaces all previously assigned permissions with those defined in the update action. To remove a permission, do not include it in the subsequent update action. The values for this parameter depend on the role's `type`.
:returns: The updated RoleInstance
"""
return self._proxy.update(
permission=permission,
)
async def update_async(self, permission: List[str]) -> "RoleInstance":
"""
Asynchronous coroutine to update the RoleInstance
:param permission: A permission that you grant to the role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. Note that the update action replaces all previously assigned permissions with those defined in the update action. To remove a permission, do not include it in the subsequent update action. The values for this parameter depend on the role's `type`.
:returns: The updated RoleInstance
"""
return await self._proxy.update_async(
permission=permission,
)
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.Chat.V2.RoleInstance {}>".format(context)
class RoleContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the RoleContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to update the Role resource in.
:param sid: The SID of the Role resource to update.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Roles/{sid}".format(**self._solution)
def delete(self) -> bool:
"""
Deletes the RoleInstance
: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 RoleInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> RoleInstance:
"""
Fetch the RoleInstance
:returns: The fetched RoleInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> RoleInstance:
"""
Asynchronous coroutine to fetch the RoleInstance
:returns: The fetched RoleInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(self, permission: List[str]) -> RoleInstance:
"""
Update the RoleInstance
:param permission: A permission that you grant to the role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. Note that the update action replaces all previously assigned permissions with those defined in the update action. To remove a permission, do not include it in the subsequent update action. The values for this parameter depend on the role's `type`.
:returns: The updated RoleInstance
"""
data = values.of(
{
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(self, permission: List[str]) -> RoleInstance:
"""
Asynchronous coroutine to update the RoleInstance
:param permission: A permission that you grant to the role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. Note that the update action replaces all previously assigned permissions with those defined in the update action. To remove a permission, do not include it in the subsequent update action. The values for this parameter depend on the role's `type`.
:returns: The updated RoleInstance
"""
data = values.of(
{
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
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.Chat.V2.RoleContext {}>".format(context)
class RolePage(Page):
def get_instance(self, payload: Dict[str, Any]) -> RoleInstance:
"""
Build an instance of RoleInstance
:param payload: Payload response from the API
"""
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.RolePage>"
class RoleList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the RoleList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the Role resources from.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Roles".format(**self._solution)
def create(
self, friendly_name: str, type: "RoleInstance.RoleType", permission: List[str]
) -> RoleInstance:
"""
Create the RoleInstance
:param friendly_name: A descriptive string that you create to describe the new resource. It can be up to 64 characters long.
:param type:
:param permission: A permission that you grant to the new role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. The values for this parameter depend on the role's `type`.
:returns: The created RoleInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Type": type,
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self, friendly_name: str, type: "RoleInstance.RoleType", permission: List[str]
) -> RoleInstance:
"""
Asynchronously create the RoleInstance
:param friendly_name: A descriptive string that you create to describe the new resource. It can be up to 64 characters long.
:param type:
:param permission: A permission that you grant to the new role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. The values for this parameter depend on the role's `type`.
:returns: The created RoleInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"Type": type,
"Permission": serialize.map(permission, lambda e: e),
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
return RoleInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[RoleInstance]:
"""
Streams RoleInstance 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[RoleInstance]:
"""
Asynchronously streams RoleInstance 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[RoleInstance]:
"""
Lists RoleInstance 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[RoleInstance]:
"""
Asynchronously lists RoleInstance 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,
) -> RolePage:
"""
Retrieve a single page of RoleInstance 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 RoleInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return RolePage(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,
) -> RolePage:
"""
Asynchronously retrieve a single page of RoleInstance 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 RoleInstance
"""
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 RolePage(self._version, response, self._solution)
def get_page(self, target_url: str) -> RolePage:
"""
Retrieve a specific page of RoleInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of RoleInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return RolePage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> RolePage:
"""
Asynchronously retrieve a specific page of RoleInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of RoleInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return RolePage(self._version, response, self._solution)
def get(self, sid: str) -> RoleContext:
"""
Constructs a RoleContext
:param sid: The SID of the Role resource to update.
"""
return RoleContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> RoleContext:
"""
Constructs a RoleContext
:param sid: The SID of the Role resource to update.
"""
return RoleContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.RoleList>"
@@ -0,0 +1,751 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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.chat.v2.service.user.user_binding import UserBindingList
from twilio.rest.chat.v2.service.user.user_channel import UserChannelList
class UserInstance(InstanceResource):
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar sid: The unique string that we created to identify the User resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the User resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the User resource is associated with.
:ivar attributes: The JSON string that stores application-specific data. If attributes have not been set, `{}` is returned.
:ivar friendly_name: The string that you assigned to describe the resource.
:ivar role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) assigned to the user.
:ivar identity: The application-defined string that uniquely identifies the resource's User within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). This value is often a username or an email address, and is case-sensitive. See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:ivar is_online: Whether the User is actively connected to the Service instance and online. This value is only returned by Fetch actions that return a single resource and `null` is always returned by a Read action. This value is `null` if the Service's `reachability_enabled` is `false`, if the User has never been online for the Service instance, even if the Service's `reachability_enabled` is `true`.
:ivar is_notifiable: Whether the User has a potentially valid Push Notification registration (APN or GCM) for the Service instance. If at least one registration exists, `true`; otherwise `false`. This value is only returned by Fetch actions that return a single resource and `null` is always returned by a Read action. This value is `null` if the Service's `reachability_enabled` is `false`, and if the User has never had a notification registration, even if the Service's `reachability_enabled` is `true`.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar joined_channels_count: The number of Channels the User is a Member of.
:ivar links: The absolute URLs of the [Channel](https://www.twilio.com/docs/chat/channels) and [Binding](https://www.twilio.com/docs/chat/rest/binding-resource) resources related to the user.
:ivar url: The absolute URL of the User resource.
"""
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.attributes: Optional[str] = payload.get("attributes")
self.friendly_name: Optional[str] = payload.get("friendly_name")
self.role_sid: Optional[str] = payload.get("role_sid")
self.identity: Optional[str] = payload.get("identity")
self.is_online: Optional[bool] = payload.get("is_online")
self.is_notifiable: Optional[bool] = payload.get("is_notifiable")
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.joined_channels_count: Optional[int] = deserialize.integer(
payload.get("joined_channels_count")
)
self.links: Optional[Dict[str, object]] = payload.get("links")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"sid": sid or self.sid,
}
self._context: Optional[UserContext] = None
@property
def _proxy(self) -> "UserContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UserContext for this UserInstance
"""
if self._context is None:
self._context = UserContext(
self._version,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the UserInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the UserInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "UserInstance":
"""
Fetch the UserInstance
:returns: The fetched UserInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "UserInstance":
"""
Asynchronous coroutine to fetch the UserInstance
:returns: The fetched UserInstance
"""
return await self._proxy.fetch_async()
def update(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> "UserInstance":
"""
Update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the User.
:param attributes: A valid JSON string that contains application-specific data.
:param friendly_name: A descriptive string that you create to describe the resource. It is often used for display purposes.
:returns: The updated UserInstance
"""
return self._proxy.update(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> "UserInstance":
"""
Asynchronous coroutine to update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the User.
:param attributes: A valid JSON string that contains application-specific data.
:param friendly_name: A descriptive string that you create to describe the resource. It is often used for display purposes.
:returns: The updated UserInstance
"""
return await self._proxy.update_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
@property
def user_bindings(self) -> UserBindingList:
"""
Access the user_bindings
"""
return self._proxy.user_bindings
@property
def user_channels(self) -> UserChannelList:
"""
Access the user_channels
"""
return self._proxy.user_channels
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.Chat.V2.UserInstance {}>".format(context)
class UserContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, sid: str):
"""
Initialize the UserContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to update the User resource in.
:param sid: The SID of the User resource to update. This value can be either the `sid` or the `identity` of the User resource to update.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Users/{sid}".format(**self._solution)
self._user_bindings: Optional[UserBindingList] = None
self._user_channels: Optional[UserChannelList] = None
def delete(self) -> bool:
"""
Deletes the UserInstance
: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 UserInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> UserInstance:
"""
Fetch the UserInstance
:returns: The fetched UserInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> UserInstance:
"""
Asynchronous coroutine to fetch the UserInstance
:returns: The fetched UserInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
def update(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the User.
:param attributes: A valid JSON string that contains application-specific data.
:param friendly_name: A descriptive string that you create to describe the resource. It is often used for display purposes.
:returns: The updated UserInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.update(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Asynchronous coroutine to update the UserInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the User.
:param attributes: A valid JSON string that contains application-specific data.
:param friendly_name: A descriptive string that you create to describe the resource. It is often used for display purposes.
:returns: The updated UserInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.update_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@property
def user_bindings(self) -> UserBindingList:
"""
Access the user_bindings
"""
if self._user_bindings is None:
self._user_bindings = UserBindingList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._user_bindings
@property
def user_channels(self) -> UserChannelList:
"""
Access the user_channels
"""
if self._user_channels is None:
self._user_channels = UserChannelList(
self._version,
self._solution["service_sid"],
self._solution["sid"],
)
return self._user_channels
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.Chat.V2.UserContext {}>".format(context)
class UserPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserInstance:
"""
Build an instance of UserInstance
:param payload: Payload response from the API
"""
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.UserPage>"
class UserList(ListResource):
def __init__(self, version: Version, service_sid: str):
"""
Initialize the UserList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the User resources from.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
}
self._uri = "/Services/{service_sid}/Users".format(**self._solution)
def create(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Create the UserInstance
:param identity: The `identity` value that uniquely identifies the new resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). This value is often a username or email address. See the Identity documentation for more info.
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the new User.
:param attributes: A valid JSON string that contains application-specific data.
:param friendly_name: A descriptive string that you create to describe the new resource. This value is often used for display purposes.
:returns: The created UserInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = self._version.create(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
identity: str,
x_twilio_webhook_enabled: Union[
"UserInstance.WebhookEnabledType", object
] = values.unset,
role_sid: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
friendly_name: Union[str, object] = values.unset,
) -> UserInstance:
"""
Asynchronously create the UserInstance
:param identity: The `identity` value that uniquely identifies the new resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). This value is often a username or email address. See the Identity documentation for more info.
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/chat/rest/role-resource) to assign to the new User.
:param attributes: A valid JSON string that contains application-specific data.
:param friendly_name: A descriptive string that you create to describe the new resource. This value is often used for display purposes.
:returns: The created UserInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
"Attributes": attributes,
"FriendlyName": friendly_name,
}
)
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
payload = await self._version.create_async(
method="POST", uri=self._uri, data=data, headers=headers
)
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserInstance]:
"""
Streams UserInstance 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[UserInstance]:
"""
Asynchronously streams UserInstance 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[UserInstance]:
"""
Lists UserInstance 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[UserInstance]:
"""
Asynchronously lists UserInstance 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,
) -> UserPage:
"""
Retrieve a single page of UserInstance 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 UserInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserPage(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,
) -> UserPage:
"""
Asynchronously retrieve a single page of UserInstance 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 UserInstance
"""
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 UserPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserPage:
"""
Retrieve a specific page of UserInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserPage:
"""
Asynchronously retrieve a specific page of UserInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserPage(self._version, response, self._solution)
def get(self, sid: str) -> UserContext:
"""
Constructs a UserContext
:param sid: The SID of the User resource to update. This value can be either the `sid` or the `identity` of the User resource to update.
"""
return UserContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __call__(self, sid: str) -> UserContext:
"""
Constructs a UserContext
:param sid: The SID of the User resource to update. This value can be either the `sid` or the `identity` of the User resource to update.
"""
return UserContext(
self._version, service_sid=self._solution["service_sid"], sid=sid
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.UserList>"
@@ -0,0 +1,533 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 UserBindingInstance(InstanceResource):
class BindingType(object):
GCM = "gcm"
APN = "apn"
FCM = "fcm"
"""
:ivar sid: The unique string that we created to identify the User Binding resource.
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the User Binding resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the User Binding resource is associated with.
:ivar date_created: The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
:ivar endpoint: The unique endpoint identifier for the User Binding. The format of the value depends on the `binding_type`.
:ivar identity: The application-defined string that uniquely identifies the resource's [User](https://www.twilio.com/docs/chat/rest/user-resource) within the [Service](https://www.twilio.com/docs/chat/rest/service-resource). See [access tokens](https://www.twilio.com/docs/chat/create-tokens) for more info.
:ivar user_sid: The SID of the [User](https://www.twilio.com/docs/chat/rest/user-resource) with the User Binding resource. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:ivar credential_sid: The SID of the [Credential](https://www.twilio.com/docs/chat/rest/credential-resource) for the binding. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:ivar binding_type:
:ivar message_types: The [Programmable Chat message types](https://www.twilio.com/docs/chat/push-notification-configuration#push-types) the binding is subscribed to.
:ivar url: The absolute URL of the User Binding resource.
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
user_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.endpoint: Optional[str] = payload.get("endpoint")
self.identity: Optional[str] = payload.get("identity")
self.user_sid: Optional[str] = payload.get("user_sid")
self.credential_sid: Optional[str] = payload.get("credential_sid")
self.binding_type: Optional["UserBindingInstance.BindingType"] = payload.get(
"binding_type"
)
self.message_types: Optional[List[str]] = payload.get("message_types")
self.url: Optional[str] = payload.get("url")
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"sid": sid or self.sid,
}
self._context: Optional[UserBindingContext] = None
@property
def _proxy(self) -> "UserBindingContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UserBindingContext for this UserBindingInstance
"""
if self._context is None:
self._context = UserBindingContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=self._solution["sid"],
)
return self._context
def delete(self) -> bool:
"""
Deletes the UserBindingInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the UserBindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
def fetch(self) -> "UserBindingInstance":
"""
Fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "UserBindingInstance":
"""
Asynchronous coroutine to fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
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.Chat.V2.UserBindingInstance {}>".format(context)
class UserBindingContext(InstanceContext):
def __init__(self, version: Version, service_sid: str, user_sid: str, sid: str):
"""
Initialize the UserBindingContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to fetch the User Binding resource from.
:param user_sid: The SID of the [User](https://www.twilio.com/docs/chat/rest/user-resource) with the User Binding resource to fetch. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
:param sid: The SID of the User Binding resource to fetch.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"sid": sid,
}
self._uri = "/Services/{service_sid}/Users/{user_sid}/Bindings/{sid}".format(
**self._solution
)
def delete(self) -> bool:
"""
Deletes the UserBindingInstance
: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 UserBindingInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
def fetch(self) -> UserBindingInstance:
"""
Fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return UserBindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=self._solution["sid"],
)
async def fetch_async(self) -> UserBindingInstance:
"""
Asynchronous coroutine to fetch the UserBindingInstance
:returns: The fetched UserBindingInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return UserBindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_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.Chat.V2.UserBindingContext {}>".format(context)
class UserBindingPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserBindingInstance:
"""
Build an instance of UserBindingInstance
:param payload: Payload response from the API
"""
return UserBindingInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.UserBindingPage>"
class UserBindingList(ListResource):
def __init__(self, version: Version, service_sid: str, user_sid: str):
"""
Initialize the UserBindingList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the User Binding resources from.
:param user_sid: The SID of the [User](https://www.twilio.com/docs/chat/rest/user-resource) with the User Binding resources to read. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
}
self._uri = "/Services/{service_sid}/Users/{user_sid}/Bindings".format(
**self._solution
)
def stream(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserBindingInstance]:
"""
Streams UserBindingInstance 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 List[&quot;UserBindingInstance.BindingType&quot;] binding_type: The push technology used by the User Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
: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(binding_type=binding_type, page_size=limits["page_size"])
return self._version.stream(page, limits["limit"])
async def stream_async(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> AsyncIterator[UserBindingInstance]:
"""
Asynchronously streams UserBindingInstance 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 List[&quot;UserBindingInstance.BindingType&quot;] binding_type: The push technology used by the User Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
: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(
binding_type=binding_type, page_size=limits["page_size"]
)
return self._version.stream_async(page, limits["limit"])
def list(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[UserBindingInstance]:
"""
Lists UserBindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;UserBindingInstance.BindingType&quot;] binding_type: The push technology used by the User Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
: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(
binding_type=binding_type,
limit=limit,
page_size=page_size,
)
)
async def list_async(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[UserBindingInstance]:
"""
Asynchronously lists UserBindingInstance records from the API as a list.
Unlike stream(), this operation is eager and will load `limit` records into
memory before returning.
:param List[&quot;UserBindingInstance.BindingType&quot;] binding_type: The push technology used by the User Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
: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(
binding_type=binding_type,
limit=limit,
page_size=page_size,
)
]
def page(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> UserBindingPage:
"""
Retrieve a single page of UserBindingInstance records from the API.
Request is executed immediately
:param binding_type: The push technology used by the User Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
: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 UserBindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserBindingPage(self._version, response, self._solution)
async def page_async(
self,
binding_type: Union[
List["UserBindingInstance.BindingType"], object
] = values.unset,
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
) -> UserBindingPage:
"""
Asynchronously retrieve a single page of UserBindingInstance records from the API.
Request is executed immediately
:param binding_type: The push technology used by the User Binding resources to read. Can be: `apn`, `gcm`, or `fcm`. See [push notification configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more info.
: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 UserBindingInstance
"""
data = values.of(
{
"BindingType": serialize.map(binding_type, lambda e: e),
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = await self._version.page_async(
method="GET", uri=self._uri, params=data
)
return UserBindingPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserBindingPage:
"""
Retrieve a specific page of UserBindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserBindingInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserBindingPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserBindingPage:
"""
Asynchronously retrieve a specific page of UserBindingInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserBindingInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserBindingPage(self._version, response, self._solution)
def get(self, sid: str) -> UserBindingContext:
"""
Constructs a UserBindingContext
:param sid: The SID of the User Binding resource to fetch.
"""
return UserBindingContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=sid,
)
def __call__(self, sid: str) -> UserBindingContext:
"""
Constructs a UserBindingContext
:param sid: The SID of the User Binding resource to fetch.
"""
return UserBindingContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
sid=sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.UserBindingList>"
@@ -0,0 +1,679 @@
r"""
This code was generated by
___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
| | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
| |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
Twilio - Chat
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 UserChannelInstance(InstanceResource):
class ChannelStatus(object):
JOINED = "joined"
INVITED = "invited"
NOT_PARTICIPATING = "not_participating"
class NotificationLevel(object):
DEFAULT = "default"
MUTED = "muted"
class WebhookEnabledType(object):
TRUE = "true"
FALSE = "false"
"""
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the User Channel resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) the User Channel resource is associated with.
:ivar channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) the User Channel resource belongs to.
:ivar user_sid: The SID of the [User](https://www.twilio.com/docs/chat/rest/user-resource) the User Channel belongs to.
:ivar member_sid: The SID of a [Member](https://www.twilio.com/docs/chat/rest/member-resource) that represents the User on the Channel.
:ivar status:
:ivar last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read.
:ivar unread_messages_count: The number of unread Messages in the Channel for the User. Note that retrieving messages on a client endpoint does not mean that messages are consumed or read. See [Consumption Horizon feature](https://www.twilio.com/docs/chat/consumption-horizon) to learn how to mark messages as consumed.
:ivar links: The absolute URLs of the [Members](https://www.twilio.com/docs/chat/rest/member-resource), [Messages](https://www.twilio.com/docs/chat/rest/message-resource) , [Invites](https://www.twilio.com/docs/chat/rest/invite-resource) and, if it exists, the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) for the Channel.
:ivar url: The absolute URL of the User Channel resource.
:ivar notification_level:
"""
def __init__(
self,
version: Version,
payload: Dict[str, Any],
service_sid: str,
user_sid: str,
channel_sid: Optional[str] = None,
):
super().__init__(version)
self.account_sid: Optional[str] = payload.get("account_sid")
self.service_sid: Optional[str] = payload.get("service_sid")
self.channel_sid: Optional[str] = payload.get("channel_sid")
self.user_sid: Optional[str] = payload.get("user_sid")
self.member_sid: Optional[str] = payload.get("member_sid")
self.status: Optional["UserChannelInstance.ChannelStatus"] = payload.get(
"status"
)
self.last_consumed_message_index: Optional[int] = deserialize.integer(
payload.get("last_consumed_message_index")
)
self.unread_messages_count: Optional[int] = deserialize.integer(
payload.get("unread_messages_count")
)
self.links: Optional[Dict[str, object]] = payload.get("links")
self.url: Optional[str] = payload.get("url")
self.notification_level: Optional[
"UserChannelInstance.NotificationLevel"
] = payload.get("notification_level")
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"channel_sid": channel_sid or self.channel_sid,
}
self._context: Optional[UserChannelContext] = None
@property
def _proxy(self) -> "UserChannelContext":
"""
Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UserChannelContext for this UserChannelInstance
"""
if self._context is None:
self._context = UserChannelContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
return self._context
def delete(
self,
x_twilio_webhook_enabled: Union[
"UserChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the UserChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"UserChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the UserChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async(
x_twilio_webhook_enabled=x_twilio_webhook_enabled,
)
def fetch(self) -> "UserChannelInstance":
"""
Fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
return self._proxy.fetch()
async def fetch_async(self) -> "UserChannelInstance":
"""
Asynchronous coroutine to fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
return await self._proxy.fetch_async()
def update(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> "UserChannelInstance":
"""
Update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read.
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:returns: The updated UserChannelInstance
"""
return self._proxy.update(
notification_level=notification_level,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
)
async def update_async(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> "UserChannelInstance":
"""
Asynchronous coroutine to update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read.
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:returns: The updated UserChannelInstance
"""
return await self._proxy.update_async(
notification_level=notification_level,
last_consumed_message_index=last_consumed_message_index,
last_consumption_timestamp=last_consumption_timestamp,
)
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.Chat.V2.UserChannelInstance {}>".format(context)
class UserChannelContext(InstanceContext):
def __init__(
self, version: Version, service_sid: str, user_sid: str, channel_sid: str
):
"""
Initialize the UserChannelContext
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to update the User Channel resource in.
:param user_sid: The SID of the [User](https://www.twilio.com/docs/chat/rest/user-resource) to update the User Channel resource from. This value can be either the `sid` or the `identity` of the User resource.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) with the User Channel resource to update. This value can be the Channel resource's `sid` or `unique_name`.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
"channel_sid": channel_sid,
}
self._uri = (
"/Services/{service_sid}/Users/{user_sid}/Channels/{channel_sid}".format(
**self._solution
)
)
def delete(
self,
x_twilio_webhook_enabled: Union[
"UserChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Deletes the UserChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return self._version.delete(method="DELETE", uri=self._uri, headers=headers)
async def delete_async(
self,
x_twilio_webhook_enabled: Union[
"UserChannelInstance.WebhookEnabledType", object
] = values.unset,
) -> bool:
"""
Asynchronous coroutine that deletes the UserChannelInstance
:param x_twilio_webhook_enabled: The X-Twilio-Webhook-Enabled HTTP request header
:returns: True if delete succeeds, False otherwise
"""
headers = values.of(
{
"X-Twilio-Webhook-Enabled": x_twilio_webhook_enabled,
}
)
return await self._version.delete_async(
method="DELETE", uri=self._uri, headers=headers
)
def fetch(self) -> UserChannelInstance:
"""
Fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
payload = self._version.fetch(
method="GET",
uri=self._uri,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
async def fetch_async(self) -> UserChannelInstance:
"""
Asynchronous coroutine to fetch the UserChannelInstance
:returns: The fetched UserChannelInstance
"""
payload = await self._version.fetch_async(
method="GET",
uri=self._uri,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
def update(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> UserChannelInstance:
"""
Update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read.
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:returns: The updated UserChannelInstance
"""
data = values.of(
{
"NotificationLevel": notification_level,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_sid"],
)
async def update_async(
self,
notification_level: Union[
"UserChannelInstance.NotificationLevel", object
] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
last_consumption_timestamp: Union[datetime, object] = values.unset,
) -> UserChannelInstance:
"""
Asynchronous coroutine to update the UserChannelInstance
:param notification_level:
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) in the [Channel](https://www.twilio.com/docs/chat/channels) that the Member has read.
:param last_consumption_timestamp: The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp of the last [Message](https://www.twilio.com/docs/chat/rest/message-resource) read event for the Member within the [Channel](https://www.twilio.com/docs/chat/channels).
:returns: The updated UserChannelInstance
"""
data = values.of(
{
"NotificationLevel": notification_level,
"LastConsumedMessageIndex": last_consumed_message_index,
"LastConsumptionTimestamp": serialize.iso8601_datetime(
last_consumption_timestamp
),
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=self._solution["channel_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.Chat.V2.UserChannelContext {}>".format(context)
class UserChannelPage(Page):
def get_instance(self, payload: Dict[str, Any]) -> UserChannelInstance:
"""
Build an instance of UserChannelInstance
:param payload: Payload response from the API
"""
return UserChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.UserChannelPage>"
class UserChannelList(ListResource):
def __init__(self, version: Version, service_sid: str, user_sid: str):
"""
Initialize the UserChannelList
:param version: Version that contains the resource
:param service_sid: The SID of the [Service](https://www.twilio.com/docs/chat/rest/service-resource) to read the User Channel resources from.
:param user_sid: The SID of the [User](https://www.twilio.com/docs/chat/rest/user-resource) to read the User Channel resources from. This value can be either the `sid` or the `identity` of the User resource.
"""
super().__init__(version)
# Path Solution
self._solution = {
"service_sid": service_sid,
"user_sid": user_sid,
}
self._uri = "/Services/{service_sid}/Users/{user_sid}/Channels".format(
**self._solution
)
def stream(
self,
limit: Optional[int] = None,
page_size: Optional[int] = None,
) -> Iterator[UserChannelInstance]:
"""
Streams UserChannelInstance 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[UserChannelInstance]:
"""
Asynchronously streams UserChannelInstance 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[UserChannelInstance]:
"""
Lists UserChannelInstance 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[UserChannelInstance]:
"""
Asynchronously lists UserChannelInstance 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,
) -> UserChannelPage:
"""
Retrieve a single page of UserChannelInstance 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 UserChannelInstance
"""
data = values.of(
{
"PageToken": page_token,
"Page": page_number,
"PageSize": page_size,
}
)
response = self._version.page(method="GET", uri=self._uri, params=data)
return UserChannelPage(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,
) -> UserChannelPage:
"""
Asynchronously retrieve a single page of UserChannelInstance 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 UserChannelInstance
"""
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 UserChannelPage(self._version, response, self._solution)
def get_page(self, target_url: str) -> UserChannelPage:
"""
Retrieve a specific page of UserChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserChannelInstance
"""
response = self._version.domain.twilio.request("GET", target_url)
return UserChannelPage(self._version, response, self._solution)
async def get_page_async(self, target_url: str) -> UserChannelPage:
"""
Asynchronously retrieve a specific page of UserChannelInstance records from the API.
Request is executed immediately
:param target_url: API-generated URL for the requested results page
:returns: Page of UserChannelInstance
"""
response = await self._version.domain.twilio.request_async("GET", target_url)
return UserChannelPage(self._version, response, self._solution)
def get(self, channel_sid: str) -> UserChannelContext:
"""
Constructs a UserChannelContext
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) with the User Channel resource to update. This value can be the Channel resource's `sid` or `unique_name`.
"""
return UserChannelContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=channel_sid,
)
def __call__(self, channel_sid: str) -> UserChannelContext:
"""
Constructs a UserChannelContext
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/chat/channels) with the User Channel resource to update. This value can be the Channel resource's `sid` or `unique_name`.
"""
return UserChannelContext(
self._version,
service_sid=self._solution["service_sid"],
user_sid=self._solution["user_sid"],
channel_sid=channel_sid,
)
def __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V2.UserChannelList>"