From 3c845ef66e087e8d1dd33a2313df686805e7effb Mon Sep 17 00:00:00 2001 From: zuczkows Date: Mon, 4 Aug 2025 09:26:33 +0200 Subject: [PATCH 1/2] ME-566: Add send_message_preview method --- changelog.md | 2 +- livechat/agent/rtm/api/v36.py | 23 +++++++++++++++++++++++ livechat/agent/web/api/v36.py | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 8b02005..3a39b47 100644 --- a/changelog.md +++ b/changelog.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. ### Added - New method `delete_event` in customer-api v3.6. - New methods in configuration-api v3.6 for greetings: `create_greeting`, `delete_greeting`, `get_greeting`, `update_greeting`, `list_greetings`. -- New method `send_thinking_indicator` in agent-api v3.6. +- New methods in agent-api v3.6: `send_thinking_indicator`, `send_message_preview`. ### Changed - Improved websocket response collection + extended logging in the websocket client. diff --git a/livechat/agent/rtm/api/v36.py b/livechat/agent/rtm/api/v36.py index a2d6a88..c7f6ac6 100644 --- a/livechat/agent/rtm/api/v36.py +++ b/livechat/agent/rtm/api/v36.py @@ -981,6 +981,29 @@ def send_thinking_indicator(self, 'payload': payload }) + def send_event_preview(self, + chat_id: str = None, + event: dict = None, + payload: dict = None) -> RtmResponse: + ''' Sends an event preview. + + Args: + chat_id (str): ID of the chat you want to send the event preview to. + event (dict): Event 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_event_preview', + 'payload': payload + }) + def multicast(self, recipients: dict = None, content: Any = None, diff --git a/livechat/agent/web/api/v36.py b/livechat/agent/web/api/v36.py index c2b6636..e0d5f0d 100644 --- a/livechat/agent/web/api/v36.py +++ b/livechat/agent/web/api/v36.py @@ -1018,6 +1018,31 @@ def send_thinking_indicator(self, json=payload, headers=headers) + def send_event_preview(self, + chat_id: str = None, + event: dict = None, + payload: dict = None, + headers: dict = None) -> httpx.Response: + ''' Sends event preview. + + Args: + chat_id (str): ID of the chat to send event preview to. + event (dict): Event object containing the event data. + 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_preview', + json=payload, + headers=headers) + def multicast(self, recipients: dict = None, content: typing.Any = None, From fd7bf7a0b1f76cc3d11481248e7ad06b42936058 Mon Sep 17 00:00:00 2001 From: zuczkows Date: Mon, 4 Aug 2025 09:28:39 +0200 Subject: [PATCH 2/2] fixup! ME-566: Add send_message_preview method --- livechat/agent/rtm/api/v36.py | 4 ++-- livechat/agent/web/api/v36.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/livechat/agent/rtm/api/v36.py b/livechat/agent/rtm/api/v36.py index c7f6ac6..6a2cf4d 100644 --- a/livechat/agent/rtm/api/v36.py +++ b/livechat/agent/rtm/api/v36.py @@ -988,8 +988,8 @@ def send_event_preview(self, ''' Sends an event preview. Args: - chat_id (str): ID of the chat you want to send the event preview to. - event (dict): Event object. + chat_id (str): ID of the chat to send event preview to. + event (dict): Event object containing the event data. payload (dict): Custom payload to be used as request's data. It overrides all other parameters provided for the method. diff --git a/livechat/agent/web/api/v36.py b/livechat/agent/web/api/v36.py index e0d5f0d..48b756a 100644 --- a/livechat/agent/web/api/v36.py +++ b/livechat/agent/web/api/v36.py @@ -1023,7 +1023,7 @@ def send_event_preview(self, event: dict = None, payload: dict = None, headers: dict = None) -> httpx.Response: - ''' Sends event preview. + ''' Sends an event preview. Args: chat_id (str): ID of the chat to send event preview to.