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.v1.credential import CredentialList
from twilio.rest.chat.v1.service import ServiceList
class V1(Version):
def __init__(self, domain: Domain):
"""
Initialize the V1 version of Chat
:param domain: The Twilio.chat domain
"""
super().__init__(domain, "v1")
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.V1>"
@@ -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/api/rest/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 [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) 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+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----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+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----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.V1.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 Twilio-provided string that uniquely identifies 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+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----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+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----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.V1.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.V1.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+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----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+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----`
:param private_key: [APN only] The URL encoded representation of the private key. For example, `-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----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 Twilio-provided string that uniquely identifies the Credential resource to update.
"""
return CredentialContext(self._version, sid=sid)
def __call__(self, sid: str) -> CredentialContext:
"""
Constructs a CredentialContext
:param sid: The Twilio-provided string that uniquely identifies 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.V1.CredentialList>"
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,755 @@
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.v1.service.channel.invite import InviteList
from twilio.rest.chat.v1.service.channel.member import MemberList
from twilio.rest.chat.v1.service.channel.message import MessageList
class ChannelInstance(InstanceResource):
class ChannelType(object):
PUBLIC = "public"
PRIVATE = "private"
"""
: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/api/rest/account) that created the Channel resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/api/chat/rest/services) the 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. **Note** If this property has been assigned a value, it's only displayed in a FETCH action that returns a single resource; otherwise, it's null. If the 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 [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) 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 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/api/members), [Messages](https://www.twilio.com/docs/chat/api/messages) , [Invites](https://www.twilio.com/docs/chat/api/invites) and, if it exists, the last [Message](https://www.twilio.com/docs/chat/api/messages) 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) -> bool:
"""
Deletes the ChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the ChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
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,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Update the ChannelInstance
:param friendly_name: A descriptive string that you create to describe the 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 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.
:returns: The updated ChannelInstance
"""
return self._proxy.update(
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
)
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "ChannelInstance":
"""
Asynchronous coroutine to update the ChannelInstance
:param friendly_name: A descriptive string that you create to describe the 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 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.
:returns: The updated ChannelInstance
"""
return await self._proxy.update_async(
friendly_name=friendly_name,
unique_name=unique_name,
attributes=attributes,
)
@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
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.V1.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/api/chat/rest/services) to update the resource from.
:param sid: The Twilio-provided string that uniquely identifies 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
def delete(self) -> bool:
"""
Deletes the ChannelInstance
: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 ChannelInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
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,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Update the ChannelInstance
:param friendly_name: A descriptive string that you create to describe the 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 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.
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return ChannelInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
friendly_name: Union[str, object] = values.unset,
unique_name: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> ChannelInstance:
"""
Asynchronous coroutine to update the ChannelInstance
:param friendly_name: A descriptive string that you create to describe the 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 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.
:returns: The updated ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
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
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.V1.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.V1.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/api/chat/rest/services) to read the 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,
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,
) -> ChannelInstance:
"""
Create the ChannelInstance
: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 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:
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return ChannelInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
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,
) -> ChannelInstance:
"""
Asynchronously create the ChannelInstance
: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 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:
:returns: The created ChannelInstance
"""
data = values.of(
{
"FriendlyName": friendly_name,
"UniqueName": unique_name,
"Attributes": attributes,
"Type": type,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
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 Twilio-provided string that uniquely identifies 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 Twilio-provided string that uniquely identifies 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.V1.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/api/rest/account) that created the Invite resource.
:ivar channel_sid: The SID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the resource belongs to.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/api/chat/rest/services) the resource is associated with.
:ivar identity: The application-defined string that uniquely identifies the resource's [User](https://www.twilio.com/docs/api/chat/rest/users) within the [Service](https://www.twilio.com/docs/api/chat/rest/services). See [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) for more info.
:ivar date_created: The date and time in GMT when the resource was created specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) 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.V1.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/api/chat/rest/services) to fetch the resource from.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the resource to fetch belongs to.
:param sid: The Twilio-provided string that uniquely identifies 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.V1.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.V1.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/api/chat/rest/services) to read the resources from.
:param channel_sid: The SID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the resources to read belong to.
"""
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/api/chat/rest/v1/user) within the [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). See [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) for more info.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) 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/api/chat/rest/v1/user) within the [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). See [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) for more info.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) 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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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 Twilio-provided string that uniquely identifies 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 Twilio-provided string that uniquely identifies 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.V1.InviteList>"
@@ -0,0 +1,683 @@
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):
"""
: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/api/rest/account) that created the Member resource.
:ivar channel_sid: The unique ID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) for the member.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/api/chat/rest/services) the resource is associated with.
:ivar identity: The application-defined string that uniquely identifies the resource's [User](https://www.twilio.com/docs/api/chat/rest/users) within the [Service](https://www.twilio.com/docs/api/chat/rest/services). See [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) for more info.
:ivar date_created: The date and time in GMT when the resource was created specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned to the member.
:ivar last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/api/chat/rest/messages) in the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) that the Member has read.
:ivar last_consumption_timestamp: The ISO 8601 timestamp string that represents the date-time of the last [Message](https://www.twilio.com/docs/api/chat/rest/messages) read event for the Member within the [Channel](https://www.twilio.com/docs/api/chat/rest/channels).
:ivar url: The absolute URL of the Member 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.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._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) -> bool:
"""
Deletes the MemberInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the MemberInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
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,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> "MemberInstance":
"""
Update the MemberInstance
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/api/services).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/api/chat/rest/messages) that the Member has read within the [Channel](https://www.twilio.com/docs/api/chat/rest/channels).
:returns: The updated MemberInstance
"""
return self._proxy.update(
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_index,
)
async def update_async(
self,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> "MemberInstance":
"""
Asynchronous coroutine to update the MemberInstance
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/api/services).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/api/chat/rest/messages) that the Member has read within the [Channel](https://www.twilio.com/docs/api/chat/rest/channels).
:returns: The updated MemberInstance
"""
return await self._proxy.update_async(
role_sid=role_sid,
last_consumed_message_index=last_consumed_message_index,
)
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.V1.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/api/chat/rest/services) to update the resource from.
:param channel_sid: The unique ID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the member to update belongs to. Can be the Channel resource's `sid` or `unique_name`.
:param sid: The Twilio-provided string that uniquely identifies the Member 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}/Members/{sid}".format(
**self._solution
)
)
def delete(self) -> bool:
"""
Deletes the MemberInstance
: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 MemberInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
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,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> MemberInstance:
"""
Update the MemberInstance
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/api/services).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/api/chat/rest/messages) that the Member has read within the [Channel](https://www.twilio.com/docs/api/chat/rest/channels).
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
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,
role_sid: Union[str, object] = values.unset,
last_consumed_message_index: Union[int, object] = values.unset,
) -> MemberInstance:
"""
Asynchronous coroutine to update the MemberInstance
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/api/services).
:param last_consumed_message_index: The index of the last [Message](https://www.twilio.com/docs/api/chat/rest/messages) that the Member has read within the [Channel](https://www.twilio.com/docs/api/chat/rest/channels).
:returns: The updated MemberInstance
"""
data = values.of(
{
"RoleSid": role_sid,
"LastConsumedMessageIndex": last_consumed_message_index,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
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.V1.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.V1.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/api/chat/rest/services) to read the resources from.
:param channel_sid: The unique ID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the members to read belong to. Can be the Channel resource's `sid` or `unique_name` value.
"""
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, role_sid: 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/api/chat/rest/v1/user) within the [Service](https://www.twilio.com/docs/api/chat/rest/services). See [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) for more details.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/api/services).
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return MemberInstance(
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
) -> MemberInstance:
"""
Asynchronously create the MemberInstance
:param identity: The `identity` value that uniquely identifies the new resource's [User](https://www.twilio.com/docs/api/chat/rest/v1/user) within the [Service](https://www.twilio.com/docs/api/chat/rest/services). See [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) for more details.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) to assign to the member. The default roles are those specified on the [Service](https://www.twilio.com/docs/chat/api/services).
:returns: The created MemberInstance
"""
data = values.of(
{
"Identity": identity,
"RoleSid": role_sid,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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/api/chat/rest/v1/user)'s `identity` value of the resources to read. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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 Twilio-provided string that uniquely identifies the Member resource to update.
"""
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 Twilio-provided string that uniquely identifies the Member resource to update.
"""
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.V1.MemberList>"
@@ -0,0 +1,696 @@
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 MessageInstance(InstanceResource):
class OrderType(object):
ASC = "asc"
DESC = "desc"
"""
: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/api/rest/account) that created the Message resource.
:ivar attributes: The JSON string that stores application-specific data. **Note** If this property has been assigned a value, it's only displayed in a FETCH action that returns a single resource; otherwise, it's null. If the attributes have not been set, `{}` is returned.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/api/chat/rest/services) the resource is associated with.
:ivar to: The SID of the [Channel](https://www.twilio.com/docs/chat/api/channels) that the message was sent to.
:ivar channel_sid: The unique ID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the Message resource belongs to.
:ivar date_created: The date and time in GMT when the resource was created specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar was_edited: Whether the message has been edited since it was created.
:ivar _from: The [identity](https://www.twilio.com/docs/api/chat/guides/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/api/channels).
: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.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.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) -> bool:
"""
Deletes the MessageInstance
:returns: True if delete succeeds, False otherwise
"""
return self._proxy.delete()
async def delete_async(self) -> bool:
"""
Asynchronous coroutine that deletes the MessageInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._proxy.delete_async()
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,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Update the MessageInstance
:param body: The message to send to the channel. Can also 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.
:returns: The updated MessageInstance
"""
return self._proxy.update(
body=body,
attributes=attributes,
)
async def update_async(
self,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> "MessageInstance":
"""
Asynchronous coroutine to update the MessageInstance
:param body: The message to send to the channel. Can also 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.
:returns: The updated MessageInstance
"""
return await self._proxy.update_async(
body=body,
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.V1.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/api/chat/rest/services) to update the resource from.
:param channel_sid: The unique ID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the message belongs to. Can be the Channel's `sid` or `unique_name`.
:param sid: The Twilio-provided string that uniquely identifies 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) -> bool:
"""
Deletes the MessageInstance
: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 MessageInstance
:returns: True if delete succeeds, False otherwise
"""
return await self._version.delete_async(
method="DELETE",
uri=self._uri,
)
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,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Update the MessageInstance
:param body: The message to send to the channel. Can also 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.
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
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,
body: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronous coroutine to update the MessageInstance
:param body: The message to send to the channel. Can also 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.
:returns: The updated MessageInstance
"""
data = values.of(
{
"Body": body,
"Attributes": attributes,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
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.V1.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.V1.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/api/chat/rest/services) to read the resources from.
:param channel_sid: The unique ID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the message to read belongs to. Can be the Channel'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,
body: str,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Create the MessageInstance
:param body: The message to send to the channel. Can also 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 from_: The [identity](https://www.twilio.com/docs/api/chat/guides/identity) of the new message's author. The default value is `system`.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The created MessageInstance
"""
data = values.of(
{
"Body": body,
"From": from_,
"Attributes": attributes,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return MessageInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
channel_sid=self._solution["channel_sid"],
)
async def create_async(
self,
body: str,
from_: Union[str, object] = values.unset,
attributes: Union[str, object] = values.unset,
) -> MessageInstance:
"""
Asynchronously create the MessageInstance
:param body: The message to send to the channel. Can also 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 from_: The [identity](https://www.twilio.com/docs/api/chat/guides/identity) of the new message's author. The default value is `system`.
:param attributes: A valid JSON string that contains application-specific data.
:returns: The created MessageInstance
"""
data = values.of(
{
"Body": body,
"From": from_,
"Attributes": attributes,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
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 Twilio-provided string that uniquely identifies 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 Twilio-provided string that uniquely identifies 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.V1.MessageList>"
@@ -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/api/rest/account) that created the Role resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/api/chat/rest/services) the 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, formatted as a JSON string.
:ivar date_created: The date and time in GMT when the resource was created specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) 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. The values for this parameter depend on the role's `type` and are described in the documentation.
: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. The values for this parameter depend on the role's `type` and are described in the documentation.
: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.V1.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/api/chat/rest/services) to update the resource from.
:param sid: The Twilio-provided string that uniquely identifies 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. The values for this parameter depend on the role's `type` and are described in the documentation.
: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. The values for this parameter depend on the role's `type` and are described in the documentation.
: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.V1.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.V1.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/api/chat/rest/services) to read the 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` and are described in the documentation.
: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` and are described in the documentation.
: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 Twilio-provided string that uniquely identifies 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 Twilio-provided string that uniquely identifies 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.V1.RoleList>"
@@ -0,0 +1,690 @@
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.v1.service.user.user_channel import UserChannelList
class UserInstance(InstanceResource):
"""
: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/api/rest/account) that created the User resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/api/chat/rest/services) the resource is associated with.
:ivar attributes: The JSON string that stores application-specific data. **Note** If this property has been assigned a value, it's only displayed in a FETCH action that returns a single resource; otherwise, it's null. If the 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/api/chat/rest/roles) 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/api/chat/rest/services). This value is often a username or an email address. See [access tokens](https://www.twilio.com/docs/api/chat/guides/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 [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar date_updated: The date and time in GMT when the resource was last updated specified in [RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
:ivar joined_channels_count: The number of Channels this User is a Member of.
:ivar links: The absolute URLs of the [Channel](https://www.twilio.com/docs/chat/api/channels) and [Binding](https://www.twilio.com/docs/chat/rest/bindings-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,
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 role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned to this 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(
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
async def update_async(
self,
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 role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned to this 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(
role_sid=role_sid,
attributes=attributes,
friendly_name=friendly_name,
)
@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.V1.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/api/chat/rest/services) to update the resource from.
:param sid: The Twilio-provided string that uniquely identifies 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_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,
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 role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned to this 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,
}
)
payload = self._version.update(
method="POST",
uri=self._uri,
data=data,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
async def update_async(
self,
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 role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned to this 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,
}
)
payload = await self._version.update_async(
method="POST",
uri=self._uri,
data=data,
)
return UserInstance(
self._version,
payload,
service_sid=self._solution["service_sid"],
sid=self._solution["sid"],
)
@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.V1.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.V1.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/api/chat/rest/services) to read the 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,
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/api/chat/rest/v1/user) within the [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). This value is often a username or email address. See the Identity documentation for more details.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned 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,
}
)
payload = self._version.create(
method="POST",
uri=self._uri,
data=data,
)
return UserInstance(
self._version, payload, service_sid=self._solution["service_sid"]
)
async def create_async(
self,
identity: str,
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/api/chat/rest/v1/user) within the [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). This value is often a username or email address. See the Identity documentation for more details.
:param role_sid: The SID of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned 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,
}
)
payload = await self._version.create_async(
method="POST",
uri=self._uri,
data=data,
)
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 Twilio-provided string that uniquely identifies 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 Twilio-provided string that uniquely identifies 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.V1.UserList>"
@@ -0,0 +1,310 @@
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 Any, Dict, List, Optional, Union, Iterator, AsyncIterator
from twilio.base import deserialize, values
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"
"""
:ivar account_sid: The SID of the [Account](https://www.twilio.com/docs/api/rest/account) that created the User Channel resource.
:ivar service_sid: The SID of the [Service](https://www.twilio.com/docs/api/chat/rest/services) the resource is associated with.
:ivar channel_sid: The SID of the [Channel](https://www.twilio.com/docs/api/chat/rest/channels) the resource belongs to.
:ivar member_sid: The SID of a [Member](https://www.twilio.com/docs/api/chat/rest/members) 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/api/chat/rest/messages) in the [Channel](https://www.twilio.com/docs/api/chat/rest/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](/docs/api/chat/guides/consumption-horizon) to learn how to mark messages as consumed.
:ivar links: The absolute URLs of the [Members](https://www.twilio.com/docs/chat/api/members), [Messages](https://www.twilio.com/docs/chat/api/messages) , [Invites](https://www.twilio.com/docs/chat/api/invites) and, if it exists, the last [Message](https://www.twilio.com/docs/chat/api/messages) for the Channel.
"""
def __init__(
self, version: Version, payload: Dict[str, Any], service_sid: str, user_sid: str
):
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.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._solution = {
"service_sid": service_sid,
"user_sid": user_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.V1.UserChannelInstance {}>".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.V1.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/api/chat/rest/services) to read the resources from.
:param user_sid: The SID of the [User](https://www.twilio.com/docs/api/chat/rest/users) to read the User Channel resources from.
"""
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 __repr__(self) -> str:
"""
Provide a friendly representation
:returns: Machine friendly representation
"""
return "<Twilio.Chat.V1.UserChannelList>"