From ca73b872962cd9507af667e31940406b1f1afc8b Mon Sep 17 00:00:00 2001 From: zuczkows Date: Wed, 21 Oct 2026 15:22:10 +0200 Subject: [PATCH] ME-4054: Remove support for v3.4 --- changelog.md | 2 +- livechat/agent/rtm/api/v34.py | 962 ----------------------- livechat/agent/rtm/base.py | 4 +- livechat/agent/web/api/v34.py | 1019 ------------------------ livechat/agent/web/base.py | 6 +- livechat/configuration/api/v34.py | 1210 ----------------------------- livechat/configuration/base.py | 6 +- livechat/customer/rtm/api/v34.py | 664 ---------------- livechat/customer/rtm/base.py | 4 +- livechat/customer/web/api/v34.py | 966 ----------------------- livechat/customer/web/base.py | 4 +- livechat/reports/api/v34.py | 386 --------- livechat/reports/base.py | 6 +- livechat/tests/test_wh_parser.py | 2 - livechat/webhooks/parser.py | 4 +- livechat/webhooks/v34.py | 370 --------- 16 files changed, 8 insertions(+), 5607 deletions(-) delete mode 100644 livechat/agent/rtm/api/v34.py delete mode 100644 livechat/agent/web/api/v34.py delete mode 100644 livechat/configuration/api/v34.py delete mode 100644 livechat/customer/rtm/api/v34.py delete mode 100644 livechat/customer/web/api/v34.py delete mode 100644 livechat/reports/api/v34.py delete mode 100644 livechat/webhooks/v34.py diff --git a/changelog.md b/changelog.md index 959a7f5..c8dfb04 100644 --- a/changelog.md +++ b/changelog.md @@ -30,7 +30,7 @@ All notable changes to this project will be documented in this file. - Fixed passing query params in customer-api WEB client for httpx v0.28.0 compatibility. ### Removed -- Support for version 3.3. +- Support for versions 3.3 and 3.4. - Removed support for billing-api. - Support `get_predicted_agent` in customer-api v3.7. - Support for `create_customer` method removed in agent-api v3.6 and later. diff --git a/livechat/agent/rtm/api/v34.py b/livechat/agent/rtm/api/v34.py deleted file mode 100644 index 3fe6c8c..0000000 --- a/livechat/agent/rtm/api/v34.py +++ /dev/null @@ -1,962 +0,0 @@ -''' Module containing Agent RTM API client implementation for v3.4. ''' - -from typing import Any, Callable, Optional, Union - -from livechat.utils.helpers import prepare_payload -from livechat.utils.structures import AccessToken, RtmResponse -from livechat.utils.ws_client import WebsocketClient - -# pylint: disable=unused-argument, too-many-arguments, invalid-name, redefined-builtin - - -class AgentRtmV34: - ''' Agent RTM API Class containing methods in version 3.4. ''' - def __init__( - self, - url: str, - header: Union[list, dict, Callable, None], - ): - self.ws = WebsocketClient(url=f'wss://{url}/v3.4/agent/rtm/ws', - header=header) - - def open_connection(self, - origin: dict = None, - ping_timeout: Union[float, int] = 3, - ping_interval: Union[float, int] = 5, - ws_conn_timeout: Union[float, int] = 10, - keep_alive: bool = True, - response_timeout: Union[float, int] = 3) -> None: - ''' Opens WebSocket connection. - - Args: - origin (dict): Specifies origin while creating websocket connection. - ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 3 seconds. - ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). - If set to 0, no ping is sent periodically, by default sets to 5 seconds. - ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, - by default sets to 10 seconds. - keep_alive(bool): Bool which states if connection should be kept, by default sets to `True`. - response_timeout (int or float): timeout (in seconds) to wait for the response, - by default sets to 3 seconds. - ''' - self.ws.open(origin, ping_timeout, ping_interval, ws_conn_timeout, - keep_alive, response_timeout) - - def close_connection(self) -> None: - ''' Closes WebSocket connection. ''' - self.ws.close() - - # Chats - - def list_chats(self, - filters: dict = None, - sort_order: str = None, - limit: int = None, - page_id: str = None, - payload: dict = None) -> RtmResponse: - ''' Returns summaries of the chats an Agent has access to. - - Args: - filters (dict): Possible request filters. Mustn't change between requests for subsequent pages. - Otherwise, the behavior is undefined. - sort_order (str): Possible values: asc, desc (default). Chat summaries are sorted by the - creation date of its last thread. - limit (int): Chats limit per page. Default: 10, maximum: 100. - page_id (str): Page ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'list_chats', 'payload': payload}) - - def list_threads(self, - chat_id: str = None, - sort_order: str = None, - limit: int = None, - page_id: str = None, - min_events_count: int = None, - filters: dict = None, - payload: dict = None) -> RtmResponse: - ''' Returns threads that the current Agent has access to in a given chat. - - Args: - chat_id (str): Chat ID to get threads from. - sort_order (str): Possible values: asc - oldest threads first and desc - - newest threads first (default). - limit (int): Default: 3, maximum: 100. - page_id (str): Page ID. - min_events_count (int): Range: 1-100; Specifies the minimum number of - events to be returned in the response. - filters (dict): Filters object. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'list_threads', 'payload': payload}) - - def get_chat(self, - chat_id: str = None, - thread_id: str = None, - payload: dict = None) -> RtmResponse: - ''' Returns a thread that the current Agent has access to in a given chat. - - Args: - chat_id (str): ID of a chat to get. - thread_id (str): Thread ID to get. Default: the latest thread (if exists). - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'get_chat', 'payload': payload}) - - def list_archives(self, - filters: dict = None, - page_id: str = None, - sort_order: str = None, - limit: int = None, - highlights: dict = None, - payload: dict = None) -> RtmResponse: - ''' Returns a list of the chats an Agent has access to. - - Args: - filters (dict): Filters object. - page_id (str): Page ID. - sort_order (str): Possible values: asc - oldest threads first and desc - - newest threads first (default). - limit (int): Default: 10, minimum: 1, maximum: 100. - highlights (dict): Use it to highlight the match of filters.query. - To enable highlights with default parameters, pass an empty object. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'list_archives', 'payload': payload}) - - def start_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None) -> RtmResponse: - ''' Starts a chat. - - Args: - chat (dict): Chat object. - active (bool): When set to False, creates an inactive thread; default: True. - continuous (bool): Starts chat as continuous (online group is not required); default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'start_chat', 'payload': payload}) - - def resume_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None) -> RtmResponse: - ''' Restarts an archived chat. - - Args: - chat (dict): Chat object. - active (bool): When set to False, creates an inactive thread; default: True. - continuous (bool): Sets a chat to the continuous mode. When unset, leaves the mode unchanged. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'resume_chat', 'payload': payload}) - - def deactivate_chat(self, - id: str = None, - ignore_requester_presence: bool = None, - payload: dict = None) -> RtmResponse: - ''' Deactivates a chat by closing the currently open thread. - - Args: - id (str): Chat ID to deactivate. - ignore_requester_presence (bool): If `True`, allows requester to deactivate chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'deactivate_chat', 'payload': payload}) - - def follow_chat(self, id: str = None, payload: dict = None) -> RtmResponse: - ''' Marks a chat as followed. - - Args: - id (str): Chat ID to follow. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'follow_chat', 'payload': payload}) - - def unfollow_chat(self, - id: str = None, - payload: dict = None) -> RtmResponse: - ''' Removes the requester from the chat followers. - - Args: - id (str): Chat ID to unfollow. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'unfollow_chat', 'payload': payload}) - -# Chat access - - def transfer_chat(self, - id: str = None, - target: dict = None, - ignore_agents_availability: bool = None, - ignore_requester_presence: bool = None, - payload: dict = None) -> RtmResponse: - ''' Transfers a chat to an agent or a group. - - Args: - id (str): Chat ID. - target (dict): Target object. If missing, the chat will be - transferred within the current group. - ignore_agents_availability (bool): If `True`, always transfers chats. Otherwise, fails - when unable to assign any agent from the requested groups. - ignore_requester_presence (bool): If `True`, allows requester to transfer chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'transfer_chat', 'payload': payload}) - -# Chat users - - def add_user_to_chat(self, - chat_id: str = None, - user_id: str = None, - user_type: str = None, - visibility: str = None, - ignore_requester_presence: bool = None, - payload: dict = None) -> RtmResponse: - ''' Adds a user to the chat. You can't add more than - one customer user type to the chat. - - Args: - chat_id (str): Chat ID. - user_id (str): ID of the user that will be added to the chat. - user_type (str): Possible values: agent or customer. - visibility (str): Determines the visibility of events sent by - the agent. Possible values: `all` or `agents`. - ignore_requester_presence (bool): If `True`, allows requester to add user to chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for - the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'add_user_to_chat', 'payload': payload}) - - def remove_user_from_chat(self, - chat_id: str = None, - user_id: str = None, - user_type: str = None, - ignore_requester_presence: bool = None, - payload: dict = None) -> RtmResponse: - ''' Removes a user from chat. - - Args: - chat_id (str): Chat ID. - user_id (str): ID of the user that will be added to the chat. - user_type (str): Possible values: agent or customer. - ignore_requester_presence (bool): If `True`, allows requester to remove user from chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'remove_user_from_chat', - 'payload': payload - }) - -# Events - - def send_event(self, - chat_id: str = None, - event: dict = None, - attach_to_last_thread: bool = None, - author_id: Optional[str] = None, - payload: dict = None) -> RtmResponse: - ''' Sends an Event object. - - Args: - chat_id (str): ID of the chat you want to send the message to. - event (dict): Event object. - attach_to_last_thread (bool): Flag which states if event object should be added to last thread. - The flag is ignored for active chats. - author_id (optional str): Provide if the event should be sent on behalf of a bot. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - opts = {} - if author_id: - opts['author_id'] = author_id - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'send_event', - 'payload': payload, - **opts - }) - - def send_rich_message_postback(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - postback: dict = None, - payload: dict = None) -> RtmResponse: - ''' Sends rich message postback. - - Args: - chat_id (str): ID of the chat to send a rich message to. - thread_id (str): ID of the thread. - event_id (str): ID of the event. - postback (dict): Postback object. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'send_rich_message_postback', - 'payload': payload - }) - -# Properties - - def update_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Updates chat properties. - - Args: - id (str): ID of the chat you to set a property for. - properties (dict): Chat properties to set. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'update_chat_properties', - 'payload': payload - }) - - def delete_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Deletes chat properties. - - Args: - id (str): ID of the chat you want to delete properties of. - properties (dict): Chat properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'delete_chat_properties', - 'payload': payload - }) - - def update_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Updates thread properties. - - Args: - chat_id (str): ID of the chat you want to set properties for. - thread_id (str): ID of the thread you want to set properties for. - properties (dict): Chat properties to set. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'update_thread_properties', - 'payload': payload - }) - - def delete_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Deletes thread properties. - - Args: - chat_id (str): ID of the chat you want to delete the properties of. - thread_id (str): ID of the thread you want to delete the properties of. - properties (dict): Thread properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'delete_thread_properties', - 'payload': payload - }) - - def update_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Updates event properties. - - Args: - chat_id (str): ID of the chat you want to set properties for. - thread_id (str): ID of the thread you want to set properties for. - event_id (str): ID of the event you want to set properties for. - properties (dict): Chat properties to set. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'update_event_properties', - 'payload': payload - }) - - def delete_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Deletes event properties. - - Args: - chat_id (str): ID of the chat you want to delete the properties of. - thread_id (str): ID of the thread you want to delete the properties of. - event_id (str): ID of the event you want to delete the properties of. - properties (dict): Event properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'delete_event_properties', - 'payload': payload - }) - -# Thread tags - - def tag_thread(self, - chat_id: str = None, - thread_id: str = None, - tag: str = None, - payload: dict = None) -> RtmResponse: - ''' Tags thread. - - Args: - chat_id (str): ID of the chat you want to add a tag to. - thread_id (str): ID of the thread you want to add a tag to. - tag (str): Tag name. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'tag_thread', 'payload': payload}) - - def untag_thread(self, - chat_id: str = None, - thread_id: str = None, - tag: str = None, - payload: dict = None) -> RtmResponse: - ''' Untags thread. - - Args: - chat_id (str): ID of the chat you want to remove a tag from. - thread_id (str): ID of the thread you want to remove a tag from. - tag (str): Tag name. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'untag_thread', 'payload': payload}) - -# Customers - - def get_customer(self, - id: str = None, - payload: dict = None) -> RtmResponse: - ''' Returns the info about the Customer with a given ID. - - Args: - id (str): ID of the Customer. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'get_customer', 'payload': payload}) - - def list_customers(self, - page_id: str = None, - limit: int = None, - sort_order: str = None, - sort_by: str = None, - filters: dict = None, - payload: dict = None) -> RtmResponse: - ''' Returns the list of Customers. - - Args: - page_id (str): Page ID. - limit (int): Customers limit. Default: 10, maximum: 100. - sort_order (str): Possible values: asc, desc (default). Customers are sorted - by the creation date. - sort_by (str): Possible values: created_at (default), threads_count, visits_count, - agent_last_event or customer_last_event. - filters (dict): Filters object. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'list_customers', 'payload': payload}) - - def create_customer(self, - name: str = None, - email: str = None, - avatar: str = None, - session_fields: list = None, - payload: dict = None) -> RtmResponse: - ''' Creates a new Customer user type. - - Args: - name (str): Customer's name. - email (str): Customer's email. - avatar (str): URL of the Customer's avatar. - session_fields (list): An array of custom object-enclosed key:value pairs. - Respects the order of items. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'create_customer', 'payload': payload}) - - def update_customer(self, - id: str = None, - name: str = None, - email: str = None, - avatar: str = None, - session_fields: list = None, - payload: dict = None) -> RtmResponse: - ''' Updates Customer's properties. - - Args: - id (str): ID of the Customer. UUID v4 format is required. - name (str): Customer's name. - email (str): Customer's email. - avatar (str): URL of the Customer's avatar. - session_fields (list): An array of custom object-enclosed key:value pairs. - Respects the order of items. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'update_customer', 'payload': payload}) - - def ban_customer(self, - id: str = None, - ban: dict = None, - payload: dict = None) -> RtmResponse: - ''' Bans the customer for a specific period of time. - - Args: - id (str): ID of the Customer. UUID v4 format is required. - ban (dict): Ban object containing the number of days that - the Customer will be banned. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'ban_customer', 'payload': payload}) - -# Status - - def login(self, - token: Union[AccessToken, str] = None, - timezone: str = None, - reconnect: bool = None, - push_notifications: dict = None, - application: dict = None, - away: bool = None, - customer_monitoring_level: str = None, - pushes: dict = None, - payload: dict = None) -> RtmResponse: - ''' Logs in agent. - - Args: - token (str): OAuth token from the Agent's account. - timezone (str): Agent's timezone. - reconnect (bool): Reconnecting sets the status to the - last known state instead of the default one. - push_notifications (dict): Push notifications for the requested token. - application (dict): Object containing information related to - the application's name and version. - away (bool): When True, the connection is set to the away state. - Defaults to False. - customer_monitoring_level (str): Possible values are: `my`, `chatting`, `invited`, `online` and `highest_available`. - Defaults to my if login creates the first session; - otherwise it preserves the current customer_monitoring_level. - pushes (dict): Use case: when you want to receive only specific pushes. - By default, it's set to all for the version of your currently established RTM connection. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if token: - token = str(token) - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'login', 'payload': payload}) - - def change_push_notifications(self, - firebase_token: str = None, - platform: str = None, - enabled: bool = None, - payload: dict = None) -> RtmResponse: - ''' Changes the firebase push notifications properties. - - Args: - firebase_token (str): Firebase device token. - platform (str): OS platform. Possible values: ios, android. - enabled (bool): Enable or disable push notifications for the requested token. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'change_push_notifications', - 'payload': payload - }) - - def set_routing_status(self, - status: str = None, - agent_id: str = None, - payload: dict = None) -> RtmResponse: - ''' Changes the status of an Agent or a Bot Agent. - - Args: - status (str): For Agents: accepting_chats or not_accepting_chats. - For Bot Agents: accepting_chats, not_accepting_chats, or offline. - agent_id (str): If not specified, the requester's status will be updated. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'set_routing_status', - 'payload': payload - }) - - def set_away_status(self, - away: bool = None, - payload: dict = None) -> RtmResponse: - ''' Sets an Agent's connection to the away state. - - Args: - away (bool): A flag. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'set_away_status', 'payload': payload}) - - def logout(self, payload: dict = None) -> RtmResponse: - ''' Logs out agent. - - Args: - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - return self.ws.send({ - 'action': 'logout', - 'payload': {} if payload is None else payload - }) - - def list_routing_statuses(self, - filters: dict = None, - payload: dict = None) -> RtmResponse: - ''' Returns the current routing status of each agent selected by the provided filters. - - Args: - filters (dict): Filters object. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'list_routing_statuses', - 'payload': payload - }) - - -# Other - - def mark_events_as_seen(self, - chat_id: str = None, - seen_up_to: str = None, - payload: dict = None) -> RtmResponse: - ''' Marks events as seen by agent. - - Args: - chat_id (str): Chat to mark events. - seen_up_to (str): Date up to which mark events - RFC 3339 date-time format. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'mark_events_as_seen', - 'payload': payload - }) - - def send_typing_indicator(self, - chat_id: str = None, - visibility: str = None, - is_typing: bool = None, - payload: dict = None) -> RtmResponse: - ''' Sends a typing indicator. - - Args: - chat_id (str): ID of the chat you want to send the typing indicator to. - visibility (str): Possible values: `all`, `agents`. - is_typing (bool): A flag that indicates if you are typing. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'send_typing_indicator', - 'payload': payload - }) - - def multicast(self, - recipients: dict = None, - content: Any = None, - type: str = None, - payload: dict = None) -> RtmResponse: - ''' Sends a multicast (chat-unrelated communication). - - Args: - recipients (object): Object containing filters related to multicast recipients. - content (typing.Any): A JSON message to be sent. - type (str): Multicast message type. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'multicast', 'payload': payload}) - - def list_agents_for_transfer(self, - chat_id: str = None, - payload: dict = None) -> RtmResponse: - ''' Returns the list of Agents you can transfer a chat to. - - Args: - chat_id (str): ID of the chat you want to transfer. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'list_agents_for_transfer', - 'payload': payload - }) diff --git a/livechat/agent/rtm/base.py b/livechat/agent/rtm/base.py index 52d54b1..bbcccef 100644 --- a/livechat/agent/rtm/base.py +++ b/livechat/agent/rtm/base.py @@ -5,7 +5,6 @@ from typing import Callable, Union -from livechat.agent.rtm.api.v34 import AgentRtmV34 from livechat.agent.rtm.api.v35 import AgentRtmV35 from livechat.agent.rtm.api.v36 import AgentRtmV36 from livechat.agent.rtm.api.v37 import AgentRtmV37 @@ -22,7 +21,7 @@ def get_client( version: str = stable_version, base_url: str = api_url, header: Union[list, dict, Callable, None] = None, - ) -> Union[AgentRtmV34, AgentRtmV35, AgentRtmV36, AgentRtmV37]: + ) -> Union[AgentRtmV35, AgentRtmV36, AgentRtmV37]: ''' Returns client for specific Agent RTM version. Args: @@ -38,7 +37,6 @@ def get_client( ValueError: If the specified version does not exist. ''' client = { - '3.4': AgentRtmV34, '3.5': AgentRtmV35, '3.6': AgentRtmV36, '3.7': AgentRtmV37, diff --git a/livechat/agent/web/api/v34.py b/livechat/agent/web/api/v34.py deleted file mode 100644 index de2ff7b..0000000 --- a/livechat/agent/web/api/v34.py +++ /dev/null @@ -1,1019 +0,0 @@ -''' Agent Web client implementation for v3.4. ''' - -# pylint: disable=W0613,R0913,W0622,C0103,W0221 -from __future__ import annotations - -import typing - -import httpx - -from livechat.utils.helpers import prepare_payload -from livechat.utils.http_client import HttpClient -from livechat.utils.structures import AccessToken - -# pylint: disable=R0903 - - -class AgentWebV34(HttpClient): - ''' Agent Web API Class containing methods in version 3.4. ''' - def __init__(self, - access_token: typing.Union[AccessToken, str], - base_url: str, - http2: bool, - proxies=None, - verify: bool = True, - disable_logging: bool = False, - timeout: float = httpx.Timeout(15)): - super().__init__(access_token, base_url, http2, proxies, verify, - disable_logging, timeout) - self.api_url = f'https://{base_url}/v3.4/agent/action' - - # Chats - - def list_chats(self, - filters: dict = None, - sort_order: str = None, - limit: int = None, - page_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns summaries of the chats an Agent has access to. - - Args: - filters (dict): Possible request filters. Mustn't change between - requests for subsequent pages. Otherwise, - the behavior is undefined. - sort_order (str): Possible values: asc, desc (default). - Chat summaries are sorted by the creation - date of its last thread. - limit (int): Limit of results per page. Default: 10, maximum: 100. - page_id (str): ID of the page with paginated results. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided - for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_chats', - json=payload, - headers=headers) - - def list_threads(self, - chat_id: str = None, - sort_order: str = None, - limit: str = None, - page_id: str = None, - min_events_count: int = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns threads that the current Agent has access to in a given chat. - - Args: - chat_id (str): ID of the chat for which threads are to be listed. - sort_order (str): Possible values: asc, desc (default). - limit (str): Limit of results per page. Default: 3, maximum: 100. - page_id (str): ID of the page with paginated results. - min_events_count (int): Range: 1-100; - Specifies the minimum number of events - to be returned in the response. - filters (dict): Possible request filters. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_threads', - json=payload, - headers=headers) - - def get_chat(self, - chat_id: str = None, - thread_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns a thread that the current Agent has access to in a given chat - - Args: - chat_id (str): ID of the chat for which thread is to be returned. - thread_id (str): ID of the thread to show. Default: the latest thread (if exists) - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_chat', - json=payload, - headers=headers) - - def list_archives(self, - filters: dict = None, - page_id: str = None, - sort_order: str = None, - limit: str = None, - highlights: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns a list of the chats an Agent has access to. - Together with a chat, the events of one thread from this chat are returned. - - Args: - filters (dict): Possible request filters. - page_id (str): ID of the page with paginated results. - sort_order (str): Possible values: asc, desc (default). - Chat summaries are sorted by the creation date - of its last thread. - limit (str): Limit of results per page. Default: 10, maximum: 100. - highlights (dict): Use it to highlight the match of filters.query. - To enable highlights with default parameters, - pass an empty object. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_archives', - json=payload, - headers=headers) - - def start_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Starts a chat. - - Args: - chat (dict): Dict containing chat properties, access and thread. - active (bool): When set to False, creates an inactive thread; default: True. - continuous (bool): Starts chat as continuous (online group is not required); default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/start_chat', - json=payload, - headers=headers) - - def resume_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Restarts an archived chat. - - Args: - chat (dict): Dict containing chat properties, access and thread. - active (bool): When set to False, creates an inactive thread; default: True. - continuous (bool): Starts chat as continuous (online group is not required); default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/resume_chat', - json=payload, - headers=headers) - - def deactivate_chat(self, - id: str = None, - ignore_requester_presence: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deactivates a chat by closing the currently open thread. - Sending messages to this thread will no longer be possible. - - Args: - id (str): Chat ID to deactivate. - ignore_requester_presence (bool): If `True`, allows requester to deactivate chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/deactivate_chat', - json=payload, - headers=headers) - - def follow_chat(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Marks a chat as followed. All changes to the chat will be sent to the requester - until the chat is reactivated or unfollowed. Chat members don't need to follow - their chats. They receive all chat pushes regardless of their follower status. - - Args: - id (str): ID of chat to be followed. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/follow_chat', - json=payload, - headers=headers) - - def unfollow_chat(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Removes the requester from the chat followers. After that, only key changes - to the chat (like transfer_chat or close_active_thread) will be sent - to the requester. Chat members cannot unfollow the chat. - - Args: - id (str): ID of chat to be unfollowed. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/unfollow_chat', - json=payload, - headers=headers) - -# Chat access - - def transfer_chat(self, - id: str = None, - target: dict = None, - ignore_agents_availability: bool = None, - ignore_requester_presence: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Transfers a chat to an agent or a group. - - Args: - id (str): chat ID - target (dict): If missing, chat will be transferred within the current group. - ignore_agents_availability (bool): If `True`, always transfers chats. Otherwise, fails - when unable to assign any agent from the requested groups. - ignore_requester_presence (bool): If `True`, allows requester to transfer chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/transfer_chat', - json=payload, - headers=headers) - -# Chat users - - def add_user_to_chat(self, - chat_id: str = None, - user_id: str = None, - user_type: str = None, - visibility: str = None, - ignore_requester_presence: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Adds a user to the chat. You can't add more than one customer user - type to the chat. - - Args: - chat_id (str): chat ID. - user_id (str): user ID. - user_type (str): Possible values: agent or customer. - visibility (str): Determines the visibility of events sent by - the agent. Possible values: `all` or `agents`. - ignore_requester_presence (bool): If `True`, allows requester to add user to chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/add_user_to_chat', - json=payload, - headers=headers) - - def remove_user_from_chat(self, - chat_id: str = None, - user_id: str = None, - user_type: str = None, - ignore_requester_presence: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Removes a user from chat. - - Args: - chat_id (str): chat ID. - user_id (str): user ID. - user_type (str): Possible values: agent or customer. - ignore_requester_presence (bool): If `True`, allows requester to remove user from chat - without being present in the chat's users list. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/remove_user_from_chat', - json=payload, - headers=headers) - -# Events - - def send_event(self, - chat_id: str = None, - event: dict = None, - attach_to_last_thread: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Sends an Event object. Use this method to send a message by specifying the Message event type in the request. - The method updates the requester's `events_seen_up_to` as if they've seen all chat events. - - Args: - chat_id (int): ID of the chat that you to send a message to. - event (dict): Event object. - attach_to_last_thread (bool): The flag is ignored for active chats. - For inactive chats: - True – the event will be added to the last thread; - False – the request will fail. Default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/send_event', - json=payload, - headers=headers) - - def upload_file(self, - file: typing.BinaryIO = None, - headers: dict = None) -> httpx.Response: - ''' Uploads a file to the server as a temporary file. It returns a URL that expires - after 24 hours unless the URL is used in `send_event`. - - Args: - file (typing.BinaryIO): File-like object with file to upload (Maximum size: 10MB). - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - return self.session.post(f'{self.api_url}/upload_file', - files=file, - headers=headers) - - def send_rich_message_postback(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - postback: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Sends a rich message postback. - - Args: - chat_id (str): ID of the chat to send rich message postback to. - thread_id (str): ID of the thread to send rich message postback to. - event_id (str): ID of the event related to the rich message postback. - postback (dict): Object containing postback data (id, toggled). - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/send_rich_message_postback', - json=payload, - headers=headers) - -# Properties - - def update_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates chat properties. - - Args: - id (str): ID of the chat you to set a property for. - properties (dict): Chat properties to set. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_chat_properties', - json=payload, - headers=headers) - - def delete_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes chat properties. - - Args: - id (str): ID of the chat you want to delete properties of. - properties (dict): Chat properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_chat_properties', - json=payload, - headers=headers) - - def update_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates chat thread properties. - - Args: - chat_id (str): ID of the chat you to set properties for. - thread_id (str): ID of the thread you want to set properties for. - properties (dict): Thread properties to set. - You should stick to the general properties format and include namespace, property name and value. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_thread_properties', - json=payload, - headers=headers) - - def delete_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes chat thread properties. - - Args: - chat_id (str): ID of the chat you want to delete the properties of. - thread_id (str): ID of the thread you want to delete the properties of. - properties (dict): Thread properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_thread_properties', - json=payload, - headers=headers) - - def update_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates event properties. - - Args: - chat_id (str): ID of the chat you to set properties for. - thread_id (str): ID of the thread you want to set properties for. - event_id (str): ID of the event you want to set properties for. - properties (dict): Thread properties to set. - You should stick to the general properties format and include namespace, property name and value. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_event_properties', - json=payload, - headers=headers) - - def delete_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes event properties. - - Args: - chat_id (str): ID of the chat you to delete the properties for. - thread_id (str): ID of the thread you want to delete the properties for. - event_id (str): ID of the event you want to delete the properties for. - properties (dict): Event properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_event_properties', - json=payload, - headers=headers) - -# Thread tags - - def tag_thread(self, - chat_id: str = None, - thread_id: str = None, - tag: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Tags thread. - - Args: - chat_id (str): ID of the chat you want to add a tag to. - thread_id (str): ID of the thread you want to add a tag to. - tag (str): Tag name. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/tag_thread', - json=payload, - headers=headers) - - def untag_thread(self, - chat_id: str = None, - thread_id: str = None, - tag: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Untags thread. - - Args: - chat_id (str): ID of the chat you want to remove a tag from. - thread_id (str): ID of the thread you want to remove a tag from. - tag (str): Tag name. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/untag_thread', - json=payload, - headers=headers) - -# Customers - - def get_customer(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the info about the Customer with a given id. - - Args: - id (str): customer id - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_customer', - json=payload, - headers=headers) - - def list_customers(self, - page_id: str = None, - limit: str = None, - sort_order: str = None, - sort_by: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the list of Customers. - - Args: - page_id (str): ID of the page with paginated results. - limit (str): Limit of results per page. Default: 10, maximum: 100. - sort_order (str): Possible values: asc, desc (default). - sort_by (str): When sorting by fields other than created_at, the entries - with identical values will be additionally sorted by their - creation time. Possible values: created_at (default), - threads_count, visits_count, agent_last_event, customer_last_event. - filters (dict): Possible request filters. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_customers', - json=payload, - headers=headers) - - def create_customer(self, - name: str = None, - email: str = None, - avatar: str = None, - session_fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Creates a new Customer user type. - - Args: - name (str): Customer's name. - email (str): Customer's email. - avatar (str): URL of the Customer's avatar - session_fields (list): An array of custom object-enclosed key:value pairs. - Respects the order of items. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/create_customer', - json=payload, - headers=headers) - - def update_customer(self, - id: str = None, - name: str = None, - email: str = None, - avatar: str = None, - session_fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates Customer's properties. - - Args: - id (str): ID of the Customer. - name (str): Customer's name. - email (str): Customer's email. - avatar (str): URL of the Customer's avatar. - session_fields (list): An array of custom object-enclosed key:value pairs. - Respects the order of items. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_customer', - json=payload, - headers=headers) - - def ban_customer(self, - id: str = None, - ban: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Bans the customer for a specific period of time. It immediately - disconnects all active sessions of this customer and does not accept - new ones during the ban lifespan. - - Args: - id (str): ID of the Customer. - ban (dict): Ban object containing the number of days that - the Customer will be banned. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/ban_customer', - json=payload, - headers=headers) - -# Status - - def set_routing_status(self, - status: str = None, - agent_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Changes the status of an Agent or a Bot Agent. - - Args: - status (str): For Agents: accepting_chats or not_accepting_chats; - for Bot Agents: accepting_chats, not_accepting_chats, or offline - agent_id (str): If not specified, the requester's status will be updated. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/set_routing_status', - json=payload, - headers=headers) - - def list_routing_statuses(self, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the current routing status of each agent selected by the provided filters. - - Args: - filters (dict): Possible request filters. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_routing_statuses', - json=payload, - headers=headers) - - -# Other - - def mark_events_as_seen(self, - chat_id: str = None, - seen_up_to: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates `seen_up_to` value for a given chat. - - Args: - chat_id (str): Chat to mark events. - seen_up_to (str): Date up to which mark events - RFC 3339 date-time format - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/mark_events_as_seen', - json=payload, - headers=headers) - - def send_typing_indicator(self, - chat_id: str = None, - visibility: str = None, - is_typing: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Sends typing indicator. - - Args: - chat_id (str): ID of the chat that to send the typing indicator to. - visibility (str): Possible values: `all`, `agents`. - is_typing (bool): A flag that indicates if you are typing. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/send_typing_indicator', - json=payload, - headers=headers) - - def multicast(self, - recipients: dict = None, - content: typing.Any = None, - type: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Sends a multicast (chat-unrelated communication). - - Args: - recipients (dict): Object containing filters related to multicast recipients. - content (typing.Any): A JSON message to be sent. - type (str): Multicast message type. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/multicast', - json=payload, - headers=headers) - - def list_agents_for_transfer(self, - chat_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the list of Agents you can transfer a chat to. - - Args: - chat_id (str): ID of the chat you want to transfer. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_agents_for_transfer', - json=payload, - headers=headers) diff --git a/livechat/agent/web/base.py b/livechat/agent/web/base.py index cba71e5..302e60f 100644 --- a/livechat/agent/web/base.py +++ b/livechat/agent/web/base.py @@ -7,7 +7,6 @@ import httpx -from livechat.agent.web.api.v34 import AgentWebV34 from livechat.agent.web.api.v35 import AgentWebV35 from livechat.agent.web.api.v36 import AgentWebV36 from livechat.agent.web.api.v37 import AgentWebV37 @@ -31,7 +30,7 @@ def get_client( verify: bool = True, disable_logging: bool = False, timeout: float = httpx.Timeout(15) - ) -> Union[AgentWebV34, AgentWebV35, AgentWebV36, AgentWebV37]: + ) -> Union[AgentWebV35, AgentWebV36, AgentWebV37]: ''' Returns client for specific API version. Args: @@ -57,9 +56,6 @@ def get_client( ValueError: If the specified version does not exist. ''' client = { - '3.4': - AgentWebV34(access_token, base_url, http2, proxies, verify, - disable_logging, timeout), '3.5': AgentWebV35(access_token, base_url, http2, proxies, verify, disable_logging, timeout), diff --git a/livechat/configuration/api/v34.py b/livechat/configuration/api/v34.py deleted file mode 100644 index f780739..0000000 --- a/livechat/configuration/api/v34.py +++ /dev/null @@ -1,1210 +0,0 @@ -''' Configuration API module with client class in version 3.4. ''' - -from typing import Union - -import httpx - -from livechat.utils.helpers import prepare_payload -from livechat.utils.http_client import HttpClient -from livechat.utils.structures import AccessToken - - -class ConfigurationApiV34(HttpClient): - ''' Configuration API client class in version 3.4. ''' - def __init__(self, - token: Union[AccessToken, str], - base_url: str, - http2: bool, - proxies=None, - verify: bool = True, - disable_logging: bool = False, - timeout: float = httpx.Timeout(15)): - super().__init__(token, base_url, http2, proxies, verify, - disable_logging, timeout) - self.api_url = f'https://{base_url}/v3.4/configuration/action' - -# Agents - - def create_agent(self, - id: str = None, - name: str = None, - role: str = None, - avatar_path: str = None, - job_title: str = None, - mobile: str = None, - max_chats_count: int = None, - awaiting_approval: bool = None, - groups: list = None, - notifications: list = None, - email_subscriptions: list = None, - work_scheduler: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Creates a new Agent with specified parameters within a license. - - Args: - id (str): Agent's ID. - name (str): Agent's name. - role (str): Agent role, should be one of the following: - `viceowner`, `administrator`, `normal` (default). - avatar_path (str): URL path of the Agent's avatar. - job_title (str): Agent's job title. - mobile (str): Agent's mobile number. - max_chats_count (int): Agent's maximum number of concurrent chats. - awaiting_approval (bool): Determines if the Agent will be awaiting - approval after creation. - groups (list): Groups an Agent belongs to. - notifications (list): Represents which Agent notifications are turned on. - email_subscriptions (list): Represents which subscriptions will be send to - the Agent via email. - work_scheduler (dict): Work scheduler options to set for the new Agent. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/create_agent', - json=payload, - headers=headers) - - def get_agent(self, - id: str = None, - fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the info about an Agent specified by `id`. - - Args: - id (str): Agent's ID. - fields (list): Additional fields to include. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_agent', - json=payload, - headers=headers) - - def list_agents(self, - filters: dict = None, - fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns all Agents within a license. - - Args: - filters (dict): Possible request filters. - fields (list): Additional fields to include. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_agents', - json=payload, - headers=headers) - - def update_agent(self, - id: str = None, - name: str = None, - role: str = None, - avatar_path: str = None, - job_title: str = None, - mobile: str = None, - max_chats_count: int = None, - groups: list = None, - notifications: list = None, - email_subscriptions: list = None, - work_scheduler: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates the properties of an Agent specified by `id`. - - Args: - id (str): Agent's ID. - name (str): Agent's name. - role (str): Agent role, should be one of the following: - `viceowner`, `administrator`, `normal` (default). - avatar_path (str): URL path of the Agent's avatar. - job_title (str): Agent's job title. - mobile (str): Agent's mobile number. - max_chats_count (int): Agent's maximum number of concurrent chats. - groups (list): Groups an Agent belongs to. - notifications (list): Represents which Agent notifications are turned on. - email_subscriptions (list): Represents which subscriptions will be send to - the Agent via email. - work_scheduler (dict): Work scheduler options to set for the new Agent. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_agent', - json=payload, - headers=headers) - - def delete_agent(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes an Agent specified by `id`. - - Args: - id (str): Agent's ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_agent', - json=payload, - headers=headers) - - def suspend_agent(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Suspends an Agent specified by `id`. - - Args: - id (str): Agent's ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/suspend_agent', - json=payload, - headers=headers) - - def unsuspend_agent(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Unsuspends an Agent specified by `id`. - - Args: - id (str): Agent's ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/unsuspend_agent', - json=payload, - headers=headers) - - def request_agent_unsuspension(self, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' A suspended Agent can send emails to license owners and vice owners - with an unsuspension request. - - Args: - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/request_agent_unsuspension', - json=payload, - headers=headers) - - def approve_agent(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Approves an Agent thus allowing the Agent to use the application. - - Args: - id (str): Agent's ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/approve_agent', - json=payload, - headers=headers) - -# Auto access - - def add_auto_access(self, - access: dict = None, - conditions: dict = None, - description: str = None, - next_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Creates an auto access data structure, which is a set of conditions - for the tracking URL and geolocation of a customer. - - Args: - access (dict): Destination access. - conditions (dict): Conditions to check. - description (str): Description of the auto access. - next_id (str): ID of an existing auto access. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/add_auto_access', - json=payload, - headers=headers) - - def list_auto_accesses(self, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns all existing auto access data structures. - - Args: - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_auto_accesses', - json=payload, - headers=headers) - - def delete_auto_access(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes an existing auto access data structure specified by its ID. - - Args: - id (str): Auto access ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_auto_access', - json=payload, - headers=headers) - - def update_auto_access(self, - id: str = None, - next_id: str = None, - access: dict = None, - conditions: dict = None, - description: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Moves an existing auto access data structure, specified by id, - before another one, specified by next_id. - - Args: - id (str): ID of the auto access to move. - next_id (str): ID of the auto access that should follow the moved auto access. - access (dict): Destination access. - conditions (dict): Conditions to check. - description (str): Description of the auto access. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_auto_access', - json=payload, - headers=headers) - -# Bots - - def create_bot(self, - name: str = None, - avatar: str = None, - max_chats_count: int = None, - default_group_priority: str = None, - job_title: str = None, - groups: list = None, - work_scheduler: dict = None, - timezone: str = None, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Creates a new Bot. - - Args: - name (str): Display name. - avatar (str): Avatar URL. - max_chats_count (int): Max. number of incoming chats that can be routed to the Bot; default: 6. - default_group_priority (str): The default routing priority for a group without defined priority. - job_title (str): Bot's job title. - groups (list): Groups the Bot belongs to. - work_scheduler (dict): Work scheduler options to set for the new Bot. - timezone (str): The time zone in which the Bot's work scheduler should operate. - owner_client_id (str): Required only when authorizing via PATs. - The request will be rejected if you provide owner_client_id when authorizing with a Bearer Token. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/create_bot', - json=payload, - headers=headers) - - def delete_bot(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes a Bot. - - Args: - id (str): Bot's ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_bot', - json=payload, - headers=headers) - - def update_bot(self, - id: str = None, - name: str = None, - avatar: str = None, - max_chats_count: int = None, - default_group_priority: str = None, - groups: list = None, - webhooks: dict = None, - work_scheduler: dict = None, - timezone: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates an existing Bot. - - Args: - id (str): Bot's ID. - name (str): Display name. - avatar (str): Avatar URL. - max_chats_count (int): Max. number of incoming chats that can be routed to the Bot. - default_group_priority (str): The default routing priority for a group without defined priority. - groups (list): Groups the Bot belongs to. - webhooks (dict): Webhooks sent to the Bot. - work_scheduler (dict): Work scheduler options to set for the new Bot. - timezone (str): The time zone in which the Bot's work scheduler should operate. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_bot', - json=payload, - headers=headers) - - def list_bots(self, - all: bool = None, - fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the list of Bots created within a license. - - Args: - all (bool): `True` gets all Bots within a license. `False` (default) returns only the requester's Bots. - fields (list): Additional Bot fields to include. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_bots', - json=payload, - headers=headers) - - def get_bot(self, - id: str = None, - fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Gets a Bot specified by `id`. - - Args: - id (str): Bot's ID. - fields (list): Additional Bot fields to include. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_bot', - json=payload, - headers=headers) - -# Groups - - def create_group(self, - name: str = None, - language_code: str = None, - agent_priorities: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Creates a new group. - - Args: - name (str): Group name (up to 180 chars). - language_code (str): The code of the group languange. - agent_priorities (dict): Agents' priorities in a group as a map in the "": "" format. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/create_group', - json=payload, - headers=headers) - - def update_group(self, - id: int = None, - name: str = None, - language_code: str = None, - agent_priorities: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates an existing group. - - Args: - id (int): Groups' ID. - name (str): Group name (up to 180 chars). - language_code (str): The code of the group languange. - agent_priorities (dict): Agents' priorities in a group as a map in the "": "" format. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_group', - json=payload, - headers=headers) - - def delete_group(self, - id: int = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes an existing group. - - Args: - id (int): Groups' ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_group', - json=payload, - headers=headers) - - def list_groups(self, - fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Lists all the exisiting groups. - - Args: - fields (list): Additional fields to include. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_groups', - json=payload, - headers=headers) - - def get_group(self, - id: int = None, - fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns details about a group specified by its id. - - Args: - id (int): Groups' ID. - fields (list): Additional fields to include. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_group', - json=payload, - headers=headers) - -# Properties - - def register_property(self, - name: str = None, - owner_client_id: str = None, - type: str = None, - access: dict = None, - description: str = None, - domain: list = None, - range: dict = None, - default_value: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Registers a new private property for a given Client ID. - - Args: - name (str): Property name. - owner_client_id (str): Client ID that will own the property; must be owned by your organization. - type (str): Possible values: `int`, `string`, `bool`, and `tokenized_string`. - access (dict): Destination access. - description (str): Property description. - domain (list): Array of values that properties can be set to. - range (dict): Range of values that properties can be set to. - default_value (str): Default value of property; validated by domain or range, if one exists. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/register_property', - json=payload, - headers=headers) - - def unregister_property(self, - name: str = None, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Unregisters a private property. - - Args: - name (str): Property name. - owner_client_id (str): Client ID that will own the property; must be owned by your organization. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/unregister_property', - json=payload, - headers=headers) - - def publish_property(self, - name: str = None, - owner_client_id: str = None, - access_type: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Publishes a private property. - - Args: - name (str): Property name. - owner_client_id (str): Client ID that will own the property; must be owned by your organization. - access_type (list): Possible values: `read`, `write`. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/publish_property', - json=payload, - headers=headers) - - def list_properties(self, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Lists private and public properties owned by a given Client ID. - - Args: - owner_client_id (str): Client ID that will own the property; must be owned by your organization. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_properties', - json=payload, - headers=headers) - - def update_license_properties(self, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates a property value within a license. This operation doesn't - overwrite the existing values. - - Args: - properties (dict): An object with namespaces as keys and properties (grouped in objects) as values. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_license_properties', - json=payload, - headers=headers) - - def list_license_properties(self, - namespace: str = None, - name_prefix: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the properties set within a license. - - Args: - namespace (str): Properties namespace. - name_prefix (str): Properties name prefix. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_license_properties', - json=payload, - headers=headers) - - def delete_license_properties(self, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes the properties set within a license. - - Args: - properties (dict): An object with namespaces as keys and property_names (in an array) as values. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_license_properties', - json=payload, - headers=headers) - - def update_group_properties(self, - group_id: int = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates a property value within a group as the property location. - This operation doesn't overwrite the existing values. - - Args: - group_id (int): ID of the group you set the properties for. - properties (dict): An object with namespaces as keys and properties (grouped in objects) as values. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/update_group_properties', - json=payload, - headers=headers) - - def list_group_properties(self, - id: int = None, - namespace: str = None, - name_prefix: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the properties set within a group. - - Args: - id (int): ID of the group you retrieve properties from. - namespace (str): Properties namespace. - name_prefix (str): Properties name prefix. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_group_properties', - json=payload, - headers=headers) - - def delete_group_properties(self, - id: int = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes the properties set within a group. - - Args: - id (int): ID of the group you delete properties from. - properties (dict): An object with namespaces as keys and property_names (in an array) as values. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/delete_group_properties', - json=payload, - headers=headers) - -# Webhooks - - def register_webhook(self, - action: str = None, - secret_key: str = None, - url: str = None, - additional_data: list = None, - description: str = None, - filters: dict = None, - owner_client_id: str = None, - type: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Registers a webhook for the Client ID (application) provided in the request. - - Args: - action (str): The action that triggers sending a webhook. - secret_key (str): The secret key sent in webhooks to verify the source of a webhook. - url (str): Destination URL for the webhook. - additional_data (list): Additional data arriving with the webhook. - description (str): Webhook description. - filters (dict): Filters to check if a webhook should be triggered. - owner_client_id (str): The Client ID for which the webhook will be registered. - type (str): `bot` or `license`. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/register_webhook', - json=payload, - headers=headers) - - def list_webhooks(self, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Lists all webhooks registered for the given Client ID. - - Args: - owner_client_id (str): The webhook owner (the Client ID for which the webhook is registered). - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_webhooks', - json=payload, - headers=headers) - - def unregister_webhook(self, - id: str = None, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Unregisters a webhook previously registered for a Client ID (application). - - Args: - id (str): Webhook's ID. - owner_client_id (str): The webhook owner (the Client ID for which the webhook is registered). - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/unregister_webhook', - json=payload, - headers=headers) - - def list_webhook_names(self, - version: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Lists all webhooks that are supported in a given API version. This method requires no authorization. - - Args: - version (str): API's version. Defaults to the current stable API version. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/list_webhook_names', - json=payload, - headers=headers) - - def enable_license_webhooks(self, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Enables the webhooks registered for a given Client ID (application) - for the license associated with the access token used in the request. - - Args: - owner_client_id (str): The webhook owner (the Client ID for which the webhook is registered). - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/enable_license_webhooks', - json=payload, - headers=headers) - - def disable_license_webhooks(self, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Disables the enabled webhooks. - - Args: - owner_client_id (str): Required when authorizing via PATs; ignored otherwise. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/disable_license_webhooks', - json=payload, - headers=headers) - - def get_license_webhooks_state(self, - owner_client_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Gets the state of the webhooks registered for a given Client ID (application) - on the license associated with the access token used in the request. - - Args: - owner_client_id (str): Required when authorizing via PATs; ignored otherwise. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_license_webhooks_state', - json=payload, - headers=headers) - - -# Other - - def get_license_id(self, - organization_id: str = None, - params: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns license ID by given organization ID. - - Args: - organization_id (str): Organization ID to get license ID for. - params (dict): Custom params to be used in request's query string. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if params is None: - params = prepare_payload(locals()) - return self.session.get(f'{self.api_url}/get_license_id', - params=params, - headers=headers) - - def get_organization_id(self, - license_id: int = None, - params: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns organization ID by given license ID. - - Args: - license_id (int): License ID to get organization ID for. - params (dict): Custom params to be used in request's query string. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if params is None: - params = prepare_payload(locals()) - return self.session.get(f'{self.api_url}/get_organization_id', - params=params, - headers=headers) diff --git a/livechat/configuration/base.py b/livechat/configuration/base.py index 117c1f4..56b09d0 100644 --- a/livechat/configuration/base.py +++ b/livechat/configuration/base.py @@ -9,7 +9,6 @@ import httpx from livechat.config import CONFIG -from livechat.configuration.api.v34 import ConfigurationApiV34 from livechat.configuration.api.v35 import ConfigurationApiV35 from livechat.configuration.api.v36 import ConfigurationApiV36 from livechat.configuration.api.v37 import ConfigurationApiV37 @@ -32,7 +31,7 @@ def get_client( verify: bool = True, disable_logging: bool = False, timeout: float = httpx.Timeout(15) - ) -> Union[ConfigurationApiV34, ConfigurationApiV35, ConfigurationApiV36, + ) -> Union[ConfigurationApiV35, ConfigurationApiV36, ConfigurationApiV37]: ''' Returns client for specific Configuration API version. @@ -59,9 +58,6 @@ def get_client( ValueError: If the specified version does not exist. ''' client = { - '3.4': - ConfigurationApiV34(token, base_url, http2, proxies, verify, - disable_logging, timeout), '3.5': ConfigurationApiV35(token, base_url, http2, proxies, verify, disable_logging, timeout), diff --git a/livechat/customer/rtm/api/v34.py b/livechat/customer/rtm/api/v34.py deleted file mode 100644 index 5884e5e..0000000 --- a/livechat/customer/rtm/api/v34.py +++ /dev/null @@ -1,664 +0,0 @@ -''' Customer RTM API module with client class in version 3.4. ''' - -# pylint: disable=C0103,R0903,R0913,W0107,W0231,W0613,W0622 - -from typing import Callable, Optional, Union - -from livechat.utils.helpers import prepare_payload -from livechat.utils.structures import AccessToken, RtmResponse -from livechat.utils.ws_client import WebsocketClient - - -class CustomerRtmV34: - ''' Customer RTM API client class in version 3.4. ''' - def __init__( - self, - organization_id: str, - base_url: str, - header: Union[list, dict, Callable, None], - ): - if isinstance(organization_id, str): - self.ws = WebsocketClient( - url= - f'wss://{base_url}/v3.4/customer/rtm/ws?organization_id={organization_id}', - header=header) - else: - raise ValueError( - f'Provided `organization_id` (`{organization_id}`) seems invalid. Websocket connection may not open.' - ) - - def open_connection(self, - origin: dict = None, - ping_timeout: Union[float, int] = 3, - ping_interval: Union[float, int] = 5, - ws_conn_timeout: Union[float, int] = 10, - keep_alive: bool = True, - response_timeout: Union[float, int] = 3) -> None: - ''' Opens WebSocket connection. - - Args: - origin (dict): Specifies origin while creating websocket connection. - ping_timeout (int or float): timeout (in seconds) if the pong message is not received, - by default sets to 3 seconds. - ping_interval (int or float): automatically sends "ping" command every specified period (in seconds). - If set to 0, no ping is sent periodically, by default sets to 5 seconds. - ws_conn_timeout (int or float): timeout (in seconds) to wait for WebSocket connection, - by default sets to 10 seconds. - keep_alive(bool): Bool which states if connection should be kept, by default sets to `True`. - response_timeout (int or float): timeout (in seconds) to wait for the response, - by default sets to 3 seconds. - ''' - self.ws.open(origin, ping_timeout, ping_interval, ws_conn_timeout, - keep_alive, response_timeout) - - def close_connection(self) -> None: - ''' Closes WebSocket connection. ''' - self.ws.close() - -# Chats - - def list_chats(self, - limit: int = None, - sort_order: str = None, - page_id: str = None, - payload: dict = None) -> RtmResponse: - ''' It returns summaries of the chats a Customer participated in. - - Args: - limit (int): Chat limit. Default: 10, maximum: 25. - sort_order (str): Possible values: asc, desc (default). Chat summaries are sorted by the - creation date of its last thread. - page_id (str): Page ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'list_chats', 'payload': payload}) - - def list_threads(self, - chat_id: str = None, - sort_order: str = None, - limit: int = None, - page_id: str = None, - min_events_count: int = None, - payload: dict = None) -> RtmResponse: - ''' It returns threads that the current Customer has access to in a given chat. - - Args: - chat_id (str): Chat ID to get threads from. - sort_order (str): Possible values: asc - oldest threads first and desc - newest threads first (default). - limit (int): Default: 3, maximum: 100. - page_id (str): Page ID. - min_events_count (int):Range: 1-100; Specifies the minimum number of - events to be returned in the response. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'list_threads', 'payload': payload}) - - def get_chat(self, - chat_id: str = None, - thread_id: str = None, - payload: dict = None) -> RtmResponse: - ''' It returns a thread that the current Customer has access to in a given chat. - - Args: - chat_id (str): ID of a chat to get. - thread_id (str): Thread ID to get. Default: the latest thread (if exists). - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'get_chat', 'payload': payload}) - - def start_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None) -> RtmResponse: - ''' Starts a chat. - - Args: - chat (dict): Chat object. - active (bool): When set to False, creates an inactive thread; default: True. - continuous (bool): Starts chat as continuous (online group is not required); default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'start_chat', 'payload': payload}) - - def resume_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None) -> RtmResponse: - ''' Restarts an archived chat. - - Args: - chat (dict): Chat object. - active (bool): When set to false, creates an inactive thread; default: true. - continuous (bool): Sets a chat to the continuous mode. When unset, leaves the mode unchanged. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'resume_chat', 'payload': payload}) - - def deactivate_chat(self, - id: str = None, - payload: dict = None) -> RtmResponse: - ''' Deactivates a chat by closing the currently open thread. - - Args: - id (str): Chat ID to deactivate. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'deactivate_chat', 'payload': payload}) - -# Events - - def send_event(self, - chat_id: str = None, - event: dict = None, - attach_to_last_thread: bool = None, - payload: dict = None) -> RtmResponse: - ''' Sends an Event object. - - Args: - chat_id (str): ID of the chat you want to send the message to. - event (dict): Event object. - attach_to_last_thread (bool): Flag which states if event object should be added to last thread. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'send_event', 'payload': payload}) - - def send_rich_message_postback(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - postback: dict = None, - payload: dict = None) -> RtmResponse: - ''' Sends rich message postback. - - Args: - chat_id (str): ID of the chat to send a rich message to. - thread_id (str): ID of the thread. - event_id (str): ID of the event. - postback (dict): Postback object. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'send_rich_message_postback', - 'payload': payload - }) - - def send_sneak_peek(self, - chat_id: str = None, - sneak_peek_text: str = None, - payload: dict = None) -> RtmResponse: - ''' Sends a sneak peek to a chat. - - Args: - chat_id (str): ID of the chat to send a sneak peek to. - sneak_peek_text (str): Sneak peek text. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'send_sneak_peek', 'payload': payload}) - -# Properties - - def update_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Updates chat properties. - - Args: - id (str): ID of the chat you to set a property for. - properties (dict): Chat properties to set. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'update_chat_properties', - 'payload': payload - }) - - def delete_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Deletes chat properties. - - Args: - id (str): ID of the chat you want to delete properties of. - properties (dict): Chat properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'delete_chat_properties', - 'payload': payload - }) - - def update_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Updates thread properties. - - Args: - chat_id (str): ID of the chat you want to set properties for. - thread_id (str): ID of the thread you want to set properties for. - properties (dict): Chat properties to set. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'update_thread_properties', - 'payload': payload - }) - - def delete_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Deletes thread properties. - - Args: - chat_id (str): ID of the chat you want to delete the properties of. - thread_id (str): ID of the thread you want to delete the properties of. - properties (dict): Thread properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'delete_thread_properties', - 'payload': payload - }) - - def update_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Updates event properties. - - Args: - chat_id (str): ID of the chat you want to set properties for. - thread_id (str): ID of the thread you want to set properties for. - event_id (str): ID of the event you want to set properties for. - properties (dict): Chat properties to set. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'update_event_properties', - 'payload': payload - }) - - def delete_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None) -> RtmResponse: - ''' Deletes event properties. - - Args: - chat_id (str): ID of the chat you want to delete the properties of. - thread_id (str): ID of the thread you want to delete the properties of. - event_id (str): ID of the event you want to delete the properties of. - properties (dict): Event properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'delete_event_properties', - 'payload': payload - }) - -# Customers - - def update_customer(self, - name: str = None, - email: str = None, - avatar: str = None, - session_fields: list = None, - payload: dict = None) -> RtmResponse: - ''' Updates customer's properties. - - Args: - name (str): Customer`s name. - email (str): Customer`s email. - avatar (str): Customer`s avatar. - session_fields (list): An array of custom object-enclosed key:value pairs. - Respects the order of items. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'update_customer', 'payload': payload}) - - def update_customer_page(self, - url: str = None, - title: str = None, - payload: dict = None) -> RtmResponse: - ''' Updates customer's page. - - Args: - url (str): Customer`s url. - title (str): Customer`s page title. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'update_customer_page', - 'payload': payload - }) - - def set_customer_session_fields(self, - session_fields: list = None, - payload: dict = None) -> RtmResponse: - ''' Sets customer's session fields. - - Args: - session_fields (list): List of custom object-enclosed key:value pairs. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'set_customer_session_fields', - 'payload': payload - }) - - def get_customer(self, payload: dict = None) -> RtmResponse: - ''' Returns the info about the customer requesting it. - - Args: - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - return self.ws.send({ - 'action': 'get_customer', - 'payload': {} if payload is None else payload - }) - -# Status - - def login(self, - token: Optional[Union[AccessToken, str]] = None, - payload: dict = None) -> RtmResponse: - ''' Logs in customer. - - Args: - token (str) : OAuth token from the Customer's account. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if token: - token = str(token) - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'login', 'payload': payload}) - - def list_group_statuses(self, - all: bool = None, - group_ids: list = None, - payload: dict = None) -> RtmResponse: - ''' Lists statuses of groups. - - Args: - all (bool): If set to True, you will get statuses of all the groups. - group_ids (list): A table of a groups' IDs. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'list_group_statuses', - 'payload': payload - }) - - -# Other - - def get_form(self, - group_id: int = None, - type: str = None, - payload: dict = None) -> RtmResponse: - ''' Returns an empty ticket form of a prechat or postchat survey. - - Args: - group_id (int): ID of the group from which you want the form. - type (str): Form type. Possible values: prechat or postchat. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'get_form', 'payload': payload}) - - def get_predicted_agent(self, payload: dict = None) -> RtmResponse: - ''' Gets the predicted Agent - the one the Customer will chat with when the chat starts. - - Args: - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - return self.ws.send({ - 'action': 'get_predicted_agent', - 'payload': {} if payload is None else payload - }) - - def get_url_info(self, - url: str = None, - payload: dict = None) -> RtmResponse: - ''' It returns the info on a given URL. - - Args: - url (str): URL to get info about. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'get_url_info', 'payload': payload}) - - def mark_events_as_seen(self, - chat_id: str = None, - seen_up_to: str = None, - payload: dict = None) -> RtmResponse: - ''' Marks events as seen by agent. - - Args: - chat_id (str): Chat to mark events. - seen_up_to (str): Date up to which mark events - RFC 3339 date-time format. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({ - 'action': 'mark_events_as_seen', - 'payload': payload - }) - - def accept_greeting(self, - greeting_id: int = None, - unique_id: str = None, - payload: dict = None) -> RtmResponse: - ''' Marks an incoming greeting as seen. - - Args: - greeting_id (int): Number representing type of a greeting. - unique_id (str): Specific greeting event ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'accept_greeting', 'payload': payload}) - - def cancel_greeting(self, - unique_id: str = None, - payload: dict = None) -> RtmResponse: - ''' Cancels a greeting. - - Args: - unique_id (str): Specific greeting event ID. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - - Returns: - RtmResponse: RTM response structure (`request_id`, `action`, - `type`, `success` and `payload` properties) - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.ws.send({'action': 'cancel_greeting', 'payload': payload}) diff --git a/livechat/customer/rtm/base.py b/livechat/customer/rtm/base.py index 5644ef3..8f56425 100644 --- a/livechat/customer/rtm/base.py +++ b/livechat/customer/rtm/base.py @@ -5,7 +5,6 @@ from typing import Callable, Union from livechat.config import CONFIG -from livechat.customer.rtm.api.v34 import CustomerRtmV34 from livechat.customer.rtm.api.v35 import CustomerRtmV35 from livechat.customer.rtm.api.v36 import CustomerRtmV36 from livechat.customer.rtm.api.v37 import CustomerRtmV37 @@ -22,7 +21,7 @@ def get_client( base_url: str = api_url, organization_id: str = None, header: Union[list, dict, Callable, None] = None, - ) -> Union[CustomerRtmV34, CustomerRtmV35, CustomerRtmV36, CustomerRtmV37]: + ) -> Union[CustomerRtmV35, CustomerRtmV36, CustomerRtmV37]: ''' Returns client for specific Customer RTM version. Args: @@ -39,7 +38,6 @@ def get_client( ValueError: If the specified version does not exist. ''' client = { - '3.4': CustomerRtmV34, '3.5': CustomerRtmV35, '3.6': CustomerRtmV36, '3.7': CustomerRtmV37, diff --git a/livechat/customer/web/api/v34.py b/livechat/customer/web/api/v34.py deleted file mode 100644 index c4d365b..0000000 --- a/livechat/customer/web/api/v34.py +++ /dev/null @@ -1,966 +0,0 @@ -''' Module containing Customer Web API client class in v3.4. ''' -from __future__ import annotations - -import typing - -import httpx - -from livechat.utils.helpers import prepare_payload -from livechat.utils.http_client import HttpClient -from livechat.utils.structures import AccessToken - - -class CustomerWebV34(HttpClient): - ''' Customer Web API Class containing methods in version 3.4. ''' - def __init__(self, - organization_id: str, - access_token: typing.Union[AccessToken, str], - base_url: str, - http2: bool, - proxies=None, - verify: bool = True, - disable_logging: bool = False, - timeout: float = httpx.Timeout(15)): - if all([access_token, isinstance(access_token, str)]): - super().__init__(access_token, base_url, http2, proxies, verify, - disable_logging, timeout) - else: - raise ValueError( - 'Incorrect or missing `access_token` argument (should be of type str.)' - ) - - self.api_url = f'https://{base_url}/v3.4/customer/action' - if isinstance(organization_id, str): - self.organization_id = organization_id - self.query_string = f'?organization_id={organization_id}' - else: - raise ValueError( - 'Incorrect or missing `organization_id` argument (should be of type str.)' - ) - -# Chats - - def list_chats(self, - limit: int = None, - sort_order: str = None, - page_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns summaries of the chats a Customer participated in. - - Args: - limit (int): Limit of results per page. Default: 10, maximum: 25. - sort_order (str): Possible values: asc, desc (default). - Chat summaries are sorted by the creation date of its last thread. - page_id (str): ID of the page with paginated results. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/list_chats{self.query_string}', - json=payload, - headers=headers) - - def list_threads(self, - chat_id: str = None, - limit: str = None, - sort_order: str = None, - page_id: str = None, - min_events_count: int = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns threads that the current Customer has access to in a given chat. - - Args: - chat_id (str): ID of the chat for which threads are to be listed. - limit (str): Limit of results per page. Default: 10, maximum: 25. - sort_order (str): Possible values: asc, desc (default). - Chat summaries are sorted by the creation date of its last thread. - page_id (str): ID of the page with paginated results. - min_events_count (int): Range: 1-100; - Specifies the minimum number of events to be returned in the response. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/list_threads{self.query_string}', - json=payload, - headers=headers) - - def get_chat(self, - chat_id: str = None, - thread_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns a thread that the current Customer has access to in a given chat. - - Args: - chat_id (str): ID of the chat for which thread is to be returned. - thread_id (str): ID of the thread to show. Default: the latest thread (if exists) - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_chat{self.query_string}', - json=payload, - headers=headers) - - def start_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Starts a chat. - - Args: - chat (dict): Dict containing chat properties, access and thread. - active (bool): When set to False, creates an inactive thread; default: True. - continuous (bool): Starts chat as continuous (online group is not required); default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/start_chat{self.query_string}', - json=payload, - headers=headers) - - def resume_chat(self, - chat: dict = None, - active: bool = None, - continuous: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Restarts an archived chat. - - Args: - chat (dict): Dict containing chat properties, access and thread. - active (bool): When set to False, creates an inactive thread; default: True. - continuous (bool): Starts chat as continuous (online group is not required); default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/resume_chat{self.query_string}', - json=payload, - headers=headers) - - def deactivate_chat(self, - id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deactivates a chat by closing the currently open thread. - Sending messages to this thread will no longer be possible. - - Args: - id (str): ID of chat to be deactivated. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/deactivate_chat{self.query_string}', - json=payload, - headers=headers) - -# Configuration - - def get_dynamic_configuration(self, - group_id: int = None, - url: str = None, - channel_type: str = None, - test: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the dynamic configuration of a given group. - It provides data to call Get Configuration and Get Localization. - - Args: - group_id (int): The ID of the group that you want to get a dynamic configuration for. ID of the default group is used if not provided. - url (str): The URL that you want to get a dynamic configuration for. - channel_type (str): The channel type that you want to get a dynamic configuration for. - test (bool): Treats a dynamic configuration request as a test. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - payload['organization_id'] = self.organization_id - return self.session.get(f'{self.api_url}/get_dynamic_configuration', - params=payload, - headers=headers) - - def get_configuration(self, - group_id: int = None, - version: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the configuration of a given group in a given version. Contains data based on which the Chat Widget can be built. - - Args: - group_id (int): The ID of the group that you want to get a configuration for. - version (str): The version that you want to get a configuration for. - Returned from Get Dynamic Configuration as the config_version parameter. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - payload['organization_id'] = self.organization_id - return self.session.get(f'{self.api_url}/get_configuration', - params=payload, - headers=headers) - -# Events - - def send_event(self, - chat_id: str = None, - event: dict = None, - attach_to_last_thread: bool = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Sends an Event object. Use this method to send a message by specifying the Message event type in the request. - The method updates the requester's `events_seen_up_to` as if they've seen all chat events. - - Args: - chat_id (int): ID of the chat that you to send a message to. - event (dict): The event object. - attach_to_last_thread (bool): The flag is ignored for active chats. - For inactive chats: - True – the event will be added to the last thread; - False – the request will fail. Default: False. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/send_event{self.query_string}', - json=payload, - headers=headers) - - def upload_file(self, - file: typing.BinaryIO = None, - headers: dict = None) -> httpx.Response: - ''' Uploads a file to the server as a temporary file. It returns a URL that expires after 24 hours unless the URL is used in `send_event`. - - Args: - file (typing.BinaryIO): File-like object with file to upload (Maximum size: 10MB). - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - return self.session.post( - f'{self.api_url}/upload_file{self.query_string}', - files=file, - headers=headers) - - def send_rich_message_postback(self, - chat_id: str = None, - event_id: str = None, - postback: dict = None, - thread_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Sends a rich message postback. - - Args: - chat_id (str): ID of the chat to send rich message postback to. - event_id (str): ID of the event related to the rich message postback. - postback (dict): Object containing postback data (id, toggled). - thread_id (str): ID of the thread to send rich message postback to. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/send_rich_message_postback{self.query_string}', - json=payload, - headers=headers) - - def send_sneak_peek(self, - chat_id: str = None, - sneak_peek_text: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Sends a sneak peek to a chat. - - Args: - chat_id (str): ID of the chat to send a sneak peek to. - sneak_peek_text (str): Sneak peek text. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/send_sneak_peek{self.query_string}', - json=payload, - headers=headers) - -# Localization - - def get_localization(self, - group_id: int = None, - language: str = None, - version: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the localization of a given language and group in a given version. Contains translated phrases for the Chat Widget. - - Args: - group_id (int): ID of the group that you want to get a localization for. - language (str): The language that you want to get a localization for. - version (str): The version that you want to get a localization for. - Returned from `get_dynamic_configuration` as the `localization_version` parameter. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - payload['organization_id'] = self.organization_id - return self.session.get(f'{self.api_url}/get_localization', - params=payload, - headers=headers) - -# Properties - - def update_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates chat properties. - - Args: - id (str): ID of the chat you to set a property for. - properties (dict): Chat properties to set. - You should stick to the general properties format and include namespace, property name and value. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/update_chat_properties{self.query_string}', - json=payload, - headers=headers) - - def delete_chat_properties(self, - id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes chat properties. - - Args: - id (str): ID of the chat you want to delete properties of. - properties (dict): Chat properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/delete_chat_properties{self.query_string}', - json=payload, - headers=headers) - - def update_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates chat thread properties. - - Args: - chat_id (str): ID of the chat you to set properties for. - thread_id (str): ID of the thread you want to set properties for. - properties (dict): Thread properties to set. - You should stick to the general properties format and include namespace, property name and value. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/update_thread_properties{self.query_string}', - json=payload, - headers=headers) - - def delete_thread_properties(self, - chat_id: str = None, - thread_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes chat thread properties. - - Args: - chat_id (str): ID of the chat you want to delete the properties of. - thread_id (str): ID of the thread you want to delete the properties of. - properties (dict): Thread properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/delete_thread_properties{self.query_string}', - json=payload, - headers=headers) - - def update_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates event properties. - - Args: - chat_id (str): ID of the chat you to set properties for. - thread_id (str): ID of the thread you want to set properties for. - event_id (str): ID of the event you want to set properties for. - properties (dict): Thread properties to set. - You should stick to the general properties format and include namespace, property name and value. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/update_event_properties{self.query_string}', - json=payload, - headers=headers) - - def delete_event_properties(self, - chat_id: str = None, - thread_id: str = None, - event_id: str = None, - properties: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Deletes event properties. - - Args: - chat_id (str): ID of the chat you to delete the properties for. - thread_id (str): ID of the thread you want to delete the properties for. - event_id (str): ID of the event you want to delete the properties for. - properties (dict): Event properties to delete. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/delete_event_properties{self.query_string}', - json=payload, - headers=headers) - - def list_license_properties(self, - namespace: str = None, - name: str = None, - headers: dict = None) -> httpx.Response: - ''' Returns the properties of a given license. It only returns the properties a Customer has access to. - - Args: - namespace (str): Property namespace to retrieve. - name (str): Property name. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - params = {} - if namespace: - params['namespace'] = namespace - if name: - params['name'] = name - params['organization_id'] = self.organization_id - return self.session.get(f'{self.api_url}/list_license_properties', - params=params, - headers=headers) - - def list_group_properties(self, - group_id: int = None, - namespace: str = None, - name: str = None, - headers: dict = None) -> httpx.Response: - ''' Returns the properties of a given group. It only returns the properties a Customer has access to. - Args: - group_id (int): ID of the group you want to return the properties of. - namespace (str): Property namespace to retrieve. - name (str): Property name. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - params = {} - if namespace: - params['namespace'] = namespace - if name: - params['name'] = name - if group_id is not None: - params['id'] = str(group_id) - params['organization_id'] = self.organization_id - return self.session.get(f'{self.api_url}/list_group_properties', - params=params, - headers=headers) - -# Customers - - def get_customer(self, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the info about the Customer requesting it. - - Args: - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - return self.session.post( - f'{self.api_url}/get_customer{self.query_string}', - json={} if payload is None else payload, - headers=headers) - - def update_customer(self, - name: str = None, - email: str = None, - avatar: str = None, - session_fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates Customer's properties. - - Args: - name (str): Name of the customer. - email (str): Email of the customer. - avatar (str): The URL of the Customer's avatar. - session_fields (list): An array of custom object-enclosed key:value pairs. - Respects the order of items. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/update_customer{self.query_string}', - json=payload, - headers=headers) - - def set_customer_session_fields(self, - session_fields: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates Customer's session fields. - - Args: - session_fields (list): An array of custom object-enclosed key:value pairs. - Respects the order of items. Max keys: 100. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/set_customer_session_fields{self.query_string}', - json=payload, - headers=headers) - -# Status - - def list_group_statuses(self, - all: bool = None, - group_ids: list = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns object with info about current routing statuses of agent groups. - One of the optional parameters needs to be included in the request. - - Args: - all (bool): If set to True, you will get statuses of all the groups. - group_ids (list): A table of groups' IDs - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/list_group_statuses{self.query_string}', - json=payload, - headers=headers) - - -# Other - - def check_goals(self, - session_fields: list = None, - group_id: int = None, - page_url: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Customer can use this method to trigger checking if goals were achieved. - Then, Agents receive the information. You should call this method to provide goals parameters for the server - when the customers limit is reached. Works only for offline Customers. - - Args: - session_fields (list): An array of custom object-enclosed key:value pairs. - group_id (int): Group ID to check the goals for. - page_url (str): URL of the page to check the goals for. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/check_goals{self.query_string}', - json=payload, - headers=headers) - - def get_form(self, - group_id: int = None, - type: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns an empty ticket form of a prechat or postchat survey. - - Args: - group_id (int): ID of the group from which you want the form. - type (str): Form type; possible values: prechat or postchat. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/get_form{self.query_string}', - json=payload, - headers=headers) - - def get_predicted_agent(self, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Gets the predicted Agent - the one the Customer will chat with when the chat starts. - To use this method, the Customer needs to be logged in, which can be done via the `login` method. - - Args: - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - return self.session.post( - f'{self.api_url}/get_predicted_agent{self.query_string}', - json={} if payload is None else payload, - headers=headers) - - def get_url_info(self, - url: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the info on a given URL. - - Args: - url (str): Valid website URL. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/get_url_info{self.query_string}', - json=payload, - headers=headers) - - def mark_events_as_seen(self, - chat_id: str = None, - seen_up_to: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Updates `seen_up_to` value for a given chat. - - Args: - chat_id (str): ID of the chat to update `seen_up_to`. - seen_up_to (str): RFC 3339 date-time format. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/mark_events_as_seen{self.query_string}', - json=payload, - headers=headers) - - def accept_greeting(self, - greeting_id: int = None, - unique_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Marks an incoming greeting as seen. - - Args: - greeting_id (int): ID of the greeting configured within the license to accept. - unique_id (str): ID of the greeting to accept. You can get it from the `incoming_greeting` push. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/accept_greeting{self.query_string}', - json=payload, - headers=headers) - - def cancel_greeting(self, - unique_id: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Cancels a greeting (an invitation to the chat). - For example, Customers could cancel greetings by minimalizing the chat widget with a greeting. - - Args: - unique_id (str): ID of the greeting to cancel. You can get it from the `incoming_greeting` push. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/cancel_greeting{self.query_string}', - json=payload, - headers=headers) - - def request_email_verification(self, - callback_uri: str = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Requests the verification of the customer's email address by sending them a verification email - with the identity confirmation link. - - Args: - callback_uri (str): URI to be called after the customer confirms their email address. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post( - f'{self.api_url}/request_email_verification{self.query_string}', - json=payload, - headers=headers) diff --git a/livechat/customer/web/base.py b/livechat/customer/web/base.py index 8eadcbc..02ccabe 100644 --- a/livechat/customer/web/base.py +++ b/livechat/customer/web/base.py @@ -8,7 +8,6 @@ import httpx from livechat.config import CONFIG -from livechat.customer.web.api.v34 import CustomerWebV34 from livechat.customer.web.api.v35 import CustomerWebV35 from livechat.customer.web.api.v36 import CustomerWebV36 from livechat.customer.web.api.v37 import CustomerWebV37 @@ -33,7 +32,7 @@ def get_client( organization_id: str = None, disable_logging: bool = False, timeout: float = httpx.Timeout(15) - ) -> Union[CustomerWebV34, CustomerWebV35, CustomerWebV36, CustomerWebV37]: + ) -> Union[CustomerWebV35, CustomerWebV36, CustomerWebV37]: ''' Returns client for specific API version. Args: @@ -61,7 +60,6 @@ def get_client( ValueError: If the specified version does not exist. ''' client = { - '3.4': CustomerWebV34, '3.5': CustomerWebV35, '3.6': CustomerWebV36, '3.7': CustomerWebV37, diff --git a/livechat/reports/api/v34.py b/livechat/reports/api/v34.py deleted file mode 100644 index 0b02968..0000000 --- a/livechat/reports/api/v34.py +++ /dev/null @@ -1,386 +0,0 @@ -''' Reports API module with client class in version 3.4. ''' - -from typing import Union - -import httpx - -from livechat.utils.helpers import prepare_payload -from livechat.utils.http_client import HttpClient -from livechat.utils.structures import AccessToken - - -class ReportsApiV34(HttpClient): - ''' Reports API client class in version 3.4. ''' - def __init__(self, - token: Union[AccessToken, str], - base_url: str, - http2: bool, - proxies=None, - verify: bool = True, - disable_logging: bool = False, - timeout: float = httpx.Timeout(15)): - super().__init__(token, base_url, http2, proxies, verify, - disable_logging, timeout) - self.api_url = f'https://{base_url}/v3.4/reports' - - # Chats - - def duration(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the average chatting duration of agents within a license. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/duration', - json=payload, - headers=headers) - - def tags(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the distribution of tags for chats. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/tags', - json=payload, - headers=headers) - - def total_chats(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows how many chats occurred during the specified period. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/total_chats', - json=payload, - headers=headers) - - def ratings(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the number of rated chats along with their ratings during a specified period of time. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/ratings', - json=payload, - headers=headers) - - def ranking(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the ratio of good to bad ratings for each operator. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/ranking', - json=payload, - headers=headers) - - def engagement(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the distribution of chats based on engagement during the specified period. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/engagement', - json=payload, - headers=headers) - - def greetings_conversion(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the number of greetings sent to the customers and how many of those resulted in a chat or a goal. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/greetings_conversion', - json=payload, - headers=headers) - - def surveys(self, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Returns the number of submitted chat surveys along with the count of specific answers. - - Args: - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/surveys', - json=payload, - headers=headers) - - def response_time(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the average agents' response time within a licence. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/response_time', - json=payload, - headers=headers) - - def first_response_time(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows the average agents' first response time within a licence. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/chats/first_response_time', - json=payload, - headers=headers) - - # Agents - - def availability(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows for how long an agent, group, or the whole account was available for chatting during a specified period of time. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/agents/availability', - json=payload, - headers=headers) - - def performance(self, - distribution: str = None, - timezone: str = None, - filters: dict = None, - payload: dict = None, - headers: dict = None) -> httpx.Response: - ''' Shows for how long an agent, group, or the whole account was available for chatting during a specified period of time. - - Args: - distribution (str): Allowed values: `hour`, `day`, `day-hours`, `month` or `year`. Defaults to `day`. - timezone (str): IANA Time Zone (e.g. America/Phoenix). - Defaults to the requester's timezone. - When the requester's timezone isn't present, then `filters.from` is parsed to get the timezone. - filters (dict): If none provided, your report will span the last seven days. - payload (dict): Custom payload to be used as request's data. - It overrides all other parameters provided for the method. - headers (dict): Custom headers to be used with session headers. - They will be merged with session-level values that are set, - however, these method-level parameters will not be persisted across requests. - - Returns: - httpx.Response: The Response object from `httpx` library, - which contains a server’s response to an HTTP request. - ''' - if payload is None: - payload = prepare_payload(locals()) - return self.session.post(f'{self.api_url}/agents/performance', - json=payload, - headers=headers) diff --git a/livechat/reports/base.py b/livechat/reports/base.py index 4e06d3c..673a514 100644 --- a/livechat/reports/base.py +++ b/livechat/reports/base.py @@ -10,7 +10,6 @@ import httpx from livechat.config import CONFIG -from livechat.reports.api.v34 import ReportsApiV34 from livechat.reports.api.v35 import ReportsApiV35 from livechat.reports.api.v36 import ReportsApiV36 from livechat.reports.api.v37 import ReportsApiV37 @@ -33,7 +32,7 @@ def get_client( verify: bool = True, disable_logging: bool = False, timeout: float = httpx.Timeout(15) - ) -> Union[ReportsApiV34, ReportsApiV35, ReportsApiV36, ReportsApiV37]: + ) -> Union[ReportsApiV35, ReportsApiV36, ReportsApiV37]: ''' Returns client for specific Reports API version. Args: @@ -59,9 +58,6 @@ def get_client( ValueError: If the specified version does not exist. ''' client = { - '3.4': - ReportsApiV34(token, base_url, http2, proxies, verify, - disable_logging, timeout), '3.5': ReportsApiV35(token, base_url, http2, proxies, verify, disable_logging, timeout), diff --git a/livechat/tests/test_wh_parser.py b/livechat/tests/test_wh_parser.py index eeb376a..58ee2c2 100644 --- a/livechat/tests/test_wh_parser.py +++ b/livechat/tests/test_wh_parser.py @@ -6,7 +6,6 @@ from livechat.config import CONFIG from livechat.webhooks.parser import parse_webhook -from livechat.webhooks.v34 import WebhookV34, action_to_data_class_mapping_v_34 from livechat.webhooks.v35 import WebhookV35, action_to_data_class_mapping_v_35 from livechat.webhooks.v36 import WebhookV36, action_to_data_class_mapping_v_36 @@ -36,7 +35,6 @@ def webhook_data_class_and_mapping() -> tuple: ''' Returns a tuple with webhook data class and actions to payload's data classes mapping for the stable version. ''' return { - '3.4': (WebhookV34, action_to_data_class_mapping_v_34), '3.5': (WebhookV35, action_to_data_class_mapping_v_35), '3.6': (WebhookV36, action_to_data_class_mapping_v_36), }.get(stable_version) diff --git a/livechat/webhooks/parser.py b/livechat/webhooks/parser.py index 4f2d67d..eb9d640 100644 --- a/livechat/webhooks/parser.py +++ b/livechat/webhooks/parser.py @@ -3,7 +3,6 @@ from typing import Union from livechat.config import CONFIG -from livechat.webhooks.v34 import WebhookV34 from livechat.webhooks.v35 import WebhookV35 from livechat.webhooks.v36 import WebhookV36 from livechat.webhooks.v37 import WebhookV37 @@ -14,7 +13,7 @@ def parse_webhook( wh_body: dict, version: str = stable_version, -) -> Union[WebhookV34, WebhookV35, WebhookV36, WebhookV37]: +) -> Union[WebhookV35, WebhookV36, WebhookV37]: ''' Parses provided `wh_body` to a `Webhook` data class. Args: @@ -29,7 +28,6 @@ def parse_webhook( invalid or missing fields). ''' webhook_data_class = { - '3.4': WebhookV34, '3.5': WebhookV35, '3.6': WebhookV36, '3.7': WebhookV37, diff --git a/livechat/webhooks/v34.py b/livechat/webhooks/v34.py deleted file mode 100644 index 5934df3..0000000 --- a/livechat/webhooks/v34.py +++ /dev/null @@ -1,370 +0,0 @@ -''' API v3.4 webhooks data classes. ''' - -from dataclasses import dataclass - -# pylint: disable=missing-class-docstring - - -@dataclass -class WebhookV34: - webhook_id: str - secret_key: str - action: str - organization_id: str - additional_data: dict - payload: dict - - def payload_data_class(self): - ''' Returns payload's data class for webhook's action. ''' - return action_to_data_class_mapping_v_34[self.action] - - -# Chats - - -@dataclass -class IncomingChat: - chat: dict - transferred_from: dict = None - - -@dataclass -class ChatDeactivated: - chat_id: str - thread_id: str - user_id: str = None - - -# Chat access - - -@dataclass -class ChatAccessUpdated: - id: str - access: dict - - -@dataclass -class ChatTransferred: - chat_id: str - reason: str - transferred_to: dict - thread_id: str = None - requester_id: str = None - queue: dict = None - - -# Chat users - - -@dataclass -class UserAddedToChat: - chat_id: str - reason: str - requester_id: str - thread_id: str = None - user_type: str = None - user: dict = None - - -@dataclass -class UserRemovedFromChat: - chat_id: str - user_id: str - reason: str - requester_id: str - thread_id: str = None - user_type: str = None - - -# Events - - -@dataclass -class IncomingEvent: - chat_id: str - thread_id: str - event: dict = None - - -@dataclass -class EventUpdated: - chat_id: str - thread_id: str - event: dict - - -@dataclass -class IncomingRichMessagePostback: - user_id: str - chat_id: str - thread_id: str - event_id: str - postback: dict - - -# Properties - - -@dataclass -class ChatPropertiesUpdated: - chat_id: str - properties: dict - - -@dataclass -class ChatPropertiesDeleted: - chat_id: str - properties: dict - - -@dataclass -class ThreadPropertiesUpdated: - chat_id: str - thread_id: str - properties: dict - - -@dataclass -class ThreadPropertiesDeleted: - chat_id: str - thread_id: str - properties: dict - - -@dataclass -class EventPropertiesUpdated: - chat_id: str - thread_id: str - event_id: str - properties: dict - - -@dataclass -class EventPropertiesDeleted: - chat_id: str - thread_id: str - event_id: str - properties: dict - - -# Thread tags - - -@dataclass -class ThreadTagged: - chat_id: str - thread_id: str - tag: str - - -@dataclass -class ThreadUntagged: - chat_id: str - thread_id: str - tag: str - - -# Status - - -@dataclass -class RoutingStatusSet: - agent_id: str - status: str - - -# Customers - - -@dataclass -class IncomingCustomer: - customer: dict - - -@dataclass -class CustomerSessionFieldsUpdated: - id: str - session_fields: list - active_chat: dict = None - - -# Configuration - - -@dataclass -class AgentCreated: - id: str - name: str - awaiting_approval: bool - role: str = None - avatar: str = None - job_title: str = None - mobile: str = None - max_chats_count: int = None - groups: list = None - notifications: list = None - email_subscriptions: list = None - work_scheduler: dict = None - - -@dataclass -class AgentApproved: - id: str - - -@dataclass -class AgentUpdated: - id: str - name: str = None - role: str = None - avatar: str = None - job_title: str = None - mobile: str = None - max_chats_count: int = None - groups: list = None - notifications: list = None - email_subscriptions: list = None - work_scheduler: dict = None - - -@dataclass -class AgentSuspended: - id: str - - -@dataclass -class AgentUnsuspended: - id: str - - -@dataclass -class AgentDeleted: - id: str - - -@dataclass -class AutoAccessAdded: - id: str - description: str - access: dict - conditions: dict - next_id: str = None - - -@dataclass -class AutoAccessUpdated: - id: str - description: str = None - access: dict = None - conditions: dict = None - next_id: str = None - - -@dataclass -class AutoAccessDeleted: - id: str - - -@dataclass -class BotCreated: - id: str - name: str - default_group_priority: str - owner_client_id: str - avatar: str = None - max_chats_count: int = None - groups: list = None - work_scheduler: dict = None - timezone: str = None - job_title: str = None - - -@dataclass -class BotUpdated: - id: str - name: str = None - avatar: str = None - max_chats_count: int = None - default_group_priority: str = None - groups: list = None - work_scheduler: dict = None - timezone: str = None - job_title: str = None - - -@dataclass -class BotDeleted: - id: str - - -@dataclass -class GroupCreated: - id: int - name: str - language_code: str - agent_priorities: dict - - -@dataclass -class GroupDeleted: - id: str - - -@dataclass -class GroupUpdated: - id: int - name: str = None - language_code: str = None - agent_priorities: dict = None - - -# Other - - -@dataclass -class EventsMarkedAsSeen: - user_id: str - chat_id: str - seen_up_to: str - - -# Webhook's action mapping to coressponding payload's data class definition -action_to_data_class_mapping_v_34 = { - 'incoming_chat': IncomingChat, - 'chat_deactivated': ChatDeactivated, - 'chat_access_updated': ChatAccessUpdated, - 'chat_transferred': ChatTransferred, - 'user_added_to_chat': UserAddedToChat, - 'user_removed_from_chat': UserRemovedFromChat, - 'incoming_event': IncomingEvent, - 'event_updated': EventUpdated, - 'incoming_rich_message_postback': IncomingRichMessagePostback, - 'chat_properties_updated': ChatPropertiesUpdated, - 'chat_properties_deleted': ChatPropertiesDeleted, - 'thread_properties_updated': ThreadPropertiesUpdated, - 'thread_properties_deleted': ThreadPropertiesDeleted, - 'event_properties_updated': EventPropertiesUpdated, - 'event_properties_deleted': EventPropertiesDeleted, - 'thread_tagged': ThreadTagged, - 'thread_untagged': ThreadUntagged, - 'routing_status_set': RoutingStatusSet, - 'incoming_customer': IncomingCustomer, - 'customer_session_fields_updated': CustomerSessionFieldsUpdated, - 'agent_created': AgentCreated, - 'agent_approved': AgentApproved, - 'agent_updated': AgentUpdated, - 'agent_suspended': AgentSuspended, - 'agent_unsuspended': AgentUnsuspended, - 'agent_deleted': AgentDeleted, - 'auto_access_added': AutoAccessAdded, - 'auto_access_updated': AutoAccessUpdated, - 'auto_access_deleted': AutoAccessDeleted, - 'bot_created': BotCreated, - 'bot_updated': BotUpdated, - 'bot_deleted': BotDeleted, - 'group_created': GroupCreated, - 'group_deleted': GroupDeleted, - 'group_updated': GroupUpdated, - 'events_marked_as_seen': EventsMarkedAsSeen, -}