From 69203c8e7be6f830680cf60934a80c3de6e41f2e Mon Sep 17 00:00:00 2001 From: zuczkows Date: Tue, 20 Feb 2024 11:09:16 +0100 Subject: [PATCH] API-13100: Add bot template mgmt methods to v3.5 --- changelog.md | 2 +- livechat/configuration/api/v35.py | 231 ++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 674d311..b2dc3f2 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. ## [0.3.9] - XXX ### Added -- New methods in configuration-api v3.6 for bot management: `create_bot_template`, `delete_bot_template`, `update_bot_template`, `list_bot_templates`, `issue_bot_token`, `reset_bot_secret`, `reset_bot_template_secret`. +- New methods in configuration-api v3.5, v3.6 for bot management: `create_bot_template`, `delete_bot_template`, `update_bot_template`, `list_bot_templates`, `issue_bot_token`, `reset_bot_secret`, `reset_bot_template_secret`. ### Changed - Updated outdated packages. diff --git a/livechat/configuration/api/v35.py b/livechat/configuration/api/v35.py index 1e3d454..bcf7567 100644 --- a/livechat/configuration/api/v35.py +++ b/livechat/configuration/api/v35.py @@ -436,6 +436,48 @@ def create_bot(self, json=payload, headers=headers) + def create_bot_template(self, + name: str = None, + avatar: str = None, + max_chats_count: int = None, + default_group_priority: str = None, + job_title: str = None, + owner_client_id: str = None, + affect_existing_installations: bool = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Creates a new bot template for the Client ID (application) provided in the request. + One Client ID can register up to five bot templates. + Bots based on the template will be automatically created on the license when the application is installed. + The bots will have the same ID as the bot template. If the application is already installed on the license, + the bots will be created only if `affect_existing_installations` is set to `true`. + 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. + owner_client_id (str): Required only when authorizing via PAT. When you provide this param while + authorizing with a Bearer Token, the `client_id` associated with the Bearer Token + will be ignored, and provided `owner_client_id` will be used instead. + affect_existing_installations (bool): based on this template will be created on all licenses that have given + application installed. Otherwise only new installations will trigger bot + creation. + 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_template', + json=payload, + headers=headers) + def delete_bot(self, id: str = None, payload: dict = None, @@ -460,6 +502,39 @@ def delete_bot(self, json=payload, headers=headers) + def delete_bot_template(self, + id: str = None, + owner_client_id: str = None, + affect_existing_installations: bool = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Deletes a bot template specified by `id`. The bots associated with the template will + be deleted only if `affect_existing_installations` is set to `true`. + + Args: + id (str): Bot Template ID. + owner_client_id (str): Required only when authorizing via PAT. When you provide this param while + authorizing with a Bearer Token, the `client_id` associated with the Bearer Token + will be ignored, and provided `owner_client_id` will be used instead. + affect_existing_installations (bool): based on this template will be created on all licenses that have given + application installed. Otherwise only new installations will trigger bot + creation. + 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_template', + json=payload, + headers=headers) + def update_bot(self, id: str = None, name: str = None, @@ -498,6 +573,46 @@ def update_bot(self, json=payload, headers=headers) + def update_bot_template(self, + id: str = None, + name: str = None, + avatar: str = None, + max_chats_count: int = None, + default_group_priority: str = None, + owner_client_id: str = None, + affect_existing_installations: bool = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Updates an existing Bot Template. + + Args: + id (str): Bot Template ID. + name (str): Display name. + avatar (str): Avatar URL. + max_chats_count (int): Max. number of incoming chats that can be routed to the Bot. + default_group_priority (str): The default routing priority for a group without defined priority. + owner_client_id (str): Required only when authorizing via PAT. When you provide this param while + authorizing with a Bearer Token, the `client_id` associated with the Bearer Token + will be ignored, and provided `owner_client_id` will be used instead. + affect_existing_installations (bool): based on this template will be created on all licenses that have given + application installed. Otherwise only new installations will trigger bot + creation. + 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_template', + json=payload, + headers=headers) + def list_bots(self, all: bool = None, fields: list = None, @@ -524,6 +639,32 @@ def list_bots(self, json=payload, headers=headers) + def list_bot_templates(self, + owner_client_id: str = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Returns the list of Bot Templates created for the Client ID (application). + + Args: + owner_client_id (str): Required only when authorizing via PAT. When you provide this param while + authorizing with a Bearer Token, the `client_id` associated with the Bearer Token + will be ignored, and provided `owner_client_id` will be used instead. + 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_bot_templates', + json=payload, + headers=headers) + def get_bot(self, id: str = None, fields: list = None, @@ -550,6 +691,96 @@ def get_bot(self, json=payload, headers=headers) + def issue_bot_token(self, + bot_id: str = None, + bot_secret: str = None, + organization_id: str = None, + client_id: str = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Issues a new token for the Bot. The token is valid for 24 hours. The token cannot be revoked. + + Args: + bot_id (str): Bot's ID. + bot_secret (str): Bot's secret. + organization_id (str): Organization's ID. + client_id (str): Client'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}/issue_bot_token', + json=payload, + headers=headers) + + def reset_bot_secret(self, + id: str = None, + owner_client_id: str = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Resets secret for given bot. + + Args: + id (str): Bot's ID. + owner_client_id (str): Required only when authorizing via PAT. When you provide this param while + authorizing with a Bearer Token, the `client_id` associated with the Bearer Token + will be ignored, and provided `owner_client_id` will be used instead. + 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}/reset_bot_secret', + json=payload, + headers=headers) + + def reset_bot_template_secret(self, + id: str = None, + owner_client_id: str = None, + affect_existing_installations: bool = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Resets secret for given bot template. + + Args: + id (str): Bot Template ID. + owner_client_id (str): Required only when authorizing via PAT. When you provide this param while + authorizing with a Bearer Token, the `client_id` associated with the Bearer Token + will be ignored, and provided `owner_client_id` will be used instead. + affect_existing_installations (bool): based on this template will be created on all licenses that have given + application installed. Otherwise only new installations will trigger bot + creation. + 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}/reset_bot_template_secret', + json=payload, + headers=headers) + # Groups def create_group(self,