diff --git a/changelog.md b/changelog.md index 7fb549c..523a363 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,14 @@ # Change Log All notable changes to this project will be documented in this file. -## [0.3.5] - TBA +## [0.3.5] - 2022-11-25 ### Added - Support for new batch methods in configuration-api v3.5: `batch_create_bots`, `batch_delete_bots`, `batch_update_bots`. +- Support for new version 3.6. + +### Changed +- Config now points to v3.5 as stable and 3.6 as dev-preview version. ## [0.3.4] - 2022-10-26 diff --git a/livechat/agent/rtm/api/v36.py b/livechat/agent/rtm/api/v36.py new file mode 100644 index 0000000..6f716c4 --- /dev/null +++ b/livechat/agent/rtm/api/v36.py @@ -0,0 +1,965 @@ +''' Module containing Agent RTM API client implementation for v3.6. ''' + +from typing import Any + +from livechat.utils.helpers import prepare_payload +from livechat.utils.structures import RtmResponse +from livechat.utils.ws_client import WebsocketClient + +# pylint: disable=unused-argument, too-many-arguments, invalid-name, redefined-builtin + + +class AgentRtmV36: + ''' Agent RTM API Class containing methods in version 3.6. ''' + def __init__(self, url: str): + self.ws = WebsocketClient(url=f'wss://{url}/v3.6/agent/rtm/ws') + + def open_connection(self) -> None: + ''' Opens WebSocket connection. ''' + self.ws.open() + + 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, + 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. + 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 + }) + +# 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}) + + def follow_customer(self, + id: str = None, + payload: dict = None) -> RtmResponse: + ''' Marks a customer as followed. + + Args: + id (str): ID of the Customer. UUID v4 format is required. + 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_customer', 'payload': payload}) + + def unfollow_customer(self, + id: str = None, + payload: dict = None) -> RtmResponse: + ''' Removes the agent from the list of customer's followers. + + Args: + id (str): ID of the Customer. UUID v4 format is required. + 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_customer', + 'payload': payload + }) + +# Status + + def login(self, + token: str = None, + timezone: str = None, + reconnect: bool = None, + push_notifications: dict = None, + application: dict = None, + away: bool = None, + customer_push_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_push_level (str): Possible values: my, engaged, online. + Defaults to my if login creates the first session; + otherwise it preserves the current customer_push_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 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 4cb3a04..9553d9d 100644 --- a/livechat/agent/rtm/base.py +++ b/livechat/agent/rtm/base.py @@ -8,6 +8,7 @@ from livechat.agent.rtm.api.v33 import AgentRtmV33 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.config import CONFIG stable_version = CONFIG.get('stable') @@ -37,6 +38,7 @@ def get_client( '3.3': AgentRtmV33, '3.4': AgentRtmV34, '3.5': AgentRtmV35, + '3.6': AgentRtmV36, }.get(version) if not client: raise ValueError('Provided version does not exist.') diff --git a/livechat/agent/web/api/v36.py b/livechat/agent/web/api/v36.py new file mode 100644 index 0000000..26d048c --- /dev/null +++ b/livechat/agent/web/api/v36.py @@ -0,0 +1,1069 @@ +''' Agent Web client implementation for v3.6. ''' + +# 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 + +# pylint: disable=R0903 + + +class AgentWebV36(HttpClient): + ''' Agent Web API Class containing methods in version 3.6. ''' + def __init__(self, + access_token: str, + base_url: str, + http2: bool, + proxies=None, + verify: bool = True): + super().__init__(access_token, base_url, http2, proxies, verify) + self.api_url = f'https://{base_url}/v3.6/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', + file=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) + + def follow_customer(self, + id: str = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Marks a customer as followed. As a result, the requester (an agent) + will receive the info about all the changes related to that customer + via pushes. Once the customer leaves the website or is unfollowed, + the agent will no longer receive that information. + + 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. + 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_customer', + json=payload, + headers=headers) + + def unfollow_customer(self, + id: str = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Removes the agent from the list of customer's followers. Calling this + method on a customer the agent's chatting with will result in success, + however, the agent will still receive pushes about the customer's data + updates. The unfollowing will take effect once the chat ends. + + 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. + 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_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 97a31ad..2bfc1f4 100644 --- a/livechat/agent/web/base.py +++ b/livechat/agent/web/base.py @@ -8,6 +8,7 @@ from livechat.agent.web.api.v33 import AgentWebV33 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.config import CONFIG stable_version = CONFIG.get('stable') @@ -51,6 +52,7 @@ def get_client( '3.3': AgentWebV33(access_token, base_url, http2, proxies, verify), '3.4': AgentWebV34(access_token, base_url, http2, proxies, verify), '3.5': AgentWebV35(access_token, base_url, http2, proxies, verify), + '3.6': AgentWebV36(access_token, base_url, http2, proxies, verify), }.get(version) if not client: raise ValueError('Provided version does not exist.') diff --git a/livechat/config.py b/livechat/config.py index 79b795d..364b0ca 100644 --- a/livechat/config.py +++ b/livechat/config.py @@ -2,6 +2,6 @@ CONFIG = { 'url': 'api.livechatinc.com', - 'stable': '3.4', - 'dev': '3.5', + 'stable': '3.5', + 'dev': '3.6', } diff --git a/livechat/configuration/api/v36.py b/livechat/configuration/api/v36.py new file mode 100644 index 0000000..501122e --- /dev/null +++ b/livechat/configuration/api/v36.py @@ -0,0 +1,1485 @@ +''' Configuration API module with client class in version 3.6. ''' + +from typing import List + +import httpx + +from livechat.utils.helpers import prepare_payload +from livechat.utils.http_client import HttpClient + + +class ConfigurationApiV36(HttpClient): + ''' Configuration API client class in version 3.6. ''' + def __init__(self, + token: str, + base_url: str, + http2: bool, + proxies=None, + verify: bool = True): + super().__init__(token, base_url, http2, proxies, verify) + self.api_url = f'https://{base_url}/v3.6/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, + 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. + 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): ID of the client bot will be assigned 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}/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, + groups: list = None, + default_group_priority: str = 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. + groups (list): Groups the Bot belongs to. + default_group_priority (str): The default routing priority for a group without defined priority. + 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_groups_properties(self, + namespace: str = None, + name_prefix: str = None, + group_ids: List[int] = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Returns the properties set within multiple groups. + + Args: + namespace (str): Properties namespace. + name_prefix (str): Properties name prefix. + group_ids (List[int]): IDs of the groups to filter the properties by. + 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_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) + +# Tags + + def create_tag(self, + name: str = None, + group_ids: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Creates a new tag. + + Args: + name (str): Name of the new tag. Matching the name of an existing tag is case-insensitive. + group_ids (list): List of groups' IDs for the tag. Can be empty. + 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_tag', + json=payload, + headers=headers) + + def delete_tag(self, + name: str = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Deletes an existing tag. + + Args: + name (str): Name of the tag to delete. Matching the name of an existing tag is case-insensitive. + 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_tag', + json=payload, + headers=headers) + + def list_tags(self, + filters: dict = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Lists the exisiting tags. + + 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_tags', + json=payload, + headers=headers) + + def update_tag(self, + name: str = None, + group_ids: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Updates an existing tag. + + Args: + name (str): Name of the tag to update. Matching the name of an existing tag is case-insensitive. + group_ids (list): List of groups' IDs for the tag. Can be empty. + 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_tag', + 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 list_channels(self, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' List all license activity per communication channel. + 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_channels', + json=payload, + headers=headers) + + def check_product_limits_for_plan(self, + plan: str = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Checks product limits for plans. + Args: + plan (str): License plan to check limit 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_product_limits_for_plan', + json=payload, + headers=headers) + + def get_product_source(self, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Retrieves the source parameters that were passed when activating the LiveChat product. + 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.get(f'{self.api_url}/get_product_source', + json=payload, + headers=headers) + + +# Batch requests + + def batch_create_agents(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `create_agent`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_create_agents', + json=payload, + headers=headers) + + def batch_delete_agents(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `delete_agent`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_delete_agents', + json=payload, + headers=headers) + + def batch_update_agents(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `update_agent`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_update_agents', + json=payload, + headers=headers) + + def batch_approve_agents(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `approve_agent`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_approve_agents', + json=payload, + headers=headers) + + def batch_suspend_agents(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `suspend_agent`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_suspend_agents', + json=payload, + headers=headers) + + def batch_unsuspend_agents(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `unsuspend_agent`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_unsuspend_agents', + json=payload, + headers=headers) + + def batch_create_bots(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `create_bot`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_create_bots', + json=payload, + headers=headers) + + def batch_delete_bots(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `delete_bot`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_delete_bots', + json=payload, + headers=headers) + + def batch_update_bots(self, + requests: list = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Batch method for `update_bot`. + + Args: + requests (list): Array of Request objects of corresponding non-batch method. + + 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}/batch_update_bots', + json=payload, + headers=headers) diff --git a/livechat/configuration/base.py b/livechat/configuration/base.py index ec22fed..3f311d4 100644 --- a/livechat/configuration/base.py +++ b/livechat/configuration/base.py @@ -10,6 +10,7 @@ from livechat.configuration.api.v33 import ConfigurationApiV33 from livechat.configuration.api.v34 import ConfigurationApiV34 from livechat.configuration.api.v35 import ConfigurationApiV35 +from livechat.configuration.api.v36 import ConfigurationApiV36 stable_version = CONFIG.get('stable') api_url = CONFIG.get('url') @@ -55,6 +56,8 @@ def get_client( verify), '3.5': ConfigurationApiV35(token, base_url, http2, proxies, verify), + '3.6': ConfigurationApiV36(token, base_url, http2, proxies, + verify), }.get(version) if not client: raise ValueError('Provided version does not exist.') diff --git a/livechat/customer/rtm/api/v36.py b/livechat/customer/rtm/api/v36.py new file mode 100644 index 0000000..17df9fa --- /dev/null +++ b/livechat/customer/rtm/api/v36.py @@ -0,0 +1,639 @@ +''' Customer RTM API module with client class in version 3.6. ''' + +# pylint: disable=C0103,R0903,R0913,W0107,W0231,W0613,W0622 + +from livechat.utils.helpers import prepare_payload +from livechat.utils.structures import RtmResponse +from livechat.utils.ws_client import WebsocketClient + + +class CustomerRtmV36: + ''' Customer RTM API client class in version 3.6. ''' + def __init__(self, organization_id: str, base_url: str): + if isinstance(organization_id, str): + self.ws = WebsocketClient( + url= + f'wss://{base_url}/v3.6/customer/rtm/ws?organization_id={organization_id}' + ) + else: + raise ValueError( + f'Provided `organization_id` (`{organization_id}`) seems invalid. Websocket connection may not open.' + ) + + def open_connection(self, origin: dict = None) -> None: + ''' Opens WebSocket connection. + Args: + origin (dict): Specifies origin while creating websocket connection. + ''' + if origin: + self.ws.open(origin=origin) + else: + self.ws.open() + + 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: 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 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 a9b0ed2..1b4cf45 100644 --- a/livechat/customer/rtm/base.py +++ b/livechat/customer/rtm/base.py @@ -40,6 +40,7 @@ def get_client( '3.3': CustomerRtmV33, '3.4': CustomerRtmV34, '3.5': CustomerRtmV35, + '3.6': CustomerRtmV35, }.get(version) client_kwargs = { '3.3': { @@ -54,6 +55,10 @@ def get_client( 'organization_id': organization_id, 'base_url': base_url }, + '3.6': { + 'organization_id': organization_id, + 'base_url': base_url + }, }.get(version) if client: return client(**client_kwargs) diff --git a/livechat/customer/web/api/v36.py b/livechat/customer/web/api/v36.py new file mode 100644 index 0000000..3f7ca74 --- /dev/null +++ b/livechat/customer/web/api/v36.py @@ -0,0 +1,962 @@ +''' Module containing Customer Web API client class in v3.6. ''' +from __future__ import annotations + +import typing + +import httpx + +from livechat.utils.helpers import prepare_payload +from livechat.utils.http_client import HttpClient + + +class CustomerWebV36(HttpClient): + ''' Customer Web API Class containing methods in version 3.6. ''' + def __init__(self, + organization_id: str, + access_token: str, + base_url: str, + http2: bool, + proxies=None, + verify: bool = True): + if all([access_token, isinstance(access_token, str)]): + super().__init__(access_token, base_url, http2, proxies, verify) + else: + raise ValueError( + 'Incorrect or missing `access_token` argument (should be of type str.)' + ) + + self.api_url = f'https://{base_url}/v3.6/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()) + return self.session.get( + f'{self.api_url}/get_dynamic_configuration{self.query_string}', + 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()) + return self.session.get( + f'{self.api_url}/get_configuration{self.query_string}', + 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()) + return self.session.get( + f'{self.api_url}/get_localization{self.query_string}', + 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 115bbd2..03f103c 100644 --- a/livechat/customer/web/base.py +++ b/livechat/customer/web/base.py @@ -9,6 +9,7 @@ from livechat.customer.web.api.v33 import CustomerWebV33 from livechat.customer.web.api.v34 import CustomerWebV34 from livechat.customer.web.api.v35 import CustomerWebV35 +from livechat.customer.web.api.v36 import CustomerWebV36 stable_version = CONFIG.get('stable') api_url = CONFIG.get('url') @@ -57,6 +58,7 @@ def get_client( '3.3': CustomerWebV33, '3.4': CustomerWebV34, '3.5': CustomerWebV35, + '3.6': CustomerWebV36, }.get(version) client_kwargs = { '3.3': { @@ -83,6 +85,14 @@ def get_client( 'proxies': proxies, 'verify': verify }, + '3.6': { + 'organization_id': organization_id, + 'access_token': access_token, + 'base_url': base_url, + 'http2': http2, + 'proxies': proxies, + 'verify': verify + }, }.get(version) if client: return client(**client_kwargs) diff --git a/livechat/reports/api/v36.py b/livechat/reports/api/v36.py new file mode 100644 index 0000000..59e055d --- /dev/null +++ b/livechat/reports/api/v36.py @@ -0,0 +1,411 @@ +''' Reports API module with client class in version 3.6. ''' + +import httpx + +from livechat.utils.helpers import prepare_payload +from livechat.utils.http_client import HttpClient + + +class ReportsApiV36(HttpClient): + ''' Reports API client class in version 3.6. ''' + def __init__(self, + token: str, + base_url: str, + http2: bool, + proxies=None, + verify: bool = True): + super().__init__(token, base_url, http2, proxies, verify) + self.api_url = f'https://{base_url}/v3.6/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) + + +# Tags + + def chat_usage(self, + timezone: str = None, + filters: dict = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Shows the total number of chats marked with each tag. + + 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}/tags/chat_usage', + json=payload, + headers=headers) diff --git a/livechat/reports/base.py b/livechat/reports/base.py index 312a0ec..2be9bf4 100644 --- a/livechat/reports/base.py +++ b/livechat/reports/base.py @@ -11,6 +11,7 @@ from livechat.reports.api.v33 import ReportsApiV33 from livechat.reports.api.v34 import ReportsApiV34 from livechat.reports.api.v35 import ReportsApiV35 +from livechat.reports.api.v36 import ReportsApiV36 stable_version = CONFIG.get('stable') api_url = CONFIG.get('url') @@ -53,6 +54,7 @@ def get_client( '3.3': ReportsApiV33(token, base_url, http2, proxies, verify), '3.4': ReportsApiV34(token, base_url, http2, proxies, verify), '3.5': ReportsApiV35(token, base_url, http2, proxies, verify), + '3.6': ReportsApiV36(token, base_url, http2, proxies, verify), }.get(version) if not client: raise ValueError('Provided version does not exist.') diff --git a/livechat/tests/test_wh_parser.py b/livechat/tests/test_wh_parser.py index 3f31b5c..e1d6716 100644 --- a/livechat/tests/test_wh_parser.py +++ b/livechat/tests/test_wh_parser.py @@ -9,6 +9,7 @@ from livechat.webhooks.v33 import WebhookV33, action_to_data_class_mapping_v_33 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 # pylint: disable=redefined-outer-name @@ -39,6 +40,7 @@ def webhook_data_class_and_mapping() -> tuple: '3.3': (WebhookV33, action_to_data_class_mapping_v_33), '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 a4d7c3f..26f7132 100644 --- a/livechat/webhooks/parser.py +++ b/livechat/webhooks/parser.py @@ -6,6 +6,7 @@ from livechat.webhooks.v33 import WebhookV33 from livechat.webhooks.v34 import WebhookV34 from livechat.webhooks.v35 import WebhookV35 +from livechat.webhooks.v36 import WebhookV36 stable_version = CONFIG.get('stable') @@ -13,7 +14,7 @@ def parse_webhook( wh_body: dict, version: str = stable_version, -) -> Union[WebhookV33, WebhookV34, WebhookV35]: +) -> Union[WebhookV33, WebhookV34, WebhookV35, WebhookV36]: ''' Parses provided `wh_body` to a `Webhook` data class. Args: @@ -31,6 +32,7 @@ def parse_webhook( '3.3': WebhookV33, '3.4': WebhookV34, '3.5': WebhookV35, + '3.6': WebhookV36, }.get(version) try: parsed_wh = webhook_data_class(**wh_body) diff --git a/livechat/webhooks/v36.py b/livechat/webhooks/v36.py new file mode 100644 index 0000000..7a43858 --- /dev/null +++ b/livechat/webhooks/v36.py @@ -0,0 +1,394 @@ +''' API v3.6 webhooks data classes. ''' + +from dataclasses import dataclass + +# pylint: disable=missing-class-docstring + + +@dataclass +class WebhookV36: + 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_36[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 + + +@dataclass +class TagCreated: + name: str + author_id: str + created_at: str + group_ids: list + + +@dataclass +class TagDeleted: + name: str + + +@dataclass +class TagUpdated: + name: str + group_ids: list + author_id: str = None + created_at: str = 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_36 = { + '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, + 'tag_created': TagCreated, + 'tag_deleted': TagDeleted, + 'tag_updated': TagUpdated, + 'events_marked_as_seen': EventsMarkedAsSeen, +} diff --git a/setup.cfg b/setup.cfg index 675f92c..138f46a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = lc-sdk-python -version = 0.3.4 +version = 0.3.5 description = Package which lets to work with LiveChat API. long_description = file: README.md long_description_content_type = text/markdown