Skip to content

Commit

Permalink
Merge pull request #129 from livechat/API-13100/neo-bots-v35
Browse files Browse the repository at this point in the history
API-13100: Add bot template mgmt methods to v3.5
  • Loading branch information
zuczkows authored Feb 22, 2024
2 parents d6ecf2e + 69203c8 commit ee3bb5c
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 1 deletion.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
231 changes: 231 additions & 0 deletions livechat/configuration/api/v35.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit ee3bb5c

Please sign in to comment.