"""
MoH API for locations
"""
import json
from typing import Union, Optional
from ...api_child import ApiChild
from ...base import ApiModel
from ...base import SafeEnum as Enum
from ...common import AuthCode
__all__ = ['LocationMoHGreetingType', 'LocationMoHSetting', 'LocationMoHApi']
[docs]class LocationMoHGreetingType(str, Enum):
"""
Greeting type for the location.
"""
#: Play default music when call is placed on hold or parked. The system plays music to fill the silence and lets
#: the customer know they are still connected.
system = 'SYSTEM'
#: Play custom music when call is placed on hold or parked. An audio file must already have been successfully
#: uploaded to specify this option.
custom = 'CUSTOM'
[docs]class LocationMoHSetting(ApiModel):
"""
location's music on hold settings.
"""
#: If enabled, music will be played when call is placed on hold.
call_hold_enabled: Optional[bool]
#: If enabled, music will be played when call is parked.
call_park_enabled: Optional[bool]
#: Greeting type for the location.
greeting: Optional[LocationMoHGreetingType]
[docs]class LocationMoHApi(ApiChild, base='telephony/config/locations'):
"""
Access codes API
"""
def _endpoint(self, *, location_id: str, path: str = None) -> str:
"""
location specific feature endpoint like
/v1/telephony/config/locations/{locationId}/musicOnHold
:meta private:
:param location_id: Unique identifier for the location.
:type location_id: str
:param path: additional path
:type: path: str
:return: full endpoint
:rtype: str
"""
path = path and f'/{path}' or ''
ep = self.session.ep(f'telephony/config/locations/{location_id}/musicOnHold{path}')
return ep
[docs] def read(self, location_id: str, org_id: str = None) -> LocationMoHSetting:
"""
Get Music On Hold
Retrieve the location's music on hold settings.
Location's music on hold settings allows you to play music when a call is placed on hold or parked.
Retrieving location's music on hold settings requires a full, user or read-only administrator auth token with
a scope of spark-admin:telephony_config_read.
:param location_id: Retrieve access codes details for this location.
:type location_id: str
:param org_id: Retrieve access codes details for a customer location in this organization
:type org_id: str
:return: MoH settings
:rtype: :class:`LocationMoHSetting`
"""
params = org_id and {'orgId': org_id} or None
url = self._endpoint(location_id=location_id)
data = self.get(url, params=params)
return LocationMoHSetting.parse_obj(data)
[docs] def update(self, location_id: str, settings: LocationMoHSetting, org_id: str = None) -> LocationMoHSetting:
"""
Get Music On Hold
Retrieve the location's music on hold settings.
Location's music on hold settings allows you to play music when a call is placed on hold or parked.
Retrieving location's music on hold settings requires a full, user or read-only administrator auth token with
a scope of spark-admin:telephony_config_read.
:param location_id: Retrieve access codes details for this location.
:type location_id: str
:param settings: new settings
:type settings: :class:`LocationMoHSetting`
:param org_id: Retrieve access codes details for a customer location in this organization
:type org_id: str
:return: list of :class:`wxc_sdk.common.CallPark`
"""
params = org_id and {'orgId': org_id} or None
data = settings.json()
url = self._endpoint(location_id=location_id)
self.put(url, params=params, data=data)
[docs] def create(self, location_id: str, access_codes: list[AuthCode], org_id: str = None) -> list[AuthCode]:
"""
:param location_id: Add new access code for this location.
:type location_id: str
:param access_codes: Access code details
:type access_codes: list of :class:`wxc_sdk.common.AuthCode`
:param org_id: Add new access code for this organization.
:type org_id: str
"""
params = org_id and {'orgId': org_id} or None
url = self._endpoint(location_id=location_id)
body = {'accessCodes': [json.loads(ac.json()) for ac in access_codes]}
self.post(url, json=body, params=params)
[docs] def delete_codes(self, location_id: str, access_codes: list[Union[str, AuthCode]],
org_id: str = None) -> list[AuthCode]:
"""
Delete Access Code Location
Deletes the access code details for a particular location for a customer.
Use Access Codes to bypass the set permissions for all persons/workspaces at this location.
Modifying the access code location details requires a full administrator auth token with a scope
of spark-admin:telephony_config_write.
:param location_id: Deletes the access code details for this location.
:type location_id: str
:param access_codes: access codes to delete
:type access_codes: list of :class:`wxc_sdk.common.AuthCode` or str
:param org_id: Delete access codes from this organization.
:type org_id: str
"""
params = org_id and {'orgId': org_id} or None
url = self._endpoint(location_id=location_id)
body = {'deleteCodes': [ac.code if isinstance(ac, AuthCode) else ac
for ac in access_codes]}
self.put(url, json=body, params=params)