from collections.abc import Generator
from typing import Any, Optional
from pydantic import TypeAdapter
from wxc_sdk.api_child import ApiChild
from wxc_sdk.base import ApiModel
from wxc_sdk.common import UserType
__all__ = ['MeSpeedDial', 'MeSpeedDials', 'MeSpeedDialModify', 'MeSpeedDialAvailableMember', 'MeSpeedDialApi']
[docs]
class MeSpeedDial(ApiModel):
#: The identifier of the person, place or virtual line. See type for the resource type (PEOPLE, PLACE, or
#: VIRTUAL_LINE). Only present for org speed dials.
id: Optional[str] = None
#: The last name of the person or virtual line.
last_name: Optional[str] = None
#: The first name of the person or virtual line.
first_name: Optional[str] = None
#: The display name of the person, place or virtual line.
display_name: Optional[str] = None
#: Indicates whether the type is `PEOPLE`, `PLACE` or `VIRTUAL_LINE`. Only present for org speed dials.
type: Optional[UserType] = None
#: The phone number of the person, place or virtual line.
phone_number: Optional[str] = None
#: The extension number for the person, place or virtual line.
extension: Optional[str] = None
#: Routing prefix of location.
routing_prefix: Optional[str] = None
#: The location name where the speed dial is. Only present for org speed dials.
location_name: Optional[str] = None
#: The ID for the location. Only present for org speed dials.
location_id: Optional[str] = None
#: This is a custom label configured for the speed dial on the device.
line_key_label: Optional[str] = None
[docs]
class MeSpeedDials(ApiModel):
#: List of speed dial entries configured for the person.
speed_dials: Optional[list[MeSpeedDial]] = None
#: This is the number of additional entries that can be stored (more than the number of entries listed).
available_entries_count: Optional[int] = None
[docs]
class MeSpeedDialAvailableMember(ApiModel):
#: The identifier of the person, place or virtual line. See type for the resource type.
id: Optional[str] = None
#: The last name of the person or virtual line.
last_name: Optional[str] = None
#: The first name of the person or virtual line.
first_name: Optional[str] = None
#: The display name of the person, place or virtual line.
display_name: Optional[str] = None
#: The phone number of the person, place or virtual line.
phone_number: Optional[str] = None
#: The extension number for the person, place or virtual line.
extension: Optional[str] = None
#: Indicates whether the type is `PEOPLE`, `VIRTUAL_LINE` or `PLACE`.
type: Optional[UserType] = None
#: The ID for the location.
location_id: Optional[str] = None
#: The location name where the member is.
location_name: Optional[str] = None
[docs]
class MeSpeedDialModify(ApiModel):
#: The identifier of the person (PEOPLE), place (PLACE), or virtual line (VIRTUAL_LINE) to add as a speed dial. Use
#: this field when adding a speed dial for an existing member in the organization. Either `id` or `phoneNumber`
#: must be provided.
id: Optional[str] = None
#: The phone number to add as a speed dial. Use this field when adding a speed dial for an external contact or
#: custom number. Either `id` or `phoneNumber` must be provided.
phone_number: Optional[str] = None
#: This is a custom label configured for the speed dial on the device.
line_key_label: Optional[str] = None
[docs]
class MeSpeedDialApi(ApiChild, base='telephony/config/people/me'):
[docs]
def get(self) -> MeSpeedDials: # type: ignore[override]
"""
Get Speed Dials
Get the Speed Dials settings for the authenticated user. This API returns all configured speed dials (no
pagination).
Speed Dials allow Webex Calling users to quickly dial frequently contacted people, places, or virtual lines by
assigning them to dedicated keys on their desk phones or soft clients.
This API requires a user auth token with a scope of `spark:telephony_config_read`.
:rtype: :class:`MeSpeedDials`
"""
url = self.ep('settings/speedDials')
data = super().get(url)
r = MeSpeedDials.model_validate(data)
return r
[docs]
def modify(self, speed_dials: list[MeSpeedDialModify]) -> None:
"""
Modify Speed Dials
Modify the Speed Dials settings for the authenticated user. This is a replacement list for speed dials.
Speed Dials allow Webex Calling users to quickly dial frequently contacted people, places, or virtual lines by
assigning them to dedicated keys on their desk phones or soft clients.
This API requires a user auth token with a scope of `spark:telephony_config_write`.
:param speed_dials: List of speed dial entries to be configured for the person. This is a replacement list.
:type speed_dials: list[MeSpeedDialModify]
:rtype: None
"""
body: dict[str, Any] = dict()
body['speedDials'] = TypeAdapter(list[MeSpeedDialModify]).dump_python(
speed_dials, mode='json', by_alias=True, exclude_none=True
)
url = self.ep('settings/speedDials')
super().put(url, json=body)
[docs]
def available_members(
self,
location_id: str = None,
name: list[str] = None,
phone_number: list[str] = None,
order: str = None,
**params: Any,
) -> Generator[MeSpeedDialAvailableMember, None, None]:
"""
Get Speed Dial Available Members
Get the available members which can be configured as Speed Dials for the authenticated user.
Speed Dials allow Webex Calling users to quickly dial frequently contacted people, places, or virtual lines by
assigning them to dedicated keys on their desk phones or soft clients.
This API requires a user auth token with a scope of `spark:telephony_config_read`.
:param location_id: Return the members list available in this location.
:type location_id: str
:param name: Search (Contains) based on first name and last name.
:type name: list[str]
:param phone_number: Search (Contains) based on number and extension.
:type phone_number: list[str]
:param order: Sort by first name (`firstName`) or last name (`lastName`). Sort directions asc or desc.
* `asc` - Sort in ascending order.
* `desc` - Sort in descending order.
:type order: str
:return: Generator yielding :class:`SpeedDialAvailableMember` instances
"""
if location_id is not None:
params['locationId'] = location_id
if name is not None:
params['name'] = ','.join(name)
if phone_number is not None:
params['phoneNumber'] = ','.join(phone_number)
if order is not None:
params['order'] = order
url = self.ep('settings/speedDials/availableMembers')
return self.session.follow_pagination(
url=url, model=MeSpeedDialAvailableMember, item_key='members', params=params
)